@stackone/transport 2.14.0 → 2.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +5 -5
- package/dist/index.mjs +4 -4
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -170,9 +170,9 @@ Example:
|
|
|
170
170
|
return nil
|
|
171
171
|
`},initializeTransportSystem=async e=>{let{redisClientConfig:t,logger:n,generateUUID:r}=e;try{n?.info({category:`TransportInitialization`,message:`Starting transport system initialization`});let[e,i,a]=await Promise.all([SingletonManager.prepare(ConcurrencyManager,{redisClientConfig:t,scripts:De,logger:n,additionalArgs:r?[r]:void 0}),SingletonManager.prepare(QueueManager,{redisClientConfig:t,scripts:vn,logger:n}),SingletonManager.prepare(RateLimitManager,{redisClientConfig:t,scripts:yn,logger:n})]),o=[{name:`ConcurrencyManager`,ready:e.isReady()},{name:`QueueManager`,ready:i.isReady()},{name:`RateLimitManager`,ready:a.isReady()}],s=o.filter(e=>!e.ready);if(s.length>0){let e=s.map(e=>e.name).join(`, `);throw Error(`Failed to initialize managers: ${e}`)}return n?.info({category:`TransportInitialization`,message:`Transport system initialization completed successfully`,context:{initializedManagers:o.map(e=>e.name)}}),{concurrencyManager:e,queueManager:i,rateLimitManager:a}}catch(e){n?.error({category:`TransportInitialization`,message:`Failed to initialize transport system`,code:`TRANSPORT_INIT_ERROR`,error:e});let t=SingletonManager.cleanupFailed();throw t>0&&n?.info({category:`TransportInitialization`,message:`Cleaned up ${t} failed singleton instances`}),e}},shutdownTransportSystem=e=>{try{e?.info({category:`TransportInitialization`,message:`Starting transport system shutdown`});let t=SingletonManager.getIfReady(ConcurrencyManager),n=SingletonManager.getIfReady(QueueManager),r=SingletonManager.getIfReady(RateLimitManager);t?.close(),n?.close(),r?.close(),SingletonManager.reset(ConcurrencyManager),SingletonManager.reset(QueueManager),SingletonManager.reset(RateLimitManager),e?.info({category:`TransportInitialization`,message:`Transport system shutdown completed`})}catch(t){e?.error({category:`TransportInitialization`,message:`Error during transport system shutdown`,code:`TRANSPORT_SHUTDOWN_ERROR`,error:t})}},isTransportSystemReady=()=>{let e=SingletonManager.getIfReady(ConcurrencyManager),t=SingletonManager.getIfReady(QueueManager),n=SingletonManager.getIfReady(RateLimitManager);return!!(e?.isReady()&&t?.isReady()&&n?.isReady())},getTransportManagers=()=>{let e=SingletonManager.getIfReady(ConcurrencyManager),t=SingletonManager.getIfReady(QueueManager),n=SingletonManager.getIfReady(RateLimitManager);return e&&t&&n?{concurrencyManager:e,queueManager:t,rateLimitManager:n}:null},isHttpQueryParamValue=e=>typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value)),toStringArray=e=>Array.isArray(e)?e:[e],toQueryValue=e=>Array.isArray(e)?e.map(String):String(e),mergeQueryValues=(e,t,n)=>{let r=toStringArray(t);if(isHttpQueryParamValue(e))return{value:[...toStringArray(e.value),...r],arrayFormat:n??e.arrayFormat};let i=[...toStringArray(e),...r];return n?{value:i,arrayFormat:n}:i},parseQueryParam=(e,t,n)=>{let r=toQueryValue(t);return e===void 0?n?{value:r,arrayFormat:n}:r:mergeQueryValues(e,r,n)},parseBodyParam=(e,t)=>Array.isArray(e)?e.concat(t):typeof e==`object`&&e&&typeof t==`object`&&t?{...e,...t}:t,parseRequestParameters=e=>e.reduce((e,t)=>{if(t.in===`query`){let n=e.query[t.name];e.query[t.name]=parseQueryParam(n,t.value,t.arrayFormat)}else if(t.in===`body`)if(t.spread)Array.isArray(t.value)?Array.isArray(e.body)?e.body=e.body.concat(t.value):e.body=t.value:typeof t.value==`object`&&t.value!==null&&(e.body={...e.body,...t.value});else{let n=e.body[t.name];e.body[t.name]=parseBodyParam(n,t.value)}else e.headers[t.name]=String(t.value);return e},{query:{},body:{},headers:{}}),bn=[`query`,`body`,`headers`],xn=[`repeat`,`brackets`,`comma`],isSuccessStatusCode=e=>(0,o.notMissing)(e)&&e>=200&&e<=299,isFailedStatusCode=e=>(0,o.notMissing)(e)&&e>=400&&e<=599,isInfoStatusCode=e=>(0,o.notMissing)(e)&&e>=100&&e<=199;var RestClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:s,requestConfig:c}){let l;try{l=await e?.request({method:n,url:t,headers:r,queryParams:i,maxRedirects:0,payload:a,requestConfig:c})}catch(e){if((0,o.isMissing)(e?.response))throw e;l=e.response}let u=translateCustomError(l,s);if(isFailedStatusCode(u?.status))throw new N(u,u.message);return u}};const Sn=`:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD`;Sn+``;const Cn=`[`+Sn+`][:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*`,wn=RegExp(`^[:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$`);function getAllMatches(e,t){let n=[],r=t.exec(e);for(;r;){let i=[];i.startIndex=t.lastIndex-r[0].length;let a=r.length;for(let e=0;e<a;e++)i.push(r[e]);n.push(i),r=t.exec(e)}return n}const isName=function(e){return wn.exec(e)!=null};function isExist(e){return e!==void 0}const Tn={allowBooleanAttributes:!1,unpairedTags:[]};function validate(e,t){t=Object.assign({},Tn,t);let n=[],r=!1,i=!1;e[0]===``&&(e=e.substr(1));for(let a=0;a<e.length;a++)if(e[a]===`<`&&e[a+1]===`?`){if(a+=2,a=readPI(e,a),a.err)return a}else if(e[a]===`<`){let o=a;if(a++,e[a]===`!`){a=readCommentAndCDATA(e,a);continue}else{let s=!1;e[a]===`/`&&(s=!0,a++);let c=``;for(;a<e.length&&e[a]!==`>`&&e[a]!==` `&&e[a]!==` `&&e[a]!==`
|
|
172
172
|
`&&e[a]!==`\r`;a++)c+=e[a];if(c=c.trim(),c[c.length-1]===`/`&&(c=c.substring(0,c.length-1),a--),!validateTagName(c)){let t;return t=c.trim().length===0?`Invalid space after '<'.`:`Tag '`+c+`' is an invalid name.`,getErrorObject(`InvalidTag`,t,getLineNumberForPosition(e,a))}let l=readAttributeStr(e,a);if(l===!1)return getErrorObject(`InvalidAttr`,`Attributes for '`+c+`' have open quote.`,getLineNumberForPosition(e,a));let u=l.value;if(a=l.index,u[u.length-1]===`/`){let n=a-u.length;u=u.substring(0,u.length-1);let i=validateAttributeString(u,t);if(i===!0)r=!0;else return getErrorObject(i.err.code,i.err.msg,getLineNumberForPosition(e,n+i.err.line))}else if(s)if(l.tagClosed){if(u.trim().length>0)return getErrorObject(`InvalidTag`,`Closing tag '`+c+`' can't have attributes or invalid starting.`,getLineNumberForPosition(e,o));if(n.length===0)return getErrorObject(`InvalidTag`,`Closing tag '`+c+`' has not been opened.`,getLineNumberForPosition(e,o));{let t=n.pop();if(c!==t.tagName){let n=getLineNumberForPosition(e,t.tagStartPos);return getErrorObject(`InvalidTag`,`Expected closing tag '`+t.tagName+`' (opened in line `+n.line+`, col `+n.col+`) instead of closing tag '`+c+`'.`,getLineNumberForPosition(e,o))}n.length==0&&(i=!0)}}else return getErrorObject(`InvalidTag`,`Closing tag '`+c+`' doesn't have proper closing.`,getLineNumberForPosition(e,a));else{let s=validateAttributeString(u,t);if(s!==!0)return getErrorObject(s.err.code,s.err.msg,getLineNumberForPosition(e,a-u.length+s.err.line));if(i===!0)return getErrorObject(`InvalidXml`,`Multiple possible root nodes found.`,getLineNumberForPosition(e,a));t.unpairedTags.indexOf(c)!==-1||n.push({tagName:c,tagStartPos:o}),r=!0}for(a++;a<e.length;a++)if(e[a]===`<`)if(e[a+1]===`!`){a++,a=readCommentAndCDATA(e,a);continue}else if(e[a+1]===`?`){if(a=readPI(e,++a),a.err)return a}else break;else if(e[a]===`&`){let t=validateAmpersand(e,a);if(t==-1)return getErrorObject(`InvalidChar`,`char '&' is not expected.`,getLineNumberForPosition(e,a));a=t}else if(i===!0&&!isWhiteSpace(e[a]))return getErrorObject(`InvalidXml`,`Extra text at the end`,getLineNumberForPosition(e,a));e[a]===`<`&&a--}}else{if(isWhiteSpace(e[a]))continue;return getErrorObject(`InvalidChar`,`char '`+e[a]+`' is not expected.`,getLineNumberForPosition(e,a))}if(r){if(n.length==1)return getErrorObject(`InvalidTag`,`Unclosed tag '`+n[0].tagName+`'.`,getLineNumberForPosition(e,n[0].tagStartPos));if(n.length>0)return getErrorObject(`InvalidXml`,`Invalid '`+JSON.stringify(n.map(e=>e.tagName),null,4).replace(/\r?\n/g,``)+`' found.`,{line:1,col:1})}else return getErrorObject(`InvalidXml`,`Start tag expected.`,1);return!0}function isWhiteSpace(e){return e===` `||e===` `||e===`
|
|
173
|
-
`||e===`\r`}function readPI(e,t){let n=t;for(;t<e.length;t++)if(e[t]==`?`||e[t]==` `){let r=e.substr(n,t-n);if(t>5&&r===`xml`)return getErrorObject(`InvalidXml`,`XML declaration allowed only at the start of the document.`,getLineNumberForPosition(e,t));if(e[t]==`?`&&e[t+1]==`>`){t++;break}else continue}return t}function readCommentAndCDATA(e,t){if(e.length>t+5&&e[t+1]===`-`&&e[t+2]===`-`){for(t+=3;t<e.length;t++)if(e[t]===`-`&&e[t+1]===`-`&&e[t+2]===`>`){t+=2;break}}else if(e.length>t+8&&e[t+1]===`D`&&e[t+2]===`O`&&e[t+3]===`C`&&e[t+4]===`T`&&e[t+5]===`Y`&&e[t+6]===`P`&&e[t+7]===`E`){let n=1;for(t+=8;t<e.length;t++)if(e[t]===`<`)n++;else if(e[t]===`>`&&(n--,n===0))break}else if(e.length>t+9&&e[t+1]===`[`&&e[t+2]===`C`&&e[t+3]===`D`&&e[t+4]===`A`&&e[t+5]===`T`&&e[t+6]===`A`&&e[t+7]===`[`){for(t+=8;t<e.length;t++)if(e[t]===`]`&&e[t+1]===`]`&&e[t+2]===`>`){t+=2;break}}return t}const En=`"`,Dn=`'`;function readAttributeStr(e,t){let n=``,r=``,i=!1;for(;t<e.length;t++){if(e[t]===`"`||e[t]===`'`)r===``?r=e[t]:r!==e[t]||(r=``);else if(e[t]===`>`&&r===``){i=!0;break}n+=e[t]}return r===``?{value:n,index:t,tagClosed:i}:!1}const On=RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,`g`);function validateAttributeString(e,t){let n=getAllMatches(e,On),r={};for(let e=0;e<n.length;e++){if(n[e][1].length===0)return getErrorObject(`InvalidAttr`,`Attribute '`+n[e][2]+`' has no space in starting.`,getPositionFromMatch(n[e]));if(n[e][3]!==void 0&&n[e][4]===void 0)return getErrorObject(`InvalidAttr`,`Attribute '`+n[e][2]+`' is without value.`,getPositionFromMatch(n[e]));if(n[e][3]===void 0&&!t.allowBooleanAttributes)return getErrorObject(`InvalidAttr`,`boolean attribute '`+n[e][2]+`' is not allowed.`,getPositionFromMatch(n[e]));let i=n[e][2];if(!validateAttrName(i))return getErrorObject(`InvalidAttr`,`Attribute '`+i+`' is an invalid name.`,getPositionFromMatch(n[e]));if(!r.hasOwnProperty(i))r[i]=1;else return getErrorObject(`InvalidAttr`,`Attribute '`+i+`' is repeated.`,getPositionFromMatch(n[e]))}return!0}function validateNumberAmpersand(e,t){let n=/\d/;for(e[t]===`x`&&(t++,n=/[\da-fA-F]/);t<e.length;t++){if(e[t]===`;`)return t;if(!e[t].match(n))break}return-1}function validateAmpersand(e,t){if(t++,e[t]===`;`)return-1;if(e[t]===`#`)return t++,validateNumberAmpersand(e,t);let n=0;for(;t<e.length;t++,n++)if(!(e[t].match(/\w/)&&n<20)){if(e[t]===`;`)break;return-1}return t}function getErrorObject(e,t,n){return{err:{code:e,msg:t,line:n.line||n,col:n.col}}}function validateAttrName(e){return isName(e)}function validateTagName(e){return isName(e)}function getLineNumberForPosition(e,t){let n=e.substring(0,t).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function getPositionFromMatch(e){return e.startIndex+e[1].length}const kn={preserveOrder:!1,attributeNamePrefix:`@_`,attributesGroupName:!1,textNodeName:`#text`,ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(e,t){return t},attributeValueProcessor:function(e,t){return t},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(e,t,n){return e},captureMetaData:!1},buildOptions=function(e){return Object.assign({},kn,e)};let An;An=typeof Symbol==`function`?Symbol(`XML Node Metadata`):`@@xmlMetadata`;var XmlNode=class{constructor(e){this.tagname=e,this.child=[],this[`:@`]={}}add(e,t){e===`__proto__`&&(e=`#__proto__`),this.child.push({[e]:t})}addChild(e,t){e.tagname===`__proto__`&&(e.tagname=`#__proto__`),e[`:@`]&&Object.keys(e[`:@`]).length>0?this.child.push({[e.tagname]:e.child,":@":e[`:@`]}):this.child.push({[e.tagname]:e.child}),t!==void 0&&(this.child[this.child.length-1][An]={startIndex:t})}static getMetaDataSymbol(){return An}};function readDocType(e,t){let n={};if(e[t+3]===`O`&&e[t+4]===`C`&&e[t+5]===`T`&&e[t+6]===`Y`&&e[t+7]===`P`&&e[t+8]===`E`){t+=9;let r=1,i=!1,a=!1,o=``;for(;t<e.length;t++)if(e[t]===`<`&&!a){if(i&&hasSeq(e,`!ENTITY`,t)){t+=7;let r,i;[r,i,t]=readEntityExp(e,t+1),i.indexOf(`&`)===-1&&(n[r]={regx:RegExp(`&${r};`,`g`),val:i})}else if(i&&hasSeq(e,`!ELEMENT`,t)){t+=8;let{index:n}=readElementExp(e,t+1);t=n}else if(i&&hasSeq(e,`!ATTLIST`,t))t+=8;else if(i&&hasSeq(e,`!NOTATION`,t)){t+=9;let{index:n}=readNotationExp(e,t+1);t=n}else if(hasSeq(e,`!--`,t))a=!0;else throw Error(`Invalid DOCTYPE`);r++,o=``}else if(e[t]===`>`){if(a?e[t-1]===`-`&&e[t-2]===`-`&&(a=!1,r--):r--,r===0)break}else e[t]===`[`?i=!0:o+=e[t];if(r!==0)throw Error(`Unclosed DOCTYPE`)}else throw Error(`Invalid Tag instead of DOCTYPE`);return{entities:n,i:t}}const skipWhitespace=(e,t)=>{for(;t<e.length&&/\s/.test(e[t]);)t++;return t};function readEntityExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t])&&e[t]!==`"`&&e[t]!==`'`;)n+=e[t],t++;if(validateEntityName(n),t=skipWhitespace(e,t),e.substring(t,t+6).toUpperCase()===`SYSTEM`)throw Error(`External entities are not supported`);if(e[t]===`%`)throw Error(`Parameter entities are not supported`);let r=``;return[t,r]=readIdentifierVal(e,t,`entity`),t--,[n,r,t]}function readNotationExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;validateEntityName(n),t=skipWhitespace(e,t);let r=e.substring(t,t+6).toUpperCase();if(r!==`SYSTEM`&&r!==`PUBLIC`)throw Error(`Expected SYSTEM or PUBLIC, found "${r}"`);t+=r.length,t=skipWhitespace(e,t);let i=null,a=null;if(r===`PUBLIC`)[t,i]=readIdentifierVal(e,t,`publicIdentifier`),t=skipWhitespace(e,t),(e[t]===`"`||e[t]===`'`)&&([t,a]=readIdentifierVal(e,t,`systemIdentifier`));else if(r===`SYSTEM`&&([t,a]=readIdentifierVal(e,t,`systemIdentifier`),!a))throw Error(`Missing mandatory system identifier for SYSTEM notation`);return{notationName:n,publicIdentifier:i,systemIdentifier:a,index:--t}}function readIdentifierVal(e,t,n){let r=``,i=e[t];if(i!==`"`&&i!==`'`)throw Error(`Expected quoted string, found "${i}"`);for(t++;t<e.length&&e[t]!==i;)r+=e[t],t++;if(e[t]!==i)throw Error(`Unterminated ${n} value`);return t++,[t,r]}function readElementExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;if(!validateEntityName(n))throw Error(`Invalid element name: "${n}"`);t=skipWhitespace(e,t);let r=``;if(e[t]===`E`&&hasSeq(e,`MPTY`,t))t+=4;else if(e[t]===`A`&&hasSeq(e,`NY`,t))t+=2;else if(e[t]===`(`){for(t++;t<e.length&&e[t]!==`)`;)r+=e[t],t++;if(e[t]!==`)`)throw Error(`Unterminated content model`)}else throw Error(`Invalid Element Expression, found "${e[t]}"`);return{elementName:n,contentModel:r.trim(),index:t}}function hasSeq(e,t,n){for(let r=0;r<t.length;r++)if(t[r]!==e[n+r+1])return!1;return!0}function validateEntityName(e){if(isName(e))return e;throw Error(`Invalid entity name ${e}`)}const jn=/^[-+]?0x[a-fA-F0-9]+$/,Mn=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,Nn={hex:!0,leadingZeros:!0,decimalPoint:`.`,eNotation:!0};function toNumber(e,t={}){if(t=Object.assign({},Nn,t),!e||typeof e!=`string`)return e;let n=e.trim();if(t.skipLike!==void 0&&t.skipLike.test(n))return e;if(e===`0`)return 0;if(t.hex&&jn.test(n))return parse_int(n,16);if(n.includes(`e`)||n.includes(`E`))return resolveEnotation(e,n,t);{let r=Mn.exec(n);if(r){let i=r[1]||``,a=r[2],o=trimZeros(r[3]),s=i?e[a.length+1]===`.`:e[a.length]===`.`;if(!t.leadingZeros&&(a.length>1||a.length===1&&!s))return e;{let r=Number(n),s=String(r);if(r===0)return r;if(s.search(/[eE]/)!==-1)return t.eNotation?r:e;if(n.indexOf(`.`)!==-1)return s===`0`||s===o||s===`${i}${o}`?r:e;let c=a?o:n;return a?c===s||i+c===s?r:e:c===s||c===i+s?r:e}}else return e}}const Pn=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function resolveEnotation(e,t,n){if(!n.eNotation)return e;let r=t.match(Pn);if(r){let i=r[1]||``,a=r[3].indexOf(`e`)===-1?`E`:`e`,o=r[2],s=i?e[o.length+1]===a:e[o.length]===a;return o.length>1&&s?e:o.length===1&&(r[3].startsWith(`.${a}`)||r[3][0]===a)?Number(t):n.leadingZeros&&!s?(t=(r[1]||``)+r[3],Number(t)):e}else return e}function trimZeros(e){return e&&e.indexOf(`.`)!==-1?(e=e.replace(/0+$/,``),e===`.`?e=`0`:e[0]===`.`?e=`0`+e:e[e.length-1]===`.`&&(e=e.substring(0,e.length-1)),e):e}function parse_int(e,t){if(parseInt)return parseInt(e,t);if(Number.parseInt)return Number.parseInt(e,t);if(window&&window.parseInt)return window.parseInt(e,t);throw Error(`parseInt, Number.parseInt, window.parseInt are not supported`)}function getIgnoreAttributesFn(e){return typeof e==`function`?e:Array.isArray(e)?t=>{for(let n of e)if(typeof n==`string`&&t===n||n instanceof RegExp&&n.test(t))return!0}:()=>!1}var OrderedObjParser=class{constructor(e){this.options=e,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:`'`},gt:{regex:/&(gt|#62|#x3E);/g,val:`>`},lt:{regex:/&(lt|#60|#x3C);/g,val:`<`},quot:{regex:/&(quot|#34|#x22);/g,val:`"`}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:`&`},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:` `},cent:{regex:/&(cent|#162);/g,val:`¢`},pound:{regex:/&(pound|#163);/g,val:`£`},yen:{regex:/&(yen|#165);/g,val:`¥`},euro:{regex:/&(euro|#8364);/g,val:`€`},copyright:{regex:/&(copy|#169);/g,val:`©`},reg:{regex:/&(reg|#174);/g,val:`®`},inr:{regex:/&(inr|#8377);/g,val:`₹`},num_dec:{regex:/&#([0-9]{1,7});/g,val:(e,t)=>String.fromCodePoint(Number.parseInt(t,10))},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(e,t)=>String.fromCodePoint(Number.parseInt(t,16))}},this.addExternalEntities=addExternalEntities,this.parseXml=parseXml,this.parseTextData=parseTextData,this.resolveNameSpace=resolveNameSpace,this.buildAttributesMap=buildAttributesMap,this.isItStopNode=isItStopNode,this.replaceEntitiesValue=In,this.readStopNodeData=readStopNodeData,this.saveTextToParentTag=saveTextToParentTag,this.addChild=addChild,this.ignoreAttributesFn=getIgnoreAttributesFn(this.options.ignoreAttributes)}};function addExternalEntities(e){let t=Object.keys(e);for(let n=0;n<t.length;n++){let r=t[n];this.lastEntities[r]={regex:RegExp(`&`+r+`;`,`g`),val:e[r]}}}function parseTextData(e,t,n,r,i,a,o){if(e!==void 0&&(this.options.trimValues&&!r&&(e=e.trim()),e.length>0)){o||(e=this.replaceEntitiesValue(e));let r=this.options.tagValueProcessor(t,e,n,i,a);return r==null?e:typeof r!=typeof e||r!==e?r:this.options.trimValues||e.trim()===e?parseValue(e,this.options.parseTagValue,this.options.numberParseOptions):e}}function resolveNameSpace(e){if(this.options.removeNSPrefix){let t=e.split(`:`),n=e.charAt(0)===`/`?`/`:``;if(t[0]===`xmlns`)return``;t.length===2&&(e=n+t[1])}return e}const Fn=RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,`gm`);function buildAttributesMap(e,t,n){if(this.options.ignoreAttributes!==!0&&typeof e==`string`){let n=getAllMatches(e,Fn),r=n.length,i={};for(let e=0;e<r;e++){let r=this.resolveNameSpace(n[e][1]);if(this.ignoreAttributesFn(r,t))continue;let a=n[e][4],o=this.options.attributeNamePrefix+r;if(r.length)if(this.options.transformAttributeName&&(o=this.options.transformAttributeName(o)),o===`__proto__`&&(o=`#__proto__`),a!==void 0){this.options.trimValues&&(a=a.trim()),a=this.replaceEntitiesValue(a);let e=this.options.attributeValueProcessor(r,a,t);e==null?i[o]=a:typeof e!=typeof a||e!==a?i[o]=e:i[o]=parseValue(a,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(i[o]=!0)}if(!Object.keys(i).length)return;if(this.options.attributesGroupName){let e={};return e[this.options.attributesGroupName]=i,e}return i}}const parseXml=function(e){e=e.replace(/\r\n?/g,`
|
|
174
|
-
`);let t=new XmlNode(`!xml`),n=t,r=``,i=``;for(let a=0;a<e.length;a++)if(e[a]===`<`)if(e[a+1]===`/`){let t=findClosingIndex(e,`>`,a,`Closing Tag is not closed.`),o=e.substring(a+2,t).trim();if(this.options.removeNSPrefix){let e=o.indexOf(`:`);e!==-1&&(o=o.substr(e+1))}this.options.transformTagName&&(o=this.options.transformTagName(o)),n&&(r=this.saveTextToParentTag(r,n,i));let s=i.substring(i.lastIndexOf(`.`)+1);if(o&&this.options.unpairedTags.indexOf(o)!==-1)throw Error(`Unpaired tag can not be used as closing tag: </${o}>`);let c=0;s&&this.options.unpairedTags.indexOf(s)!==-1?(c=i.lastIndexOf(`.`,i.lastIndexOf(`.`)-1),this.tagsNodeStack.pop()):c=i.lastIndexOf(`.`),i=i.substring(0,c),n=this.tagsNodeStack.pop(),r=``,a=t}else if(e[a+1]===`?`){let t=readTagExp(e,a,!1,`?>`);if(!t)throw Error(`Pi Tag is not closed.`);if(r=this.saveTextToParentTag(r,n,i),!(this.options.ignoreDeclaration&&t.tagName===`?xml`||this.options.ignorePiTags)){let e=new XmlNode(t.tagName);e.add(this.options.textNodeName,``),t.tagName!==t.tagExp&&t.attrExpPresent&&(e[`:@`]=this.buildAttributesMap(t.tagExp,i,t.tagName)),this.addChild(n,e,i,a)}a=t.closeIndex+1}else if(e.substr(a+1,3)===`!--`){let t=findClosingIndex(e,`-->`,a+4,`Comment is not closed.`);if(this.options.commentPropName){let o=e.substring(a+4,t-2);r=this.saveTextToParentTag(r,n,i),n.add(this.options.commentPropName,[{[this.options.textNodeName]:o}])}a=t}else if(e.substr(a+1,2)===`!D`){let t=readDocType(e,a);this.docTypeEntities=t.entities,a=t.i}else if(e.substr(a+1,2)===`![`){let t=findClosingIndex(e,`]]>`,a,`CDATA is not closed.`)-2,o=e.substring(a+9,t);r=this.saveTextToParentTag(r,n,i);let s=this.parseTextData(o,n.tagname,i,!0,!1,!0,!0);s??=``,this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:o}]):n.add(this.options.textNodeName,s),a=t+2}else{let o=readTagExp(e,a,this.options.removeNSPrefix),s=o.tagName,c=o.rawTagName,l=o.tagExp,u=o.attrExpPresent,d=o.closeIndex;this.options.transformTagName&&(s=this.options.transformTagName(s)),n&&r&&n.tagname!==`!xml`&&(r=this.saveTextToParentTag(r,n,i,!1));let f=n;f&&this.options.unpairedTags.indexOf(f.tagname)!==-1&&(n=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf(`.`))),s!==t.tagname&&(i+=i?`.`+s:s);let p=a;if(this.isItStopNode(this.options.stopNodes,i,s)){let t=``;if(l.length>0&&l.lastIndexOf(`/`)===l.length-1)s[s.length-1]===`/`?(s=s.substr(0,s.length-1),i=i.substr(0,i.length-1),l=s):l=l.substr(0,l.length-1),a=o.closeIndex;else if(this.options.unpairedTags.indexOf(s)!==-1)a=o.closeIndex;else{let n=this.readStopNodeData(e,c,d+1);if(!n)throw Error(`Unexpected end of ${c}`);a=n.i,t=n.tagContent}let r=new XmlNode(s);s!==l&&u&&(r[`:@`]=this.buildAttributesMap(l,i,s)),t&&=this.parseTextData(t,s,i,!0,u,!0,!0),i=i.substr(0,i.lastIndexOf(`.`)),r.add(this.options.textNodeName,t),this.addChild(n,r,i,p)}else{if(l.length>0&&l.lastIndexOf(`/`)===l.length-1){s[s.length-1]===`/`?(s=s.substr(0,s.length-1),i=i.substr(0,i.length-1),l=s):l=l.substr(0,l.length-1),this.options.transformTagName&&(s=this.options.transformTagName(s));let e=new XmlNode(s);s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i,s)),this.addChild(n,e,i,p),i=i.substr(0,i.lastIndexOf(`.`))}else{let e=new XmlNode(s);this.tagsNodeStack.push(n),s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i,s)),this.addChild(n,e,i,p),n=e}r=``,a=d}}else r+=e[a];return t.child};function addChild(e,t,n,r){this.options.captureMetaData||(r=void 0);let i=this.options.updateTag(t.tagname,n,t[`:@`]);i===!1||(typeof i==`string`&&(t.tagname=i),e.addChild(t,r))}const In=__name(function(e){if(this.options.processEntities){for(let t in this.docTypeEntities){let n=this.docTypeEntities[t];e=e.replace(n.regx,n.val)}for(let t in this.lastEntities){let n=this.lastEntities[t];e=e.replace(n.regex,n.val)}if(this.options.htmlEntities)for(let t in this.htmlEntities){let n=this.htmlEntities[t];e=e.replace(n.regex,n.val)}e=e.replace(this.ampEntity.regex,this.ampEntity.val)}return e},`replaceEntitiesValue`);function saveTextToParentTag(e,t,n,r){return e&&=(r===void 0&&(r=t.child.length===0),e=this.parseTextData(e,t.tagname,n,!1,t[`:@`]?Object.keys(t[`:@`]).length!==0:!1,r),e!==void 0&&e!==``&&t.add(this.options.textNodeName,e),``),e}function isItStopNode(e,t,n){let r=`*.`+n;for(let n in e){let i=e[n];if(r===i||t===i)return!0}return!1}function tagExpWithClosingIndex(e,t,n=`>`){let r,i=``;for(let a=t;a<e.length;a++){let t=e[a];if(r)t===r&&(r=``);else if(t===`"`||t===`'`)r=t;else if(t===n[0])if(n[1]){if(e[a+1]===n[1])return{data:i,index:a}}else return{data:i,index:a};else t===` `&&(t=` `);i+=t}}function findClosingIndex(e,t,n,r){let i=e.indexOf(t,n);if(i===-1)throw Error(r);return i+t.length-1}function readTagExp(e,t,n,r=`>`){let i=tagExpWithClosingIndex(e,t+1,r);if(!i)return;let a=i.data,o=i.index,s=a.search(/\s/),c=a,l=!0;s!==-1&&(c=a.substring(0,s),a=a.substring(s+1).trimStart());let u=c;if(n){let e=c.indexOf(`:`);e!==-1&&(c=c.substr(e+1),l=c!==i.data.substr(e+1))}return{tagName:c,tagExp:a,closeIndex:o,attrExpPresent:l,rawTagName:u}}function readStopNodeData(e,t,n){let r=n,i=1;for(;n<e.length;n++)if(e[n]===`<`)if(e[n+1]===`/`){let a=findClosingIndex(e,`>`,n,`${t} is not closed`);if(e.substring(n+2,a).trim()===t&&(i--,i===0))return{tagContent:e.substring(r,n),i:a};n=a}else if(e[n+1]===`?`)n=findClosingIndex(e,`?>`,n+1,`StopNode is not closed.`);else if(e.substr(n+1,3)===`!--`)n=findClosingIndex(e,`-->`,n+3,`StopNode is not closed.`);else if(e.substr(n+1,2)===`![`)n=findClosingIndex(e,`]]>`,n,`StopNode is not closed.`)-2;else{let r=readTagExp(e,n,`>`);r&&((r&&r.tagName)===t&&r.tagExp[r.tagExp.length-1]!==`/`&&i++,n=r.closeIndex)}}function parseValue(e,t,n){if(t&&typeof e==`string`){let t=e.trim();return t===`true`?!0:t===`false`?!1:toNumber(e,n)}else if(isExist(e))return e;else return``}const Ln=XmlNode.getMetaDataSymbol();function prettify(e,t){return compress(e,t)}function compress(e,t,n){let r,i={};for(let a=0;a<e.length;a++){let o=e[a],s=propName$1(o),c=``;if(c=n===void 0?s:n+`.`+s,s===t.textNodeName)r===void 0?r=o[s]:r+=``+o[s];else if(s===void 0)continue;else if(o[s]){let e=compress(o[s],t,c),n=isLeafTag(e,t);o[Ln]!==void 0&&(e[Ln]=o[Ln]),o[`:@`]?assignAttributes(e,o[`:@`],c,t):Object.keys(e).length===1&&e[t.textNodeName]!==void 0&&!t.alwaysCreateTextNode?e=e[t.textNodeName]:Object.keys(e).length===0&&(t.alwaysCreateTextNode?e[t.textNodeName]=``:e=``),i[s]!==void 0&&i.hasOwnProperty(s)?(Array.isArray(i[s])||(i[s]=[i[s]]),i[s].push(e)):t.isArray(s,c,n)?i[s]=[e]:i[s]=e}}return typeof r==`string`?r.length>0&&(i[t.textNodeName]=r):r!==void 0&&(i[t.textNodeName]=r),i}function propName$1(e){let t=Object.keys(e);for(let e=0;e<t.length;e++){let n=t[e];if(n!==`:@`)return n}}__name(propName$1,`propName`);function assignAttributes(e,t,n,r){if(t){let i=Object.keys(t),a=i.length;for(let o=0;o<a;o++){let a=i[o];r.isArray(a,n+`.`+a,!0,!0)?e[a]=[t[a]]:e[a]=t[a]}}}function isLeafTag(e,t){let{textNodeName:n}=t,r=Object.keys(e).length;return!!(r===0||r===1&&(e[n]||typeof e[n]==`boolean`||e[n]===0))}var XMLParser=class{constructor(e){this.externalEntities={},this.options=buildOptions(e)}parse(e,t){if(typeof e!=`string`)if(e.toString)e=e.toString();else throw Error(`XML data is accepted in String or Bytes[] form.`);if(t){t===!0&&(t={});let n=validate(e,t);if(n!==!0)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}let n=new OrderedObjParser(this.options);n.addExternalEntities(this.externalEntities);let r=n.parseXml(e);return this.options.preserveOrder||r===void 0?r:prettify(r,this.options)}addEntity(e,t){if(t.indexOf(`&`)!==-1)throw Error(`Entity value can't have '&'`);if(e.indexOf(`&`)!==-1||e.indexOf(`;`)!==-1)throw Error(`An entity must be set without '&' and ';'. Eg. use '#xD' for '
'`);if(t===`&`)throw Error(`An entity with value '&' is not permitted`);this.externalEntities[e]=t}static getMetaDataSymbol(){return XmlNode.getMetaDataSymbol()}};const Rn=`
|
|
175
|
-
`;function toXml(e,t){let n=``;
|
|
176
|
-
`)
|
|
173
|
+
`||e===`\r`}function readPI(e,t){let n=t;for(;t<e.length;t++)if(e[t]==`?`||e[t]==` `){let r=e.substr(n,t-n);if(t>5&&r===`xml`)return getErrorObject(`InvalidXml`,`XML declaration allowed only at the start of the document.`,getLineNumberForPosition(e,t));if(e[t]==`?`&&e[t+1]==`>`){t++;break}else continue}return t}function readCommentAndCDATA(e,t){if(e.length>t+5&&e[t+1]===`-`&&e[t+2]===`-`){for(t+=3;t<e.length;t++)if(e[t]===`-`&&e[t+1]===`-`&&e[t+2]===`>`){t+=2;break}}else if(e.length>t+8&&e[t+1]===`D`&&e[t+2]===`O`&&e[t+3]===`C`&&e[t+4]===`T`&&e[t+5]===`Y`&&e[t+6]===`P`&&e[t+7]===`E`){let n=1;for(t+=8;t<e.length;t++)if(e[t]===`<`)n++;else if(e[t]===`>`&&(n--,n===0))break}else if(e.length>t+9&&e[t+1]===`[`&&e[t+2]===`C`&&e[t+3]===`D`&&e[t+4]===`A`&&e[t+5]===`T`&&e[t+6]===`A`&&e[t+7]===`[`){for(t+=8;t<e.length;t++)if(e[t]===`]`&&e[t+1]===`]`&&e[t+2]===`>`){t+=2;break}}return t}const En=`"`,Dn=`'`;function readAttributeStr(e,t){let n=``,r=``,i=!1;for(;t<e.length;t++){if(e[t]===`"`||e[t]===`'`)r===``?r=e[t]:r!==e[t]||(r=``);else if(e[t]===`>`&&r===``){i=!0;break}n+=e[t]}return r===``?{value:n,index:t,tagClosed:i}:!1}const On=RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,`g`);function validateAttributeString(e,t){let n=getAllMatches(e,On),r={};for(let e=0;e<n.length;e++){if(n[e][1].length===0)return getErrorObject(`InvalidAttr`,`Attribute '`+n[e][2]+`' has no space in starting.`,getPositionFromMatch(n[e]));if(n[e][3]!==void 0&&n[e][4]===void 0)return getErrorObject(`InvalidAttr`,`Attribute '`+n[e][2]+`' is without value.`,getPositionFromMatch(n[e]));if(n[e][3]===void 0&&!t.allowBooleanAttributes)return getErrorObject(`InvalidAttr`,`boolean attribute '`+n[e][2]+`' is not allowed.`,getPositionFromMatch(n[e]));let i=n[e][2];if(!validateAttrName(i))return getErrorObject(`InvalidAttr`,`Attribute '`+i+`' is an invalid name.`,getPositionFromMatch(n[e]));if(!Object.prototype.hasOwnProperty.call(r,i))r[i]=1;else return getErrorObject(`InvalidAttr`,`Attribute '`+i+`' is repeated.`,getPositionFromMatch(n[e]))}return!0}function validateNumberAmpersand(e,t){let n=/\d/;for(e[t]===`x`&&(t++,n=/[\da-fA-F]/);t<e.length;t++){if(e[t]===`;`)return t;if(!e[t].match(n))break}return-1}function validateAmpersand(e,t){if(t++,e[t]===`;`)return-1;if(e[t]===`#`)return t++,validateNumberAmpersand(e,t);let n=0;for(;t<e.length;t++,n++)if(!(e[t].match(/\w/)&&n<20)){if(e[t]===`;`)break;return-1}return t}function getErrorObject(e,t,n){return{err:{code:e,msg:t,line:n.line||n,col:n.col}}}function validateAttrName(e){return isName(e)}function validateTagName(e){return isName(e)}function getLineNumberForPosition(e,t){let n=e.substring(0,t).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function getPositionFromMatch(e){return e.startIndex+e[1].length}const kn={preserveOrder:!1,attributeNamePrefix:`@_`,attributesGroupName:!1,textNodeName:`#text`,ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(e,t){return t},attributeValueProcessor:function(e,t){return t},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(e,t,n){return e},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0};function normalizeProcessEntities(e){return typeof e==`boolean`?{enabled:e,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,maxEntityCount:100,allowedTags:null,tagFilter:null}:typeof e==`object`&&e?{enabled:e.enabled!==!1,maxEntitySize:e.maxEntitySize??1e4,maxExpansionDepth:e.maxExpansionDepth??10,maxTotalExpansions:e.maxTotalExpansions??1e3,maxExpandedLength:e.maxExpandedLength??1e5,maxEntityCount:e.maxEntityCount??100,allowedTags:e.allowedTags??null,tagFilter:e.tagFilter??null}:normalizeProcessEntities(!0)}const buildOptions=function(e){let t=Object.assign({},kn,e);return t.processEntities=normalizeProcessEntities(t.processEntities),t};let An;An=typeof Symbol==`function`?Symbol(`XML Node Metadata`):`@@xmlMetadata`;var XmlNode=class{constructor(e){this.tagname=e,this.child=[],this[`:@`]=Object.create(null)}add(e,t){e===`__proto__`&&(e=`#__proto__`),this.child.push({[e]:t})}addChild(e,t){e.tagname===`__proto__`&&(e.tagname=`#__proto__`),e[`:@`]&&Object.keys(e[`:@`]).length>0?this.child.push({[e.tagname]:e.child,":@":e[`:@`]}):this.child.push({[e.tagname]:e.child}),t!==void 0&&(this.child[this.child.length-1][An]={startIndex:t})}static getMetaDataSymbol(){return An}},DocTypeReader=class{constructor(e){this.suppressValidationErr=!e,this.options=e}readDocType(e,t){let n=Object.create(null),r=0;if(e[t+3]===`O`&&e[t+4]===`C`&&e[t+5]===`T`&&e[t+6]===`Y`&&e[t+7]===`P`&&e[t+8]===`E`){t+=9;let i=1,a=!1,o=!1,s=``;for(;t<e.length;t++)if(e[t]===`<`&&!o){if(a&&hasSeq(e,`!ENTITY`,t)){t+=7;let i,a;if([i,a,t]=this.readEntityExp(e,t+1,this.suppressValidationErr),a.indexOf(`&`)===-1){if(this.options.enabled!==!1&&this.options.maxEntityCount&&r>=this.options.maxEntityCount)throw Error(`Entity count (${r+1}) exceeds maximum allowed (${this.options.maxEntityCount})`);let e=i.replace(/[.\-+*:]/g,`\\.`);n[i]={regx:RegExp(`&${e};`,`g`),val:a},r++}}else if(a&&hasSeq(e,`!ELEMENT`,t)){t+=8;let{index:n}=this.readElementExp(e,t+1);t=n}else if(a&&hasSeq(e,`!ATTLIST`,t))t+=8;else if(a&&hasSeq(e,`!NOTATION`,t)){t+=9;let{index:n}=this.readNotationExp(e,t+1,this.suppressValidationErr);t=n}else if(hasSeq(e,`!--`,t))o=!0;else throw Error(`Invalid DOCTYPE`);i++,s=``}else if(e[t]===`>`){if(o?e[t-1]===`-`&&e[t-2]===`-`&&(o=!1,i--):i--,i===0)break}else e[t]===`[`?a=!0:s+=e[t];if(i!==0)throw Error(`Unclosed DOCTYPE`)}else throw Error(`Invalid Tag instead of DOCTYPE`);return{entities:n,i:t}}readEntityExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t])&&e[t]!==`"`&&e[t]!==`'`;)n+=e[t],t++;if(validateEntityName(n),t=skipWhitespace(e,t),!this.suppressValidationErr){if(e.substring(t,t+6).toUpperCase()===`SYSTEM`)throw Error(`External entities are not supported`);if(e[t]===`%`)throw Error(`Parameter entities are not supported`)}let r=``;if([t,r]=this.readIdentifierVal(e,t,`entity`),this.options.enabled!==!1&&this.options.maxEntitySize&&r.length>this.options.maxEntitySize)throw Error(`Entity "${n}" size (${r.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return t--,[n,r,t]}readNotationExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;!this.suppressValidationErr&&validateEntityName(n),t=skipWhitespace(e,t);let r=e.substring(t,t+6).toUpperCase();if(!this.suppressValidationErr&&r!==`SYSTEM`&&r!==`PUBLIC`)throw Error(`Expected SYSTEM or PUBLIC, found "${r}"`);t+=r.length,t=skipWhitespace(e,t);let i=null,a=null;if(r===`PUBLIC`)[t,i]=this.readIdentifierVal(e,t,`publicIdentifier`),t=skipWhitespace(e,t),(e[t]===`"`||e[t]===`'`)&&([t,a]=this.readIdentifierVal(e,t,`systemIdentifier`));else if(r===`SYSTEM`&&([t,a]=this.readIdentifierVal(e,t,`systemIdentifier`),!this.suppressValidationErr&&!a))throw Error(`Missing mandatory system identifier for SYSTEM notation`);return{notationName:n,publicIdentifier:i,systemIdentifier:a,index:--t}}readIdentifierVal(e,t,n){let r=``,i=e[t];if(i!==`"`&&i!==`'`)throw Error(`Expected quoted string, found "${i}"`);for(t++;t<e.length&&e[t]!==i;)r+=e[t],t++;if(e[t]!==i)throw Error(`Unterminated ${n} value`);return t++,[t,r]}readElementExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;if(!this.suppressValidationErr&&!isName(n))throw Error(`Invalid element name: "${n}"`);t=skipWhitespace(e,t);let r=``;if(e[t]===`E`&&hasSeq(e,`MPTY`,t))t+=4;else if(e[t]===`A`&&hasSeq(e,`NY`,t))t+=2;else if(e[t]===`(`){for(t++;t<e.length&&e[t]!==`)`;)r+=e[t],t++;if(e[t]!==`)`)throw Error(`Unterminated content model`)}else if(!this.suppressValidationErr)throw Error(`Invalid Element Expression, found "${e[t]}"`);return{elementName:n,contentModel:r.trim(),index:t}}readAttlistExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;validateEntityName(n),t=skipWhitespace(e,t);let r=``;for(;t<e.length&&!/\s/.test(e[t]);)r+=e[t],t++;if(!validateEntityName(r))throw Error(`Invalid attribute name: "${r}"`);t=skipWhitespace(e,t);let i=``;if(e.substring(t,t+8).toUpperCase()===`NOTATION`){if(i=`NOTATION`,t+=8,t=skipWhitespace(e,t),e[t]!==`(`)throw Error(`Expected '(', found "${e[t]}"`);t++;let n=[];for(;t<e.length&&e[t]!==`)`;){let r=``;for(;t<e.length&&e[t]!==`|`&&e[t]!==`)`;)r+=e[t],t++;if(r=r.trim(),!validateEntityName(r))throw Error(`Invalid notation name: "${r}"`);n.push(r),e[t]===`|`&&(t++,t=skipWhitespace(e,t))}if(e[t]!==`)`)throw Error(`Unterminated list of notations`);t++,i+=` (`+n.join(`|`)+`)`}else{for(;t<e.length&&!/\s/.test(e[t]);)i+=e[t],t++;if(!this.suppressValidationErr&&![`CDATA`,`ID`,`IDREF`,`IDREFS`,`ENTITY`,`ENTITIES`,`NMTOKEN`,`NMTOKENS`].includes(i.toUpperCase()))throw Error(`Invalid attribute type: "${i}"`)}t=skipWhitespace(e,t);let a=``;return e.substring(t,t+8).toUpperCase()===`#REQUIRED`?(a=`#REQUIRED`,t+=8):e.substring(t,t+7).toUpperCase()===`#IMPLIED`?(a=`#IMPLIED`,t+=7):[t,a]=this.readIdentifierVal(e,t,`ATTLIST`),{elementName:n,attributeName:r,attributeType:i,defaultValue:a,index:t}}};const skipWhitespace=(e,t)=>{for(;t<e.length&&/\s/.test(e[t]);)t++;return t};function hasSeq(e,t,n){for(let r=0;r<t.length;r++)if(t[r]!==e[n+r+1])return!1;return!0}function validateEntityName(e){if(isName(e))return e;throw Error(`Invalid entity name ${e}`)}const jn=/^[-+]?0x[a-fA-F0-9]+$/,Mn=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,Nn={hex:!0,leadingZeros:!0,decimalPoint:`.`,eNotation:!0,infinity:`original`};function toNumber(e,t={}){if(t=Object.assign({},Nn,t),!e||typeof e!=`string`)return e;let n=e.trim();if(t.skipLike!==void 0&&t.skipLike.test(n))return e;if(e===`0`)return 0;if(t.hex&&jn.test(n))return parse_int(n,16);if(isFinite(n)){if(n.includes(`e`)||n.includes(`E`))return resolveEnotation(e,n,t);{let r=Mn.exec(n);if(r){let i=r[1]||``,a=r[2],o=trimZeros(r[3]),s=i?e[a.length+1]===`.`:e[a.length]===`.`;if(!t.leadingZeros&&(a.length>1||a.length===1&&!s))return e;{let r=Number(n),s=String(r);if(r===0)return r;if(s.search(/[eE]/)!==-1)return t.eNotation?r:e;if(n.indexOf(`.`)!==-1)return s===`0`||s===o||s===`${i}${o}`?r:e;let c=a?o:n;return a?c===s||i+c===s?r:e:c===s||c===i+s?r:e}}else return e}}else return handleInfinity(e,Number(n),t)}const Pn=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function resolveEnotation(e,t,n){if(!n.eNotation)return e;let r=t.match(Pn);if(r){let i=r[1]||``,a=r[3].indexOf(`e`)===-1?`E`:`e`,o=r[2],s=i?e[o.length+1]===a:e[o.length]===a;return o.length>1&&s?e:o.length===1&&(r[3].startsWith(`.${a}`)||r[3][0]===a)?Number(t):n.leadingZeros&&!s?(t=(r[1]||``)+r[3],Number(t)):e}else return e}function trimZeros(e){return e&&e.indexOf(`.`)!==-1?(e=e.replace(/0+$/,``),e===`.`?e=`0`:e[0]===`.`?e=`0`+e:e[e.length-1]===`.`&&(e=e.substring(0,e.length-1)),e):e}function parse_int(e,t){if(parseInt)return parseInt(e,t);if(Number.parseInt)return Number.parseInt(e,t);if(window&&window.parseInt)return window.parseInt(e,t);throw Error(`parseInt, Number.parseInt, window.parseInt are not supported`)}function handleInfinity(e,t,n){let r=t===1/0;switch(n.infinity.toLowerCase()){case`null`:return null;case`infinity`:return t;case`string`:return r?`Infinity`:`-Infinity`;case`original`:default:return e}}function getIgnoreAttributesFn$1(e){return typeof e==`function`?e:Array.isArray(e)?t=>{for(let n of e)if(typeof n==`string`&&t===n||n instanceof RegExp&&n.test(t))return!0}:()=>!1}__name(getIgnoreAttributesFn$1,`getIgnoreAttributesFn`);var OrderedObjParser=class{constructor(e){if(this.options=e,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:`'`},gt:{regex:/&(gt|#62|#x3E);/g,val:`>`},lt:{regex:/&(lt|#60|#x3C);/g,val:`<`},quot:{regex:/&(quot|#34|#x22);/g,val:`"`}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:`&`},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:` `},cent:{regex:/&(cent|#162);/g,val:`¢`},pound:{regex:/&(pound|#163);/g,val:`£`},yen:{regex:/&(yen|#165);/g,val:`¥`},euro:{regex:/&(euro|#8364);/g,val:`€`},copyright:{regex:/&(copy|#169);/g,val:`©`},reg:{regex:/&(reg|#174);/g,val:`®`},inr:{regex:/&(inr|#8377);/g,val:`₹`},num_dec:{regex:/&#([0-9]{1,7});/g,val:(e,t)=>fromCodePoint(t,10,`&#`)},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(e,t)=>fromCodePoint(t,16,`&#x`)}},this.addExternalEntities=addExternalEntities,this.parseXml=parseXml,this.parseTextData=parseTextData,this.resolveNameSpace=resolveNameSpace,this.buildAttributesMap=buildAttributesMap,this.isItStopNode=isItStopNode,this.replaceEntitiesValue=In,this.readStopNodeData=readStopNodeData,this.saveTextToParentTag=saveTextToParentTag,this.addChild=addChild,this.ignoreAttributesFn=getIgnoreAttributesFn$1(this.options.ignoreAttributes),this.entityExpansionCount=0,this.currentExpandedLength=0,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodesExact=new Set,this.stopNodesWildcard=new Set;for(let e=0;e<this.options.stopNodes.length;e++){let t=this.options.stopNodes[e];typeof t==`string`&&(t.startsWith(`*.`)?this.stopNodesWildcard.add(t.substring(2)):this.stopNodesExact.add(t))}}}};function addExternalEntities(e){let t=Object.keys(e);for(let n=0;n<t.length;n++){let r=t[n],i=r.replace(/[.\-+*:]/g,`\\.`);this.lastEntities[r]={regex:RegExp(`&`+i+`;`,`g`),val:e[r]}}}function parseTextData(e,t,n,r,i,a,o){if(e!==void 0&&(this.options.trimValues&&!r&&(e=e.trim()),e.length>0)){o||(e=this.replaceEntitiesValue(e,t,n));let r=this.options.tagValueProcessor(t,e,n,i,a);return r==null?e:typeof r!=typeof e||r!==e?r:this.options.trimValues||e.trim()===e?parseValue(e,this.options.parseTagValue,this.options.numberParseOptions):e}}function resolveNameSpace(e){if(this.options.removeNSPrefix){let t=e.split(`:`),n=e.charAt(0)===`/`?`/`:``;if(t[0]===`xmlns`)return``;t.length===2&&(e=n+t[1])}return e}const Fn=RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,`gm`);function buildAttributesMap(e,t,n){if(this.options.ignoreAttributes!==!0&&typeof e==`string`){let r=getAllMatches(e,Fn),i=r.length,a={};for(let e=0;e<i;e++){let i=this.resolveNameSpace(r[e][1]);if(this.ignoreAttributesFn(i,t))continue;let o=r[e][4],s=this.options.attributeNamePrefix+i;if(i.length)if(this.options.transformAttributeName&&(s=this.options.transformAttributeName(s)),s===`__proto__`&&(s=`#__proto__`),o!==void 0){this.options.trimValues&&(o=o.trim()),o=this.replaceEntitiesValue(o,n,t);let e=this.options.attributeValueProcessor(i,o,t);e==null?a[s]=o:typeof e!=typeof o||e!==o?a[s]=e:a[s]=parseValue(o,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(a[s]=!0)}if(!Object.keys(a).length)return;if(this.options.attributesGroupName){let e={};return e[this.options.attributesGroupName]=a,e}return a}}const parseXml=function(e){e=e.replace(/\r\n?/g,`
|
|
174
|
+
`);let t=new XmlNode(`!xml`),n=t,r=``,i=``;this.entityExpansionCount=0,this.currentExpandedLength=0;let a=new DocTypeReader(this.options.processEntities);for(let o=0;o<e.length;o++)if(e[o]===`<`)if(e[o+1]===`/`){let t=findClosingIndex(e,`>`,o,`Closing Tag is not closed.`),a=e.substring(o+2,t).trim();if(this.options.removeNSPrefix){let e=a.indexOf(`:`);e!==-1&&(a=a.substr(e+1))}this.options.transformTagName&&(a=this.options.transformTagName(a)),n&&(r=this.saveTextToParentTag(r,n,i));let s=i.substring(i.lastIndexOf(`.`)+1);if(a&&this.options.unpairedTags.indexOf(a)!==-1)throw Error(`Unpaired tag can not be used as closing tag: </${a}>`);let c=0;s&&this.options.unpairedTags.indexOf(s)!==-1?(c=i.lastIndexOf(`.`,i.lastIndexOf(`.`)-1),this.tagsNodeStack.pop()):c=i.lastIndexOf(`.`),i=i.substring(0,c),n=this.tagsNodeStack.pop(),r=``,o=t}else if(e[o+1]===`?`){let t=readTagExp(e,o,!1,`?>`);if(!t)throw Error(`Pi Tag is not closed.`);if(r=this.saveTextToParentTag(r,n,i),!(this.options.ignoreDeclaration&&t.tagName===`?xml`||this.options.ignorePiTags)){let e=new XmlNode(t.tagName);e.add(this.options.textNodeName,``),t.tagName!==t.tagExp&&t.attrExpPresent&&(e[`:@`]=this.buildAttributesMap(t.tagExp,i,t.tagName)),this.addChild(n,e,i,o)}o=t.closeIndex+1}else if(e.substr(o+1,3)===`!--`){let t=findClosingIndex(e,`-->`,o+4,`Comment is not closed.`);if(this.options.commentPropName){let a=e.substring(o+4,t-2);r=this.saveTextToParentTag(r,n,i),n.add(this.options.commentPropName,[{[this.options.textNodeName]:a}])}o=t}else if(e.substr(o+1,2)===`!D`){let t=a.readDocType(e,o);this.docTypeEntities=t.entities,o=t.i}else if(e.substr(o+1,2)===`![`){let t=findClosingIndex(e,`]]>`,o,`CDATA is not closed.`)-2,a=e.substring(o+9,t);r=this.saveTextToParentTag(r,n,i);let s=this.parseTextData(a,n.tagname,i,!0,!1,!0,!0);s??=``,this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:a}]):n.add(this.options.textNodeName,s),o=t+2}else{let a=readTagExp(e,o,this.options.removeNSPrefix),s=a.tagName,c=a.rawTagName,l=a.tagExp,u=a.attrExpPresent,d=a.closeIndex;if(this.options.transformTagName){let e=this.options.transformTagName(s);l===s&&(l=e),s=e}if(this.options.strictReservedNames&&(s===this.options.commentPropName||s===this.options.cdataPropName))throw Error(`Invalid tag name: ${s}`);n&&r&&n.tagname!==`!xml`&&(r=this.saveTextToParentTag(r,n,i,!1));let f=n;f&&this.options.unpairedTags.indexOf(f.tagname)!==-1&&(n=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf(`.`))),s!==t.tagname&&(i+=i?`.`+s:s);let p=o;if(this.isItStopNode(this.stopNodesExact,this.stopNodesWildcard,i,s)){let t=``;if(l.length>0&&l.lastIndexOf(`/`)===l.length-1)s[s.length-1]===`/`?(s=s.substr(0,s.length-1),i=i.substr(0,i.length-1),l=s):l=l.substr(0,l.length-1),o=a.closeIndex;else if(this.options.unpairedTags.indexOf(s)!==-1)o=a.closeIndex;else{let n=this.readStopNodeData(e,c,d+1);if(!n)throw Error(`Unexpected end of ${c}`);o=n.i,t=n.tagContent}let r=new XmlNode(s);s!==l&&u&&(r[`:@`]=this.buildAttributesMap(l,i,s)),t&&=this.parseTextData(t,s,i,!0,u,!0,!0),i=i.substr(0,i.lastIndexOf(`.`)),r.add(this.options.textNodeName,t),this.addChild(n,r,i,p)}else{if(l.length>0&&l.lastIndexOf(`/`)===l.length-1){if(s[s.length-1]===`/`?(s=s.substr(0,s.length-1),i=i.substr(0,i.length-1),l=s):l=l.substr(0,l.length-1),this.options.transformTagName){let e=this.options.transformTagName(s);l===s&&(l=e),s=e}let e=new XmlNode(s);s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i,s)),this.addChild(n,e,i,p),i=i.substr(0,i.lastIndexOf(`.`))}else if(this.options.unpairedTags.indexOf(s)!==-1){let e=new XmlNode(s);s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i)),this.addChild(n,e,i,p),i=i.substr(0,i.lastIndexOf(`.`)),o=a.closeIndex;continue}else{let e=new XmlNode(s);if(this.tagsNodeStack.length>this.options.maxNestedTags)throw Error(`Maximum nested tags exceeded`);this.tagsNodeStack.push(n),s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i,s)),this.addChild(n,e,i,p),n=e}r=``,o=d}}else r+=e[o];return t.child};function addChild(e,t,n,r){this.options.captureMetaData||(r=void 0);let i=this.options.updateTag(t.tagname,n,t[`:@`]);i===!1||(typeof i==`string`&&(t.tagname=i),e.addChild(t,r))}const In=__name(function(e,t,n){if(e.indexOf(`&`)===-1)return e;let r=this.options.processEntities;if(!r.enabled||r.allowedTags&&!r.allowedTags.includes(t)||r.tagFilter&&!r.tagFilter(t,n))return e;for(let t in this.docTypeEntities){let n=this.docTypeEntities[t],i=e.match(n.regx);if(i){if(this.entityExpansionCount+=i.length,r.maxTotalExpansions&&this.entityExpansionCount>r.maxTotalExpansions)throw Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${r.maxTotalExpansions}`);let t=e.length;if(e=e.replace(n.regx,n.val),r.maxExpandedLength&&(this.currentExpandedLength+=e.length-t,this.currentExpandedLength>r.maxExpandedLength))throw Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${r.maxExpandedLength}`)}}if(e.indexOf(`&`)===-1)return e;for(let t in this.lastEntities){let n=this.lastEntities[t];e=e.replace(n.regex,n.val)}if(e.indexOf(`&`)===-1)return e;if(this.options.htmlEntities)for(let t in this.htmlEntities){let n=this.htmlEntities[t];e=e.replace(n.regex,n.val)}return e=e.replace(this.ampEntity.regex,this.ampEntity.val),e},`replaceEntitiesValue`);function saveTextToParentTag(e,t,n,r){return e&&=(r===void 0&&(r=t.child.length===0),e=this.parseTextData(e,t.tagname,n,!1,t[`:@`]?Object.keys(t[`:@`]).length!==0:!1,r),e!==void 0&&e!==``&&t.add(this.options.textNodeName,e),``),e}function isItStopNode(e,t,n,r){return!!(t&&t.has(r)||e&&e.has(n))}function tagExpWithClosingIndex(e,t,n=`>`){let r,i=``;for(let a=t;a<e.length;a++){let t=e[a];if(r)t===r&&(r=``);else if(t===`"`||t===`'`)r=t;else if(t===n[0])if(n[1]){if(e[a+1]===n[1])return{data:i,index:a}}else return{data:i,index:a};else t===` `&&(t=` `);i+=t}}function findClosingIndex(e,t,n,r){let i=e.indexOf(t,n);if(i===-1)throw Error(r);return i+t.length-1}function readTagExp(e,t,n,r=`>`){let i=tagExpWithClosingIndex(e,t+1,r);if(!i)return;let a=i.data,o=i.index,s=a.search(/\s/),c=a,l=!0;s!==-1&&(c=a.substring(0,s),a=a.substring(s+1).trimStart());let u=c;if(n){let e=c.indexOf(`:`);e!==-1&&(c=c.substr(e+1),l=c!==i.data.substr(e+1))}return{tagName:c,tagExp:a,closeIndex:o,attrExpPresent:l,rawTagName:u}}function readStopNodeData(e,t,n){let r=n,i=1;for(;n<e.length;n++)if(e[n]===`<`)if(e[n+1]===`/`){let a=findClosingIndex(e,`>`,n,`${t} is not closed`);if(e.substring(n+2,a).trim()===t&&(i--,i===0))return{tagContent:e.substring(r,n),i:a};n=a}else if(e[n+1]===`?`)n=findClosingIndex(e,`?>`,n+1,`StopNode is not closed.`);else if(e.substr(n+1,3)===`!--`)n=findClosingIndex(e,`-->`,n+3,`StopNode is not closed.`);else if(e.substr(n+1,2)===`![`)n=findClosingIndex(e,`]]>`,n,`StopNode is not closed.`)-2;else{let r=readTagExp(e,n,`>`);r&&((r&&r.tagName)===t&&r.tagExp[r.tagExp.length-1]!==`/`&&i++,n=r.closeIndex)}}function parseValue(e,t,n){if(t&&typeof e==`string`){let t=e.trim();return t===`true`?!0:t===`false`?!1:toNumber(e,n)}else if(isExist(e))return e;else return``}function fromCodePoint(e,t,n){let r=Number.parseInt(e,t);return r>=0&&r<=1114111?String.fromCodePoint(r):n+e+`;`}const Ln=XmlNode.getMetaDataSymbol();function prettify(e,t){return compress(e,t)}function compress(e,t,n){let r,i={};for(let a=0;a<e.length;a++){let o=e[a],s=propName$1(o),c=``;if(c=n===void 0?s:n+`.`+s,s===t.textNodeName)r===void 0?r=o[s]:r+=``+o[s];else if(s===void 0)continue;else if(o[s]){let e=compress(o[s],t,c),n=isLeafTag(e,t);o[`:@`]?assignAttributes(e,o[`:@`],c,t):Object.keys(e).length===1&&e[t.textNodeName]!==void 0&&!t.alwaysCreateTextNode?e=e[t.textNodeName]:Object.keys(e).length===0&&(t.alwaysCreateTextNode?e[t.textNodeName]=``:e=``),o[Ln]!==void 0&&typeof e==`object`&&e&&(e[Ln]=o[Ln]),i[s]!==void 0&&Object.prototype.hasOwnProperty.call(i,s)?(Array.isArray(i[s])||(i[s]=[i[s]]),i[s].push(e)):t.isArray(s,c,n)?i[s]=[e]:i[s]=e}}return typeof r==`string`?r.length>0&&(i[t.textNodeName]=r):r!==void 0&&(i[t.textNodeName]=r),i}function propName$1(e){let t=Object.keys(e);for(let e=0;e<t.length;e++){let n=t[e];if(n!==`:@`)return n}}__name(propName$1,`propName`);function assignAttributes(e,t,n,r){if(t){let i=Object.keys(t),a=i.length;for(let o=0;o<a;o++){let a=i[o];r.isArray(a,n+`.`+a,!0,!0)?e[a]=[t[a]]:e[a]=t[a]}}}function isLeafTag(e,t){let{textNodeName:n}=t,r=Object.keys(e).length;return!!(r===0||r===1&&(e[n]||typeof e[n]==`boolean`||e[n]===0))}var XMLParser=class{constructor(e){this.externalEntities={},this.options=buildOptions(e)}parse(e,t){if(typeof e!=`string`&&e.toString)e=e.toString();else if(typeof e!=`string`)throw Error(`XML data is accepted in String or Bytes[] form.`);if(t){t===!0&&(t={});let n=validate(e,t);if(n!==!0)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}let n=new OrderedObjParser(this.options);n.addExternalEntities(this.externalEntities);let r=n.parseXml(e);return this.options.preserveOrder||r===void 0?r:prettify(r,this.options)}addEntity(e,t){if(t.indexOf(`&`)!==-1)throw Error(`Entity value can't have '&'`);if(e.indexOf(`&`)!==-1||e.indexOf(`;`)!==-1)throw Error(`An entity must be set without '&' and ';'. Eg. use '#xD' for '
'`);if(t===`&`)throw Error(`An entity with value '&' is not permitted`);this.externalEntities[e]=t}static getMetaDataSymbol(){return XmlNode.getMetaDataSymbol()}},Expression=class{constructor(e,t={}){this.pattern=e,this.separator=t.separator||`.`,this.segments=this._parse(e),this._hasDeepWildcard=this.segments.some(e=>e.type===`deep-wildcard`),this._hasAttributeCondition=this.segments.some(e=>e.attrName!==void 0),this._hasPositionSelector=this.segments.some(e=>e.position!==void 0)}_parse(e){let t=[],n=0,r=``;for(;n<e.length;)e[n]===this.separator?n+1<e.length&&e[n+1]===this.separator?(r.trim()&&(t.push(this._parseSegment(r.trim())),r=``),t.push({type:`deep-wildcard`}),n+=2):(r.trim()&&t.push(this._parseSegment(r.trim())),r=``,n++):(r+=e[n],n++);return r.trim()&&t.push(this._parseSegment(r.trim())),t}_parseSegment(e){let t={type:`tag`},n=null,r=e,i=e.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(i&&(r=i[1]+i[3],i[2])){let e=i[2].slice(1,-1);e&&(n=e)}let a,o=r;if(r.includes(`::`)){let t=r.indexOf(`::`);if(a=r.substring(0,t).trim(),o=r.substring(t+2).trim(),!a)throw Error(`Invalid namespace in pattern: ${e}`)}let s,c=null;if(o.includes(`:`)){let e=o.lastIndexOf(`:`),t=o.substring(0,e).trim(),n=o.substring(e+1).trim();[`first`,`last`,`odd`,`even`].includes(n)||/^nth\(\d+\)$/.test(n)?(s=t,c=n):s=o}else s=o;if(!s)throw Error(`Invalid segment pattern: ${e}`);if(t.tag=s,a&&(t.namespace=a),n)if(n.includes(`=`)){let e=n.indexOf(`=`);t.attrName=n.substring(0,e).trim(),t.attrValue=n.substring(e+1).trim()}else t.attrName=n.trim();if(c){let e=c.match(/^nth\((\d+)\)$/);e?(t.position=`nth`,t.positionValue=parseInt(e[1],10)):t.position=c}return t}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}},Matcher=class{constructor(e={}){this.separator=e.separator||`.`,this.path=[],this.siblingStacks=[]}push(e,t=null,n=null){if(this.path.length>0){let e=this.path[this.path.length-1];e.values=void 0}let r=this.path.length;this.siblingStacks[r]||(this.siblingStacks[r]=new Map);let i=this.siblingStacks[r],a=n?`${n}:${e}`:e,o=i.get(a)||0,s=0;for(let e of i.values())s+=e;i.set(a,o+1);let c={tag:e,position:s,counter:o};n!=null&&(c.namespace=n),t!=null&&(c.values=t),this.path.push(c)}pop(){if(this.path.length===0)return;let e=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),e}updateCurrent(e){if(this.path.length>0){let t=this.path[this.path.length-1];e!=null&&(t.values=e)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(e){if(this.path.length!==0)return this.path[this.path.length-1].values?.[e]}hasAttr(e){if(this.path.length===0)return!1;let t=this.path[this.path.length-1];return t.values!==void 0&&e in t.values}getPosition(){return this.path.length===0?-1:this.path[this.path.length-1].position??0}getCounter(){return this.path.length===0?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(e,t=!0){let n=e||this.separator;return this.path.map(e=>t&&e.namespace?`${e.namespace}:${e.tag}`:e.tag).join(n)}toArray(){return this.path.map(e=>e.tag)}reset(){this.path=[],this.siblingStacks=[]}matches(e){let t=e.segments;return t.length===0?!1:e.hasDeepWildcard()?this._matchWithDeepWildcard(t):this._matchSimple(t)}_matchSimple(e){if(this.path.length!==e.length)return!1;for(let t=0;t<e.length;t++){let n=e[t],r=this.path[t],i=t===this.path.length-1;if(!this._matchSegment(n,r,i))return!1}return!0}_matchWithDeepWildcard(e){let t=this.path.length-1,n=e.length-1;for(;n>=0&&t>=0;){let r=e[n];if(r.type===`deep-wildcard`){if(n--,n<0)return!0;let r=e[n],i=!1;for(let e=t;e>=0;e--){let a=e===this.path.length-1;if(this._matchSegment(r,this.path[e],a)){t=e-1,n--,i=!0;break}}if(!i)return!1}else{let e=t===this.path.length-1;if(!this._matchSegment(r,this.path[t],e))return!1;t--,n--}}return n<0}_matchSegment(e,t,n){if(e.tag!==`*`&&e.tag!==t.tag||e.namespace!==void 0&&e.namespace!==`*`&&e.namespace!==t.namespace)return!1;if(e.attrName!==void 0){if(!n||!t.values||!(e.attrName in t.values))return!1;if(e.attrValue!==void 0){let n=t.values[e.attrName];if(String(n)!==String(e.attrValue))return!1}}if(e.position!==void 0){if(!n)return!1;let r=t.counter??0;if(e.position===`first`&&r!==0||e.position===`odd`&&r%2!=1||e.position===`even`&&r%2!=0||e.position===`nth`&&r!==e.positionValue)return!1}return!0}snapshot(){return{path:this.path.map(e=>({...e})),siblingStacks:this.siblingStacks.map(e=>new Map(e))}}restore(e){this.path=e.path.map(e=>({...e})),this.siblingStacks=e.siblingStacks.map(e=>new Map(e))}};const Rn=`
|
|
175
|
+
`;function toXml(e,t){let n=``;t.format&&t.indentBy.length>0&&(n=`
|
|
176
|
+
`);let r=[];if(t.stopNodes&&Array.isArray(t.stopNodes))for(let e=0;e<t.stopNodes.length;e++){let n=t.stopNodes[e];typeof n==`string`?r.push(new Expression(n)):n instanceof Expression&&r.push(n)}let i=new Matcher;return arrToStr(e,t,n,i,r)}function arrToStr(e,t,n,r,i){let a=``,o=!1;if(!Array.isArray(e)){if(e!=null){let n=e.toString();return n=replaceEntitiesValue(n,t),n}return``}for(let s=0;s<e.length;s++){let c=e[s],l=propName(c);if(l===void 0)continue;let u=extractAttributeValues(c[`:@`],t);r.push(l,u);let d=checkStopNode(r,i);if(l===t.textNodeName){let e=c[l];d||(e=t.tagValueProcessor(l,e),e=replaceEntitiesValue(e,t)),o&&(a+=n),a+=e,o=!1,r.pop();continue}else if(l===t.cdataPropName){o&&(a+=n),a+=`<![CDATA[${c[l][0][t.textNodeName]}]]>`,o=!1,r.pop();continue}else if(l===t.commentPropName){a+=n+`<!--${c[l][0][t.textNodeName]}-->`,o=!0,r.pop();continue}else if(l[0]===`?`){let e=attr_to_str(c[`:@`],t,d),i=l===`?xml`?``:n,s=c[l][0][t.textNodeName];s=s.length===0?``:` `+s,a+=i+`<${l}${s}${e}?>`,o=!0,r.pop();continue}let f=n;f!==``&&(f+=t.indentBy);let p=n+`<${l}${attr_to_str(c[`:@`],t,d)}`,m;m=d?getRawContent(c[l],t):arrToStr(c[l],t,f,r,i),t.unpairedTags.indexOf(l)===-1?(!m||m.length===0)&&t.suppressEmptyNode?a+=p+`/>`:m&&m.endsWith(`>`)?a+=p+`>${m}${n}</${l}>`:(a+=p+`>`,m&&n!==``&&(m.includes(`/>`)||m.includes(`</`))?a+=n+t.indentBy+m+n:a+=m,a+=`</${l}>`):t.suppressUnpairedNode?a+=p+`>`:a+=p+`/>`,o=!0,r.pop()}return a}function extractAttributeValues(e,t){if(!e||t.ignoreAttributes)return null;let n={},r=!1;for(let i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;let a=i.startsWith(t.attributeNamePrefix)?i.substr(t.attributeNamePrefix.length):i;n[a]=e[i],r=!0}return r?n:null}function getRawContent(e,t){if(!Array.isArray(e))return e==null?``:e.toString();let n=``;for(let r=0;r<e.length;r++){let i=e[r],a=propName(i);if(a===t.textNodeName)n+=i[a];else if(a===t.cdataPropName)n+=i[a][0][t.textNodeName];else if(a===t.commentPropName)n+=i[a][0][t.textNodeName];else if(a&&a[0]===`?`)continue;else if(a){let e=attr_to_str_raw(i[`:@`],t),r=getRawContent(i[a],t);!r||r.length===0?n+=`<${a}${e}/>`:n+=`<${a}${e}>${r}</${a}>`}}return n}function attr_to_str_raw(e,t){let n=``;if(e&&!t.ignoreAttributes)for(let r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;let i=e[r];i===!0&&t.suppressBooleanAttributes?n+=` ${r.substr(t.attributeNamePrefix.length)}`:n+=` ${r.substr(t.attributeNamePrefix.length)}="${i}"`}return n}function propName(e){let t=Object.keys(e);for(let n=0;n<t.length;n++){let r=t[n];if(Object.prototype.hasOwnProperty.call(e,r)&&r!==`:@`)return r}}function attr_to_str(e,t,n){let r=``;if(e&&!t.ignoreAttributes)for(let i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;let a;n?a=e[i]:(a=t.attributeValueProcessor(i,e[i]),a=replaceEntitiesValue(a,t)),a===!0&&t.suppressBooleanAttributes?r+=` ${i.substr(t.attributeNamePrefix.length)}`:r+=` ${i.substr(t.attributeNamePrefix.length)}="${a}"`}return r}function checkStopNode(e,t){if(!t||t.length===0)return!1;for(let n=0;n<t.length;n++)if(e.matches(t[n]))return!0;return!1}function replaceEntitiesValue(e,t){if(e&&e.length>0&&t.processEntities)for(let n=0;n<t.entities.length;n++){let r=t.entities[n];e=e.replace(r.regex,r.val)}return e}function getIgnoreAttributesFn(e){return typeof e==`function`?e:Array.isArray(e)?t=>{for(let n of e)if(typeof n==`string`&&t===n||n instanceof RegExp&&n.test(t))return!0}:()=>!1}const zn={attributeNamePrefix:`@_`,attributesGroupName:!1,textNodeName:`#text`,ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:` `,suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(e,t){return t},attributeValueProcessor:function(e,t){return t},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:RegExp(`&`,`g`),val:`&`},{regex:RegExp(`>`,`g`),val:`>`},{regex:RegExp(`<`,`g`),val:`<`},{regex:RegExp(`'`,`g`),val:`'`},{regex:RegExp(`"`,`g`),val:`"`}],processEntities:!0,stopNodes:[],oneListGroup:!1,jPath:!0};function Builder(e){if(this.options=Object.assign({},zn,e),this.options.stopNodes&&Array.isArray(this.options.stopNodes)&&(this.options.stopNodes=this.options.stopNodes.map(e=>typeof e==`string`&&e.startsWith(`*.`)?`..`+e.substring(2):e)),this.stopNodeExpressions=[],this.options.stopNodes&&Array.isArray(this.options.stopNodes))for(let e=0;e<this.options.stopNodes.length;e++){let t=this.options.stopNodes[e];typeof t==`string`?this.stopNodeExpressions.push(new Expression(t)):t instanceof Expression&&this.stopNodeExpressions.push(t)}this.options.ignoreAttributes===!0||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn=getIgnoreAttributesFn(this.options.ignoreAttributes),this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=isAttribute),this.processTextOrObjNode=processTextOrObjNode,this.options.format?(this.indentate=indentate,this.tagEndChar=`>
|
|
177
177
|
`,this.newLine=`
|
|
178
|
-
`):(this.indentate=function(){return``},this.tagEndChar=`>`,this.newLine=``)}Builder.prototype.build=function(e){return this.options.preserveOrder?toXml(e,this.options):(Array.isArray(e)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(e={[this.options.arrayNodeName]:e}),this.j2x(e,0,[]).val)},Builder.prototype.j2x=function(e,t,n){let r=``,i=``,a=n.join(`.`);for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o))if(e[o]===void 0)this.isAttribute(o)&&(i+=``);else if(e[o]===null)this.isAttribute(o)||o===this.options.cdataPropName?i+=``:o[0]===`?`?i+=this.indentate(t)+`<`+o+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+o+`/`+this.tagEndChar;else if(e[o]instanceof Date)i+=this.buildTextValNode(e[o],o,``,t);else if(typeof e[o]!=`object`){let n=this.isAttribute(o);if(n&&!this.ignoreAttributesFn(n,a))r+=this.buildAttrPairStr(n,``+e[o]);else if(!n)if(o===this.options.textNodeName){let t=this.options.tagValueProcessor(o,``+e[o]);i+=this.replaceEntitiesValue(t)}else i+=this.buildTextValNode(e[o],o,``,t)}else if(Array.isArray(e[o])){let r=e[o].length,a=``,s=``;for(let c=0;c<r;c++){let r=e[o][c];if(r!==void 0)if(r===null)o[0]===`?`?i+=this.indentate(t)+`<`+o+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+o+`/`+this.tagEndChar;else if(typeof r==`object`)if(this.options.oneListGroup){let e=this.j2x(r,t+1,n.concat(o));a+=e.val,this.options.attributesGroupName&&r.hasOwnProperty(this.options.attributesGroupName)&&(s+=e.attrStr)}else a+=this.processTextOrObjNode(r,o,t,n);else if(this.options.oneListGroup){let e=this.options.tagValueProcessor(o,r);e=this.replaceEntitiesValue(e),a+=e}else a+=this.buildTextValNode(r,o,``,t)}this.options.oneListGroup&&(a=this.buildObjectNode(a,o,s,t)),i+=a}else if(this.options.attributesGroupName&&o===this.options.attributesGroupName){let t=Object.keys(e[o]),n=t.length;for(let i=0;i<n;i++)r+=this.buildAttrPairStr(t[i],``+e[o][t[i]])}else i+=this.processTextOrObjNode(e[o],o,t,n);return{attrStr:r,val:i}},Builder.prototype.buildAttrPairStr=function(e,t){return t=this.options.attributeValueProcessor(e,``+t),t=this.replaceEntitiesValue(t),this.options.suppressBooleanAttributes&&t===`true`?` `+e:` `+e+`="`+t+`"`};function processTextOrObjNode(e,t,n,r){let i=this.j2x(e,n+1,r.concat(t));return e[this.options.textNodeName]!==void 0&&Object.keys(e).length===1?this.buildTextValNode(e[this.options.textNodeName],t,i.attrStr,n):this.buildObjectNode(i.val,t,i.attrStr,n)}Builder.prototype.buildObjectNode=function(e,t,n,r){if(e===``)return t[0]===`?`?this.indentate(r)+`<`+t+n+`?`+this.tagEndChar:this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar;{let i=`</`+t+this.tagEndChar,a=``;return t[0]===`?`&&(a=`?`,i=``),(n||n===``)&&e.indexOf(`<`)===-1?this.indentate(r)+`<`+t+n+a+`>`+e+i:this.options.commentPropName!==!1&&t===this.options.commentPropName&&a.length===0?this.indentate(r)+`<!--${e}-->`+this.newLine:this.indentate(r)+`<`+t+n+a+this.tagEndChar+e+this.indentate(r)+i}},Builder.prototype.closeTag=function(e){let t=``;return this.options.unpairedTags.indexOf(e)===-1?t=this.options.suppressEmptyNode?`/`:`></${e}`:this.options.suppressUnpairedNode||(t=`/`),t},Builder.prototype.buildTextValNode=function(e,t,n,r){if(this.options.cdataPropName!==!1&&t===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${e}]]>`+this.newLine;if(this.options.commentPropName!==!1&&t===this.options.commentPropName)return this.indentate(r)+`<!--${e}-->`+this.newLine;if(t[0]===`?`)return this.indentate(r)+`<`+t+n+`?`+this.tagEndChar;{let i=this.options.tagValueProcessor(t,e);return i=this.replaceEntitiesValue(i),i===``?this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar:this.indentate(r)+`<`+t+n+`>`+i+`</`+t+this.tagEndChar}},Builder.prototype.replaceEntitiesValue=function(e){if(e&&e.length>0&&this.options.processEntities)for(let t=0;t<this.options.entities.length;t++){let n=this.options.entities[t];e=e.replace(n.regex,n.val)}return e};function indentate(e){return this.options.indentBy.repeat(e)}function isAttribute(e){return e.startsWith(this.options.attributeNamePrefix)&&e!==this.options.textNodeName?e.substr(this.attrPrefixLen):!1}const Bn={validate},Vn=`@_`;var SoapClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:s,requestConfig:c}){let l;if(l=typeof c?.envelope==`string`?c.envelope:typeof c?.envelope==`object`?Hn.build(c.envelope):await buildEnvelope(a,c),Bn.validate(l,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);let u,d={"Content-Type":`application/xml`,...r};c?.soapAction&&(d.SOAPAction=c.soapAction);try{u=await e?.request({method:n,url:t,headers:d,queryParams:i,maxRedirects:0,payload:l,requestConfig:c})}catch(e){if((0,o.isMissing)(e?.response))throw e;u=e.response}let f=Un.parse(u.data),p=f.Envelope||f,m=p.Body||p,h=m.Fault;if(h)throw new N({...u,status:500,data:h,message:h.faultstring??h.faultcode??`SOAP Fault`},h.faultstring??`SOAP Fault occurred`);u.data=m;let g=translateCustomError(u,s);if(isFailedStatusCode(g?.status))throw new N(g,g.message);return g}};const Hn=new Builder({attributeNamePrefix:`@_`,ignoreAttributes:!1,suppressBooleanAttributes:!1}),Un=new XMLParser({ignoreAttributes:!1,attributeNamePrefix:`_`,removeNSPrefix:!0,numberParseOptions:{leadingZeros:!1,hex:!1}}),buildEnvelope=async(e,t)=>{if((0,o.notMissing)(t?.envelope)){let e=typeof t.envelope==`string`?t.envelope:Hn.build(t.envelope);if(Bn.validate(e,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return e}let n=await buildSoapEnvelope(t,e),r=Hn.build(n);if(Bn.validate(r,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return r},buildSoapEnvelope=async(e,t)=>{let n=await Promise.all((e?.namespaces||[]).map(async e=>({identifier:await(0,c.evaluate)(e.namespaceIdentifier),namespace:await(0,c.evaluate)(e.namespace)})));n.forEach(({identifier:e,namespace:t})=>{if((0,o.isMissing)(e)||(0,o.isMissing)(t)||e===``||t===``)throw Error(`Invalid namespace config: both identifier and namespace are required`)});let r=n.reduce((e,{identifier:t,namespace:n})=>(e[`@_xmlns:${t}`]=n,e),{});return{"soapenv:Envelope":{"soapenv:Header":await buildSoapHeaders(t,e??{}),"soapenv:Body":await buildSoapBody(t,e?.soapOperation??``,n[0]?.identifier??``),"@_xmlns:soapenv":`http://schemas.xmlsoap.org/soap/envelope/`,...r}}},buildSoapHeaders=async(e,t)=>[await buildSoapSecurity(e,t)],buildSoapSecurity=async(e,t)=>{if((0,o.isMissing)(t.soapContext))return{};let{username:n,password:r}=t.soapContext;return{"wsse:Security":{"wsse:UsernameToken":{"wsse:Username":n,"wsse:Password":{"#text":r,"@_Type":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText`}},"@_soapenv:mustUnderstand":`1`,"@_xmlns:wsse":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd`,"@_xmlns:wsu":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd`}}},buildSoapBody=async(e,t,n)=>{if((0,o.isMissing)(t))throw Error(`Missing soapOperation in config`);let r=expandArrayAttributes({[t]:e});return(Array.isArray(r)?r:[r]).map(e=>applyNamespace(e,n))},expandArrayAttributes=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e)){if(e.length===1){let t=e[0];if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.keys(t).filter(e=>!e.startsWith(`@_`));if(e.length===1){let n=e[0],r=t[n];if(typeof r==`object`&&r&&!Array.isArray(r)){let e=Object.keys(r),t=e.filter(e=>e.startsWith(`@_`)),i=e.filter(e=>!e.startsWith(`@_`)),a=t.find(e=>Array.isArray(r[e]));if(a&&i.length===0){let e=r[a],i=t.filter(e=>e!==a),o=e.map(e=>{let t={[a]:e};for(let e of i)t[e]=r[e];return t});return{[n]:o}}}}}}return e.map(e=>expandArrayAttributes(e))}let t={};for(let n of Object.keys(e)){let r=e[n];t[n]=expandArrayAttributes(r)}return t},applyNamespace=(e,t)=>{if(typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>applyNamespace(e,t));let n={};for(let r in e){let i=applyNamespaceToKey(r,t);n[i]=applyNamespace(e[r],t)}return n},applyNamespaceToKey=(e,t)=>{let n=e.split(`:`);return n.length>1&&n[0]||e.indexOf(`${t}:`)===0||e===`#text`?e:e.startsWith(`@_`)?`@_${t}:${e.slice(2)}`:`${t}:${e}`};var RequestClientFactory=class{static build(e=`rest`){if(e===`rest`)return new RestClient;if(e===`soap`)return new SoapClient;throw Error(`Unknown request client type: ${e}`)}};exports.CUSTOM_ERROR_CONFIG_SCHEMA=ke,exports.ConcurrencyManager=ConcurrencyManager,exports.EventClient=EventClient,exports.HttpClient=HttpClient,exports.HttpClientManager=HttpClientManager,exports.HttpErrorMessages=Oe,exports.HttpMethods=_n,exports.HttpResponseError=N,exports.HttpTransportFactory=HttpTransportFactory,exports.InstanceManager=P,exports.LockManager=LockManager,exports.MemoryStore=MemoryStore,exports.QueryArrayFormats=xn,exports.QueueManager=QueueManager,exports.RateLimitManager=RateLimitManager,exports.RedisClient=te,exports.RequestClientFactory=RequestClientFactory,exports.RequestParameterLocations=bn,exports.ScriptManager=ScriptManager,exports.SubscriptionManager=SubscriptionManager,exports.buildHttpClientInstance=buildHttpClientInstance,exports.convertError=convertError,exports.createAuthorizationHeaders=createAuthorizationHeaders,exports.getRetryAfterWaitTime=getRetryAfterWaitTime,exports.getTransportInstance=getTransportInstance,exports.getTransportManagers=getTransportManagers,exports.initializeTransportSystem=initializeTransportSystem,exports.isFailedStatusCode=isFailedStatusCode,exports.isInfoStatusCode=isInfoStatusCode,exports.isSuccessStatusCode=isSuccessStatusCode,exports.isTransportSystemReady=isTransportSystemReady,exports.parseRequestParameters=parseRequestParameters,exports.serializeHttpResponseError=serializeHttpResponseError,exports.shutdownTransportSystem=shutdownTransportSystem,exports.superNormalizeHeaders=superNormalizeHeaders,exports.translateCustomError=translateCustomError;
|
|
178
|
+
`):(this.indentate=function(){return``},this.tagEndChar=`>`,this.newLine=``)}Builder.prototype.build=function(e){if(this.options.preserveOrder)return toXml(e,this.options);{Array.isArray(e)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(e={[this.options.arrayNodeName]:e});let t=new Matcher;return this.j2x(e,0,t).val}},Builder.prototype.j2x=function(e,t,n){let r=``,i=``,a=this.options.jPath?n.toString():n,o=this.checkStopNode(n);for(let s in e)if(Object.prototype.hasOwnProperty.call(e,s))if(e[s]===void 0)this.isAttribute(s)&&(i+=``);else if(e[s]===null)this.isAttribute(s)||s===this.options.cdataPropName?i+=``:s[0]===`?`?i+=this.indentate(t)+`<`+s+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+s+`/`+this.tagEndChar;else if(e[s]instanceof Date)i+=this.buildTextValNode(e[s],s,``,t,n);else if(typeof e[s]!=`object`){let c=this.isAttribute(s);if(c&&!this.ignoreAttributesFn(c,a))r+=this.buildAttrPairStr(c,``+e[s],o);else if(!c)if(s===this.options.textNodeName){let t=this.options.tagValueProcessor(s,``+e[s]);i+=this.replaceEntitiesValue(t)}else{n.push(s);let r=this.checkStopNode(n);if(n.pop(),r){let n=``+e[s];n===``?i+=this.indentate(t)+`<`+s+this.closeTag(s)+this.tagEndChar:i+=this.indentate(t)+`<`+s+`>`+n+`</`+s+this.tagEndChar}else i+=this.buildTextValNode(e[s],s,``,t,n)}}else if(Array.isArray(e[s])){let r=e[s].length,a=``,o=``;for(let c=0;c<r;c++){let r=e[s][c];if(r!==void 0)if(r===null)s[0]===`?`?i+=this.indentate(t)+`<`+s+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+s+`/`+this.tagEndChar;else if(typeof r==`object`)if(this.options.oneListGroup){n.push(s);let e=this.j2x(r,t+1,n);n.pop(),a+=e.val,this.options.attributesGroupName&&r.hasOwnProperty(this.options.attributesGroupName)&&(o+=e.attrStr)}else a+=this.processTextOrObjNode(r,s,t,n);else if(this.options.oneListGroup){let e=this.options.tagValueProcessor(s,r);e=this.replaceEntitiesValue(e),a+=e}else{n.push(s);let e=this.checkStopNode(n);if(n.pop(),e){let e=``+r;e===``?a+=this.indentate(t)+`<`+s+this.closeTag(s)+this.tagEndChar:a+=this.indentate(t)+`<`+s+`>`+e+`</`+s+this.tagEndChar}else a+=this.buildTextValNode(r,s,``,t,n)}}this.options.oneListGroup&&(a=this.buildObjectNode(a,s,o,t)),i+=a}else if(this.options.attributesGroupName&&s===this.options.attributesGroupName){let t=Object.keys(e[s]),n=t.length;for(let i=0;i<n;i++)r+=this.buildAttrPairStr(t[i],``+e[s][t[i]],o)}else i+=this.processTextOrObjNode(e[s],s,t,n);return{attrStr:r,val:i}},Builder.prototype.buildAttrPairStr=function(e,t,n){return n||(t=this.options.attributeValueProcessor(e,``+t),t=this.replaceEntitiesValue(t)),this.options.suppressBooleanAttributes&&t===`true`?` `+e:` `+e+`="`+t+`"`};function processTextOrObjNode(e,t,n,r){let i=this.extractAttributes(e);if(r.push(t,i),this.checkStopNode(r)){let i=this.buildRawContent(e),a=this.buildAttributesForStopNode(e);return r.pop(),this.buildObjectNode(i,t,a,n)}let a=this.j2x(e,n+1,r);return r.pop(),e[this.options.textNodeName]!==void 0&&Object.keys(e).length===1?this.buildTextValNode(e[this.options.textNodeName],t,a.attrStr,n,r):this.buildObjectNode(a.val,t,a.attrStr,n)}Builder.prototype.extractAttributes=function(e){if(!e||typeof e!=`object`)return null;let t={},n=!1;if(this.options.attributesGroupName&&e[this.options.attributesGroupName]){let r=e[this.options.attributesGroupName];for(let e in r){if(!Object.prototype.hasOwnProperty.call(r,e))continue;let i=e.startsWith(this.options.attributeNamePrefix)?e.substring(this.options.attributeNamePrefix.length):e;t[i]=r[e],n=!0}}else for(let r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;let i=this.isAttribute(r);i&&(t[i]=e[r],n=!0)}return n?t:null},Builder.prototype.buildRawContent=function(e){if(typeof e==`string`)return e;if(typeof e!=`object`||!e)return String(e);if(e[this.options.textNodeName]!==void 0)return e[this.options.textNodeName];let t=``;for(let n in e){if(!Object.prototype.hasOwnProperty.call(e,n)||this.isAttribute(n)||this.options.attributesGroupName&&n===this.options.attributesGroupName)continue;let r=e[n];if(n===this.options.textNodeName)t+=r;else if(Array.isArray(r)){for(let e of r)if(typeof e==`string`||typeof e==`number`)t+=`<${n}>${e}</${n}>`;else if(typeof e==`object`&&e){let r=this.buildRawContent(e),i=this.buildAttributesForStopNode(e);r===``?t+=`<${n}${i}/>`:t+=`<${n}${i}>${r}</${n}>`}}else if(typeof r==`object`&&r){let e=this.buildRawContent(r),i=this.buildAttributesForStopNode(r);e===``?t+=`<${n}${i}/>`:t+=`<${n}${i}>${e}</${n}>`}else t+=`<${n}>${r}</${n}>`}return t},Builder.prototype.buildAttributesForStopNode=function(e){if(!e||typeof e!=`object`)return``;let t=``;if(this.options.attributesGroupName&&e[this.options.attributesGroupName]){let n=e[this.options.attributesGroupName];for(let e in n){if(!Object.prototype.hasOwnProperty.call(n,e))continue;let r=e.startsWith(this.options.attributeNamePrefix)?e.substring(this.options.attributeNamePrefix.length):e,i=n[e];i===!0&&this.options.suppressBooleanAttributes?t+=` `+r:t+=` `+r+`="`+i+`"`}}else for(let n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;let r=this.isAttribute(n);if(r){let i=e[n];i===!0&&this.options.suppressBooleanAttributes?t+=` `+r:t+=` `+r+`="`+i+`"`}}return t},Builder.prototype.buildObjectNode=function(e,t,n,r){if(e===``)return t[0]===`?`?this.indentate(r)+`<`+t+n+`?`+this.tagEndChar:this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar;{let i=`</`+t+this.tagEndChar,a=``;return t[0]===`?`&&(a=`?`,i=``),(n||n===``)&&e.indexOf(`<`)===-1?this.indentate(r)+`<`+t+n+a+`>`+e+i:this.options.commentPropName!==!1&&t===this.options.commentPropName&&a.length===0?this.indentate(r)+`<!--${e}-->`+this.newLine:this.indentate(r)+`<`+t+n+a+this.tagEndChar+e+this.indentate(r)+i}},Builder.prototype.closeTag=function(e){let t=``;return this.options.unpairedTags.indexOf(e)===-1?t=this.options.suppressEmptyNode?`/`:`></${e}`:this.options.suppressUnpairedNode||(t=`/`),t},Builder.prototype.checkStopNode=function(e){if(!this.stopNodeExpressions||this.stopNodeExpressions.length===0)return!1;for(let t=0;t<this.stopNodeExpressions.length;t++)if(e.matches(this.stopNodeExpressions[t]))return!0;return!1},Builder.prototype.buildTextValNode=function(e,t,n,r,i){if(this.options.cdataPropName!==!1&&t===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${e}]]>`+this.newLine;if(this.options.commentPropName!==!1&&t===this.options.commentPropName)return this.indentate(r)+`<!--${e}-->`+this.newLine;if(t[0]===`?`)return this.indentate(r)+`<`+t+n+`?`+this.tagEndChar;{let i=this.options.tagValueProcessor(t,e);return i=this.replaceEntitiesValue(i),i===``?this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar:this.indentate(r)+`<`+t+n+`>`+i+`</`+t+this.tagEndChar}},Builder.prototype.replaceEntitiesValue=function(e){if(e&&e.length>0&&this.options.processEntities)for(let t=0;t<this.options.entities.length;t++){let n=this.options.entities[t];e=e.replace(n.regex,n.val)}return e};function indentate(e){return this.options.indentBy.repeat(e)}function isAttribute(e){return e.startsWith(this.options.attributeNamePrefix)&&e!==this.options.textNodeName?e.substr(this.attrPrefixLen):!1}var Bn=Builder;const Vn={validate},Hn=`@_`;var SoapClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:s,requestConfig:c}){let l;if(l=typeof c?.envelope==`string`?c.envelope:typeof c?.envelope==`object`?Un.build(c.envelope):await buildEnvelope(a,c),Vn.validate(l,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);let u,d={"Content-Type":`application/xml`,...r};c?.soapAction&&(d.SOAPAction=c.soapAction);try{u=await e?.request({method:n,url:t,headers:d,queryParams:i,maxRedirects:0,payload:l,requestConfig:c})}catch(e){if((0,o.isMissing)(e?.response))throw e;u=e.response}let f=Wn.parse(u.data),p=f.Envelope||f,m=p.Body||p,h=m.Fault;if(h)throw new N({...u,status:500,data:h,message:h.faultstring??h.faultcode??`SOAP Fault`},h.faultstring??`SOAP Fault occurred`);u.data=m;let g=translateCustomError(u,s);if(isFailedStatusCode(g?.status))throw new N(g,g.message);return g}};const Un=new Bn({attributeNamePrefix:`@_`,ignoreAttributes:!1,suppressBooleanAttributes:!1}),Wn=new XMLParser({ignoreAttributes:!1,attributeNamePrefix:`_`,removeNSPrefix:!0,numberParseOptions:{leadingZeros:!1,hex:!1}}),buildEnvelope=async(e,t)=>{if((0,o.notMissing)(t?.envelope)){let e=typeof t.envelope==`string`?t.envelope:Un.build(t.envelope);if(Vn.validate(e,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return e}let n=await buildSoapEnvelope(t,e),r=Un.build(n);if(Vn.validate(r,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return r},buildSoapEnvelope=async(e,t)=>{let n=await Promise.all((e?.namespaces||[]).map(async e=>({identifier:await(0,c.evaluate)(e.namespaceIdentifier),namespace:await(0,c.evaluate)(e.namespace)})));n.forEach(({identifier:e,namespace:t})=>{if((0,o.isMissing)(e)||(0,o.isMissing)(t)||e===``||t===``)throw Error(`Invalid namespace config: both identifier and namespace are required`)});let r=n.reduce((e,{identifier:t,namespace:n})=>(e[`@_xmlns:${t}`]=n,e),{});return{"soapenv:Envelope":{"soapenv:Header":await buildSoapHeaders(t,e??{}),"soapenv:Body":await buildSoapBody(t,e?.soapOperation??``,n[0]?.identifier??``),"@_xmlns:soapenv":`http://schemas.xmlsoap.org/soap/envelope/`,...r}}},buildSoapHeaders=async(e,t)=>[await buildSoapSecurity(e,t)],buildSoapSecurity=async(e,t)=>{if((0,o.isMissing)(t.soapContext))return{};let{username:n,password:r}=t.soapContext;return{"wsse:Security":{"wsse:UsernameToken":{"wsse:Username":n,"wsse:Password":{"#text":r,"@_Type":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText`}},"@_soapenv:mustUnderstand":`1`,"@_xmlns:wsse":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd`,"@_xmlns:wsu":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd`}}},buildSoapBody=async(e,t,n)=>{if((0,o.isMissing)(t))throw Error(`Missing soapOperation in config`);let r=expandArrayAttributes({[t]:e});return(Array.isArray(r)?r:[r]).map(e=>applyNamespace(e,n))},expandArrayAttributes=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e)){if(e.length===1){let t=e[0];if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.keys(t).filter(e=>!e.startsWith(`@_`));if(e.length===1){let n=e[0],r=t[n];if(typeof r==`object`&&r&&!Array.isArray(r)){let e=Object.keys(r),t=e.filter(e=>e.startsWith(`@_`)),i=e.filter(e=>!e.startsWith(`@_`)),a=t.find(e=>Array.isArray(r[e]));if(a&&i.length===0){let e=r[a],i=t.filter(e=>e!==a),o=e.map(e=>{let t={[a]:e};for(let e of i)t[e]=r[e];return t});return{[n]:o}}}}}}return e.map(e=>expandArrayAttributes(e))}let t={};for(let n of Object.keys(e)){let r=e[n];t[n]=expandArrayAttributes(r)}return t},applyNamespace=(e,t)=>{if(typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>applyNamespace(e,t));let n={};for(let r in e){let i=applyNamespaceToKey(r,t);n[i]=applyNamespace(e[r],t)}return n},applyNamespaceToKey=(e,t)=>{let n=e.split(`:`);return n.length>1&&n[0]||e.indexOf(`${t}:`)===0||e===`#text`?e:e.startsWith(`@_`)?`@_${t}:${e.slice(2)}`:`${t}:${e}`};var RequestClientFactory=class{static build(e=`rest`){if(e===`rest`)return new RestClient;if(e===`soap`)return new SoapClient;throw Error(`Unknown request client type: ${e}`)}};exports.CUSTOM_ERROR_CONFIG_SCHEMA=ke,exports.ConcurrencyManager=ConcurrencyManager,exports.EventClient=EventClient,exports.HttpClient=HttpClient,exports.HttpClientManager=HttpClientManager,exports.HttpErrorMessages=Oe,exports.HttpMethods=_n,exports.HttpResponseError=N,exports.HttpTransportFactory=HttpTransportFactory,exports.InstanceManager=P,exports.LockManager=LockManager,exports.MemoryStore=MemoryStore,exports.QueryArrayFormats=xn,exports.QueueManager=QueueManager,exports.RateLimitManager=RateLimitManager,exports.RedisClient=te,exports.RequestClientFactory=RequestClientFactory,exports.RequestParameterLocations=bn,exports.ScriptManager=ScriptManager,exports.SubscriptionManager=SubscriptionManager,exports.buildHttpClientInstance=buildHttpClientInstance,exports.convertError=convertError,exports.createAuthorizationHeaders=createAuthorizationHeaders,exports.getRetryAfterWaitTime=getRetryAfterWaitTime,exports.getTransportInstance=getTransportInstance,exports.getTransportManagers=getTransportManagers,exports.initializeTransportSystem=initializeTransportSystem,exports.isFailedStatusCode=isFailedStatusCode,exports.isInfoStatusCode=isInfoStatusCode,exports.isSuccessStatusCode=isSuccessStatusCode,exports.isTransportSystemReady=isTransportSystemReady,exports.parseRequestParameters=parseRequestParameters,exports.serializeHttpResponseError=serializeHttpResponseError,exports.shutdownTransportSystem=shutdownTransportSystem,exports.superNormalizeHeaders=superNormalizeHeaders,exports.translateCustomError=translateCustomError;
|
package/dist/index.mjs
CHANGED
|
@@ -170,8 +170,8 @@ Example:
|
|
|
170
170
|
return nil
|
|
171
171
|
`},initializeTransportSystem=async e=>{let{redisClientConfig:t,logger:n,generateUUID:r}=e;try{n?.info({category:`TransportInitialization`,message:`Starting transport system initialization`});let[e,i,a]=await Promise.all([SingletonManager.prepare(ConcurrencyManager,{redisClientConfig:t,scripts:de,logger:n,additionalArgs:r?[r]:void 0}),SingletonManager.prepare(QueueManager,{redisClientConfig:t,scripts:gt,logger:n}),SingletonManager.prepare(RateLimitManager,{redisClientConfig:t,scripts:_t,logger:n})]),o=[{name:`ConcurrencyManager`,ready:e.isReady()},{name:`QueueManager`,ready:i.isReady()},{name:`RateLimitManager`,ready:a.isReady()}],s=o.filter(e=>!e.ready);if(s.length>0){let e=s.map(e=>e.name).join(`, `);throw Error(`Failed to initialize managers: ${e}`)}return n?.info({category:`TransportInitialization`,message:`Transport system initialization completed successfully`,context:{initializedManagers:o.map(e=>e.name)}}),{concurrencyManager:e,queueManager:i,rateLimitManager:a}}catch(e){n?.error({category:`TransportInitialization`,message:`Failed to initialize transport system`,code:`TRANSPORT_INIT_ERROR`,error:e});let t=SingletonManager.cleanupFailed();throw t>0&&n?.info({category:`TransportInitialization`,message:`Cleaned up ${t} failed singleton instances`}),e}},shutdownTransportSystem=e=>{try{e?.info({category:`TransportInitialization`,message:`Starting transport system shutdown`});let t=SingletonManager.getIfReady(ConcurrencyManager),n=SingletonManager.getIfReady(QueueManager),r=SingletonManager.getIfReady(RateLimitManager);t?.close(),n?.close(),r?.close(),SingletonManager.reset(ConcurrencyManager),SingletonManager.reset(QueueManager),SingletonManager.reset(RateLimitManager),e?.info({category:`TransportInitialization`,message:`Transport system shutdown completed`})}catch(t){e?.error({category:`TransportInitialization`,message:`Error during transport system shutdown`,code:`TRANSPORT_SHUTDOWN_ERROR`,error:t})}},isTransportSystemReady=()=>{let e=SingletonManager.getIfReady(ConcurrencyManager),t=SingletonManager.getIfReady(QueueManager),n=SingletonManager.getIfReady(RateLimitManager);return!!(e?.isReady()&&t?.isReady()&&n?.isReady())},getTransportManagers=()=>{let e=SingletonManager.getIfReady(ConcurrencyManager),t=SingletonManager.getIfReady(QueueManager),n=SingletonManager.getIfReady(RateLimitManager);return e&&t&&n?{concurrencyManager:e,queueManager:t,rateLimitManager:n}:null},isHttpQueryParamValue=e=>typeof e==`object`&&!!e&&`value`in e&&(typeof e.value==`string`||Array.isArray(e.value)),toStringArray=e=>Array.isArray(e)?e:[e],toQueryValue=e=>Array.isArray(e)?e.map(String):String(e),mergeQueryValues=(e,t,n)=>{let r=toStringArray(t);if(isHttpQueryParamValue(e))return{value:[...toStringArray(e.value),...r],arrayFormat:n??e.arrayFormat};let i=[...toStringArray(e),...r];return n?{value:i,arrayFormat:n}:i},parseQueryParam=(e,t,n)=>{let r=toQueryValue(t);return e===void 0?n?{value:r,arrayFormat:n}:r:mergeQueryValues(e,r,n)},parseBodyParam=(e,t)=>Array.isArray(e)?e.concat(t):typeof e==`object`&&e&&typeof t==`object`&&t?{...e,...t}:t,parseRequestParameters=e=>e.reduce((e,t)=>{if(t.in===`query`){let n=e.query[t.name];e.query[t.name]=parseQueryParam(n,t.value,t.arrayFormat)}else if(t.in===`body`)if(t.spread)Array.isArray(t.value)?Array.isArray(e.body)?e.body=e.body.concat(t.value):e.body=t.value:typeof t.value==`object`&&t.value!==null&&(e.body={...e.body,...t.value});else{let n=e.body[t.name];e.body[t.name]=parseBodyParam(n,t.value)}else e.headers[t.name]=String(t.value);return e},{query:{},body:{},headers:{}}),vt=[`query`,`body`,`headers`],yt=[`repeat`,`brackets`,`comma`],isSuccessStatusCode=e=>p(e)&&e>=200&&e<=299,isFailedStatusCode=e=>p(e)&&e>=400&&e<=599,isInfoStatusCode=e=>p(e)&&e>=100&&e<=199;var RestClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:o,requestConfig:s}){let c;try{c=await e?.request({method:n,url:t,headers:r,queryParams:i,maxRedirects:0,payload:a,requestConfig:s})}catch(e){if(l(e?.response))throw e;c=e.response}let u=translateCustomError(c,o);if(isFailedStatusCode(u?.status))throw new me(u,u.message);return u}};const bt=`:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD`;bt+``,``+bt;const xt=RegExp(`^[:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$`);function getAllMatches(e,t){let n=[],r=t.exec(e);for(;r;){let i=[];i.startIndex=t.lastIndex-r[0].length;let a=r.length;for(let e=0;e<a;e++)i.push(r[e]);n.push(i),r=t.exec(e)}return n}const isName=function(e){return xt.exec(e)!=null};function isExist(e){return e!==void 0}const St={allowBooleanAttributes:!1,unpairedTags:[]};function validate(e,t){t=Object.assign({},St,t);let n=[],r=!1,i=!1;e[0]===``&&(e=e.substr(1));for(let a=0;a<e.length;a++)if(e[a]===`<`&&e[a+1]===`?`){if(a+=2,a=readPI(e,a),a.err)return a}else if(e[a]===`<`){let o=a;if(a++,e[a]===`!`){a=readCommentAndCDATA(e,a);continue}else{let s=!1;e[a]===`/`&&(s=!0,a++);let c=``;for(;a<e.length&&e[a]!==`>`&&e[a]!==` `&&e[a]!==` `&&e[a]!==`
|
|
172
172
|
`&&e[a]!==`\r`;a++)c+=e[a];if(c=c.trim(),c[c.length-1]===`/`&&(c=c.substring(0,c.length-1),a--),!validateTagName(c)){let t;return t=c.trim().length===0?`Invalid space after '<'.`:`Tag '`+c+`' is an invalid name.`,getErrorObject(`InvalidTag`,t,getLineNumberForPosition(e,a))}let l=readAttributeStr(e,a);if(l===!1)return getErrorObject(`InvalidAttr`,`Attributes for '`+c+`' have open quote.`,getLineNumberForPosition(e,a));let u=l.value;if(a=l.index,u[u.length-1]===`/`){let n=a-u.length;u=u.substring(0,u.length-1);let i=validateAttributeString(u,t);if(i===!0)r=!0;else return getErrorObject(i.err.code,i.err.msg,getLineNumberForPosition(e,n+i.err.line))}else if(s)if(l.tagClosed){if(u.trim().length>0)return getErrorObject(`InvalidTag`,`Closing tag '`+c+`' can't have attributes or invalid starting.`,getLineNumberForPosition(e,o));if(n.length===0)return getErrorObject(`InvalidTag`,`Closing tag '`+c+`' has not been opened.`,getLineNumberForPosition(e,o));{let t=n.pop();if(c!==t.tagName){let n=getLineNumberForPosition(e,t.tagStartPos);return getErrorObject(`InvalidTag`,`Expected closing tag '`+t.tagName+`' (opened in line `+n.line+`, col `+n.col+`) instead of closing tag '`+c+`'.`,getLineNumberForPosition(e,o))}n.length==0&&(i=!0)}}else return getErrorObject(`InvalidTag`,`Closing tag '`+c+`' doesn't have proper closing.`,getLineNumberForPosition(e,a));else{let s=validateAttributeString(u,t);if(s!==!0)return getErrorObject(s.err.code,s.err.msg,getLineNumberForPosition(e,a-u.length+s.err.line));if(i===!0)return getErrorObject(`InvalidXml`,`Multiple possible root nodes found.`,getLineNumberForPosition(e,a));t.unpairedTags.indexOf(c)!==-1||n.push({tagName:c,tagStartPos:o}),r=!0}for(a++;a<e.length;a++)if(e[a]===`<`)if(e[a+1]===`!`){a++,a=readCommentAndCDATA(e,a);continue}else if(e[a+1]===`?`){if(a=readPI(e,++a),a.err)return a}else break;else if(e[a]===`&`){let t=validateAmpersand(e,a);if(t==-1)return getErrorObject(`InvalidChar`,`char '&' is not expected.`,getLineNumberForPosition(e,a));a=t}else if(i===!0&&!isWhiteSpace(e[a]))return getErrorObject(`InvalidXml`,`Extra text at the end`,getLineNumberForPosition(e,a));e[a]===`<`&&a--}}else{if(isWhiteSpace(e[a]))continue;return getErrorObject(`InvalidChar`,`char '`+e[a]+`' is not expected.`,getLineNumberForPosition(e,a))}if(r){if(n.length==1)return getErrorObject(`InvalidTag`,`Unclosed tag '`+n[0].tagName+`'.`,getLineNumberForPosition(e,n[0].tagStartPos));if(n.length>0)return getErrorObject(`InvalidXml`,`Invalid '`+JSON.stringify(n.map(e=>e.tagName),null,4).replace(/\r?\n/g,``)+`' found.`,{line:1,col:1})}else return getErrorObject(`InvalidXml`,`Start tag expected.`,1);return!0}function isWhiteSpace(e){return e===` `||e===` `||e===`
|
|
173
|
-
`||e===`\r`}function readPI(e,t){let n=t;for(;t<e.length;t++)if(e[t]==`?`||e[t]==` `){let r=e.substr(n,t-n);if(t>5&&r===`xml`)return getErrorObject(`InvalidXml`,`XML declaration allowed only at the start of the document.`,getLineNumberForPosition(e,t));if(e[t]==`?`&&e[t+1]==`>`){t++;break}else continue}return t}function readCommentAndCDATA(e,t){if(e.length>t+5&&e[t+1]===`-`&&e[t+2]===`-`){for(t+=3;t<e.length;t++)if(e[t]===`-`&&e[t+1]===`-`&&e[t+2]===`>`){t+=2;break}}else if(e.length>t+8&&e[t+1]===`D`&&e[t+2]===`O`&&e[t+3]===`C`&&e[t+4]===`T`&&e[t+5]===`Y`&&e[t+6]===`P`&&e[t+7]===`E`){let n=1;for(t+=8;t<e.length;t++)if(e[t]===`<`)n++;else if(e[t]===`>`&&(n--,n===0))break}else if(e.length>t+9&&e[t+1]===`[`&&e[t+2]===`C`&&e[t+3]===`D`&&e[t+4]===`A`&&e[t+5]===`T`&&e[t+6]===`A`&&e[t+7]===`[`){for(t+=8;t<e.length;t++)if(e[t]===`]`&&e[t+1]===`]`&&e[t+2]===`>`){t+=2;break}}return t}function readAttributeStr(e,t){let n=``,r=``,i=!1;for(;t<e.length;t++){if(e[t]===`"`||e[t]===`'`)r===``?r=e[t]:r!==e[t]||(r=``);else if(e[t]===`>`&&r===``){i=!0;break}n+=e[t]}return r===``?{value:n,index:t,tagClosed:i}:!1}const Ct=RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,`g`);function validateAttributeString(e,t){let n=getAllMatches(e,Ct),r={};for(let e=0;e<n.length;e++){if(n[e][1].length===0)return getErrorObject(`InvalidAttr`,`Attribute '`+n[e][2]+`' has no space in starting.`,getPositionFromMatch(n[e]));if(n[e][3]!==void 0&&n[e][4]===void 0)return getErrorObject(`InvalidAttr`,`Attribute '`+n[e][2]+`' is without value.`,getPositionFromMatch(n[e]));if(n[e][3]===void 0&&!t.allowBooleanAttributes)return getErrorObject(`InvalidAttr`,`boolean attribute '`+n[e][2]+`' is not allowed.`,getPositionFromMatch(n[e]));let i=n[e][2];if(!validateAttrName(i))return getErrorObject(`InvalidAttr`,`Attribute '`+i+`' is an invalid name.`,getPositionFromMatch(n[e]));if(!r.hasOwnProperty(i))r[i]=1;else return getErrorObject(`InvalidAttr`,`Attribute '`+i+`' is repeated.`,getPositionFromMatch(n[e]))}return!0}function validateNumberAmpersand(e,t){let n=/\d/;for(e[t]===`x`&&(t++,n=/[\da-fA-F]/);t<e.length;t++){if(e[t]===`;`)return t;if(!e[t].match(n))break}return-1}function validateAmpersand(e,t){if(t++,e[t]===`;`)return-1;if(e[t]===`#`)return t++,validateNumberAmpersand(e,t);let n=0;for(;t<e.length;t++,n++)if(!(e[t].match(/\w/)&&n<20)){if(e[t]===`;`)break;return-1}return t}function getErrorObject(e,t,n){return{err:{code:e,msg:t,line:n.line||n,col:n.col}}}function validateAttrName(e){return isName(e)}function validateTagName(e){return isName(e)}function getLineNumberForPosition(e,t){let n=e.substring(0,t).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function getPositionFromMatch(e){return e.startIndex+e[1].length}const wt={preserveOrder:!1,attributeNamePrefix:`@_`,attributesGroupName:!1,textNodeName:`#text`,ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(e,t){return t},attributeValueProcessor:function(e,t){return t},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(e,t,n){return e},captureMetaData:!1},buildOptions=function(e){return Object.assign({},wt,e)};let Tt;Tt=typeof Symbol==`function`?Symbol(`XML Node Metadata`):`@@xmlMetadata`;var XmlNode=class{constructor(e){this.tagname=e,this.child=[],this[`:@`]={}}add(e,t){e===`__proto__`&&(e=`#__proto__`),this.child.push({[e]:t})}addChild(e,t){e.tagname===`__proto__`&&(e.tagname=`#__proto__`),e[`:@`]&&Object.keys(e[`:@`]).length>0?this.child.push({[e.tagname]:e.child,":@":e[`:@`]}):this.child.push({[e.tagname]:e.child}),t!==void 0&&(this.child[this.child.length-1][Tt]={startIndex:t})}static getMetaDataSymbol(){return Tt}};function readDocType(e,t){let n={};if(e[t+3]===`O`&&e[t+4]===`C`&&e[t+5]===`T`&&e[t+6]===`Y`&&e[t+7]===`P`&&e[t+8]===`E`){t+=9;let r=1,i=!1,a=!1,o=``;for(;t<e.length;t++)if(e[t]===`<`&&!a){if(i&&hasSeq(e,`!ENTITY`,t)){t+=7;let r,i;[r,i,t]=readEntityExp(e,t+1),i.indexOf(`&`)===-1&&(n[r]={regx:RegExp(`&${r};`,`g`),val:i})}else if(i&&hasSeq(e,`!ELEMENT`,t)){t+=8;let{index:n}=readElementExp(e,t+1);t=n}else if(i&&hasSeq(e,`!ATTLIST`,t))t+=8;else if(i&&hasSeq(e,`!NOTATION`,t)){t+=9;let{index:n}=readNotationExp(e,t+1);t=n}else if(hasSeq(e,`!--`,t))a=!0;else throw Error(`Invalid DOCTYPE`);r++,o=``}else if(e[t]===`>`){if(a?e[t-1]===`-`&&e[t-2]===`-`&&(a=!1,r--):r--,r===0)break}else e[t]===`[`?i=!0:o+=e[t];if(r!==0)throw Error(`Unclosed DOCTYPE`)}else throw Error(`Invalid Tag instead of DOCTYPE`);return{entities:n,i:t}}const skipWhitespace=(e,t)=>{for(;t<e.length&&/\s/.test(e[t]);)t++;return t};function readEntityExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t])&&e[t]!==`"`&&e[t]!==`'`;)n+=e[t],t++;if(validateEntityName(n),t=skipWhitespace(e,t),e.substring(t,t+6).toUpperCase()===`SYSTEM`)throw Error(`External entities are not supported`);if(e[t]===`%`)throw Error(`Parameter entities are not supported`);let r=``;return[t,r]=readIdentifierVal(e,t,`entity`),t--,[n,r,t]}function readNotationExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;validateEntityName(n),t=skipWhitespace(e,t);let r=e.substring(t,t+6).toUpperCase();if(r!==`SYSTEM`&&r!==`PUBLIC`)throw Error(`Expected SYSTEM or PUBLIC, found "${r}"`);t+=r.length,t=skipWhitespace(e,t);let i=null,a=null;if(r===`PUBLIC`)[t,i]=readIdentifierVal(e,t,`publicIdentifier`),t=skipWhitespace(e,t),(e[t]===`"`||e[t]===`'`)&&([t,a]=readIdentifierVal(e,t,`systemIdentifier`));else if(r===`SYSTEM`&&([t,a]=readIdentifierVal(e,t,`systemIdentifier`),!a))throw Error(`Missing mandatory system identifier for SYSTEM notation`);return{notationName:n,publicIdentifier:i,systemIdentifier:a,index:--t}}function readIdentifierVal(e,t,n){let r=``,i=e[t];if(i!==`"`&&i!==`'`)throw Error(`Expected quoted string, found "${i}"`);for(t++;t<e.length&&e[t]!==i;)r+=e[t],t++;if(e[t]!==i)throw Error(`Unterminated ${n} value`);return t++,[t,r]}function readElementExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;if(!validateEntityName(n))throw Error(`Invalid element name: "${n}"`);t=skipWhitespace(e,t);let r=``;if(e[t]===`E`&&hasSeq(e,`MPTY`,t))t+=4;else if(e[t]===`A`&&hasSeq(e,`NY`,t))t+=2;else if(e[t]===`(`){for(t++;t<e.length&&e[t]!==`)`;)r+=e[t],t++;if(e[t]!==`)`)throw Error(`Unterminated content model`)}else throw Error(`Invalid Element Expression, found "${e[t]}"`);return{elementName:n,contentModel:r.trim(),index:t}}function hasSeq(e,t,n){for(let r=0;r<t.length;r++)if(t[r]!==e[n+r+1])return!1;return!0}function validateEntityName(e){if(isName(e))return e;throw Error(`Invalid entity name ${e}`)}const Et=/^[-+]?0x[a-fA-F0-9]+$/,Dt=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,Ot={hex:!0,leadingZeros:!0,decimalPoint:`.`,eNotation:!0};function toNumber(e,t={}){if(t=Object.assign({},Ot,t),!e||typeof e!=`string`)return e;let n=e.trim();if(t.skipLike!==void 0&&t.skipLike.test(n))return e;if(e===`0`)return 0;if(t.hex&&Et.test(n))return parse_int(n,16);if(n.includes(`e`)||n.includes(`E`))return resolveEnotation(e,n,t);{let r=Dt.exec(n);if(r){let i=r[1]||``,a=r[2],o=trimZeros(r[3]),s=i?e[a.length+1]===`.`:e[a.length]===`.`;if(!t.leadingZeros&&(a.length>1||a.length===1&&!s))return e;{let r=Number(n),s=String(r);if(r===0)return r;if(s.search(/[eE]/)!==-1)return t.eNotation?r:e;if(n.indexOf(`.`)!==-1)return s===`0`||s===o||s===`${i}${o}`?r:e;let c=a?o:n;return a?c===s||i+c===s?r:e:c===s||c===i+s?r:e}}else return e}}const kt=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function resolveEnotation(e,t,n){if(!n.eNotation)return e;let r=t.match(kt);if(r){let i=r[1]||``,a=r[3].indexOf(`e`)===-1?`E`:`e`,o=r[2],s=i?e[o.length+1]===a:e[o.length]===a;return o.length>1&&s?e:o.length===1&&(r[3].startsWith(`.${a}`)||r[3][0]===a)?Number(t):n.leadingZeros&&!s?(t=(r[1]||``)+r[3],Number(t)):e}else return e}function trimZeros(e){return e&&e.indexOf(`.`)!==-1?(e=e.replace(/0+$/,``),e===`.`?e=`0`:e[0]===`.`?e=`0`+e:e[e.length-1]===`.`&&(e=e.substring(0,e.length-1)),e):e}function parse_int(e,t){if(parseInt)return parseInt(e,t);if(Number.parseInt)return Number.parseInt(e,t);if(window&&window.parseInt)return window.parseInt(e,t);throw Error(`parseInt, Number.parseInt, window.parseInt are not supported`)}function getIgnoreAttributesFn(e){return typeof e==`function`?e:Array.isArray(e)?t=>{for(let n of e)if(typeof n==`string`&&t===n||n instanceof RegExp&&n.test(t))return!0}:()=>!1}var OrderedObjParser=class{constructor(e){this.options=e,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:`'`},gt:{regex:/&(gt|#62|#x3E);/g,val:`>`},lt:{regex:/&(lt|#60|#x3C);/g,val:`<`},quot:{regex:/&(quot|#34|#x22);/g,val:`"`}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:`&`},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:` `},cent:{regex:/&(cent|#162);/g,val:`¢`},pound:{regex:/&(pound|#163);/g,val:`£`},yen:{regex:/&(yen|#165);/g,val:`¥`},euro:{regex:/&(euro|#8364);/g,val:`€`},copyright:{regex:/&(copy|#169);/g,val:`©`},reg:{regex:/&(reg|#174);/g,val:`®`},inr:{regex:/&(inr|#8377);/g,val:`₹`},num_dec:{regex:/&#([0-9]{1,7});/g,val:(e,t)=>String.fromCodePoint(Number.parseInt(t,10))},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(e,t)=>String.fromCodePoint(Number.parseInt(t,16))}},this.addExternalEntities=addExternalEntities,this.parseXml=parseXml,this.parseTextData=parseTextData,this.resolveNameSpace=resolveNameSpace,this.buildAttributesMap=buildAttributesMap,this.isItStopNode=isItStopNode,this.replaceEntitiesValue=jt,this.readStopNodeData=readStopNodeData,this.saveTextToParentTag=saveTextToParentTag,this.addChild=addChild,this.ignoreAttributesFn=getIgnoreAttributesFn(this.options.ignoreAttributes)}};function addExternalEntities(e){let t=Object.keys(e);for(let n=0;n<t.length;n++){let r=t[n];this.lastEntities[r]={regex:RegExp(`&`+r+`;`,`g`),val:e[r]}}}function parseTextData(e,t,n,r,i,a,o){if(e!==void 0&&(this.options.trimValues&&!r&&(e=e.trim()),e.length>0)){o||(e=this.replaceEntitiesValue(e));let r=this.options.tagValueProcessor(t,e,n,i,a);return r==null?e:typeof r!=typeof e||r!==e?r:this.options.trimValues||e.trim()===e?parseValue(e,this.options.parseTagValue,this.options.numberParseOptions):e}}function resolveNameSpace(e){if(this.options.removeNSPrefix){let t=e.split(`:`),n=e.charAt(0)===`/`?`/`:``;if(t[0]===`xmlns`)return``;t.length===2&&(e=n+t[1])}return e}const At=RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,`gm`);function buildAttributesMap(e,t,n){if(this.options.ignoreAttributes!==!0&&typeof e==`string`){let n=getAllMatches(e,At),r=n.length,i={};for(let e=0;e<r;e++){let r=this.resolveNameSpace(n[e][1]);if(this.ignoreAttributesFn(r,t))continue;let a=n[e][4],o=this.options.attributeNamePrefix+r;if(r.length)if(this.options.transformAttributeName&&(o=this.options.transformAttributeName(o)),o===`__proto__`&&(o=`#__proto__`),a!==void 0){this.options.trimValues&&(a=a.trim()),a=this.replaceEntitiesValue(a);let e=this.options.attributeValueProcessor(r,a,t);e==null?i[o]=a:typeof e!=typeof a||e!==a?i[o]=e:i[o]=parseValue(a,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(i[o]=!0)}if(!Object.keys(i).length)return;if(this.options.attributesGroupName){let e={};return e[this.options.attributesGroupName]=i,e}return i}}const parseXml=function(e){e=e.replace(/\r\n?/g,`
|
|
174
|
-
`);let t=new XmlNode(`!xml`),n=t,r=``,i=``;for(let a=0;a<e.length;a++)if(e[a]===`<`)if(e[a+1]===`/`){let t=findClosingIndex(e,`>`,a,`Closing Tag is not closed.`),o=e.substring(a+2,t).trim();if(this.options.removeNSPrefix){let e=o.indexOf(`:`);e!==-1&&(o=o.substr(e+1))}this.options.transformTagName&&(o=this.options.transformTagName(o)),n&&(r=this.saveTextToParentTag(r,n,i));let s=i.substring(i.lastIndexOf(`.`)+1);if(o&&this.options.unpairedTags.indexOf(o)!==-1)throw Error(`Unpaired tag can not be used as closing tag: </${o}>`);let c=0;s&&this.options.unpairedTags.indexOf(s)!==-1?(c=i.lastIndexOf(`.`,i.lastIndexOf(`.`)-1),this.tagsNodeStack.pop()):c=i.lastIndexOf(`.`),i=i.substring(0,c),n=this.tagsNodeStack.pop(),r=``,a=t}else if(e[a+1]===`?`){let t=readTagExp(e,a,!1,`?>`);if(!t)throw Error(`Pi Tag is not closed.`);if(r=this.saveTextToParentTag(r,n,i),!(this.options.ignoreDeclaration&&t.tagName===`?xml`||this.options.ignorePiTags)){let e=new XmlNode(t.tagName);e.add(this.options.textNodeName,``),t.tagName!==t.tagExp&&t.attrExpPresent&&(e[`:@`]=this.buildAttributesMap(t.tagExp,i,t.tagName)),this.addChild(n,e,i,a)}a=t.closeIndex+1}else if(e.substr(a+1,3)===`!--`){let t=findClosingIndex(e,`-->`,a+4,`Comment is not closed.`);if(this.options.commentPropName){let o=e.substring(a+4,t-2);r=this.saveTextToParentTag(r,n,i),n.add(this.options.commentPropName,[{[this.options.textNodeName]:o}])}a=t}else if(e.substr(a+1,2)===`!D`){let t=readDocType(e,a);this.docTypeEntities=t.entities,a=t.i}else if(e.substr(a+1,2)===`![`){let t=findClosingIndex(e,`]]>`,a,`CDATA is not closed.`)-2,o=e.substring(a+9,t);r=this.saveTextToParentTag(r,n,i);let s=this.parseTextData(o,n.tagname,i,!0,!1,!0,!0);s??=``,this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:o}]):n.add(this.options.textNodeName,s),a=t+2}else{let o=readTagExp(e,a,this.options.removeNSPrefix),s=o.tagName,c=o.rawTagName,l=o.tagExp,u=o.attrExpPresent,d=o.closeIndex;this.options.transformTagName&&(s=this.options.transformTagName(s)),n&&r&&n.tagname!==`!xml`&&(r=this.saveTextToParentTag(r,n,i,!1));let f=n;f&&this.options.unpairedTags.indexOf(f.tagname)!==-1&&(n=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf(`.`))),s!==t.tagname&&(i+=i?`.`+s:s);let p=a;if(this.isItStopNode(this.options.stopNodes,i,s)){let t=``;if(l.length>0&&l.lastIndexOf(`/`)===l.length-1)s[s.length-1]===`/`?(s=s.substr(0,s.length-1),i=i.substr(0,i.length-1),l=s):l=l.substr(0,l.length-1),a=o.closeIndex;else if(this.options.unpairedTags.indexOf(s)!==-1)a=o.closeIndex;else{let n=this.readStopNodeData(e,c,d+1);if(!n)throw Error(`Unexpected end of ${c}`);a=n.i,t=n.tagContent}let r=new XmlNode(s);s!==l&&u&&(r[`:@`]=this.buildAttributesMap(l,i,s)),t&&=this.parseTextData(t,s,i,!0,u,!0,!0),i=i.substr(0,i.lastIndexOf(`.`)),r.add(this.options.textNodeName,t),this.addChild(n,r,i,p)}else{if(l.length>0&&l.lastIndexOf(`/`)===l.length-1){s[s.length-1]===`/`?(s=s.substr(0,s.length-1),i=i.substr(0,i.length-1),l=s):l=l.substr(0,l.length-1),this.options.transformTagName&&(s=this.options.transformTagName(s));let e=new XmlNode(s);s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i,s)),this.addChild(n,e,i,p),i=i.substr(0,i.lastIndexOf(`.`))}else{let e=new XmlNode(s);this.tagsNodeStack.push(n),s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i,s)),this.addChild(n,e,i,p),n=e}r=``,a=d}}else r+=e[a];return t.child};function addChild(e,t,n,r){this.options.captureMetaData||(r=void 0);let i=this.options.updateTag(t.tagname,n,t[`:@`]);i===!1||(typeof i==`string`&&(t.tagname=i),e.addChild(t,r))}const jt=e(function(e){if(this.options.processEntities){for(let t in this.docTypeEntities){let n=this.docTypeEntities[t];e=e.replace(n.regx,n.val)}for(let t in this.lastEntities){let n=this.lastEntities[t];e=e.replace(n.regex,n.val)}if(this.options.htmlEntities)for(let t in this.htmlEntities){let n=this.htmlEntities[t];e=e.replace(n.regex,n.val)}e=e.replace(this.ampEntity.regex,this.ampEntity.val)}return e},`replaceEntitiesValue`);function saveTextToParentTag(e,t,n,r){return e&&=(r===void 0&&(r=t.child.length===0),e=this.parseTextData(e,t.tagname,n,!1,t[`:@`]?Object.keys(t[`:@`]).length!==0:!1,r),e!==void 0&&e!==``&&t.add(this.options.textNodeName,e),``),e}function isItStopNode(e,t,n){let r=`*.`+n;for(let n in e){let i=e[n];if(r===i||t===i)return!0}return!1}function tagExpWithClosingIndex(e,t,n=`>`){let r,i=``;for(let a=t;a<e.length;a++){let t=e[a];if(r)t===r&&(r=``);else if(t===`"`||t===`'`)r=t;else if(t===n[0])if(n[1]){if(e[a+1]===n[1])return{data:i,index:a}}else return{data:i,index:a};else t===` `&&(t=` `);i+=t}}function findClosingIndex(e,t,n,r){let i=e.indexOf(t,n);if(i===-1)throw Error(r);return i+t.length-1}function readTagExp(e,t,n,r=`>`){let i=tagExpWithClosingIndex(e,t+1,r);if(!i)return;let a=i.data,o=i.index,s=a.search(/\s/),c=a,l=!0;s!==-1&&(c=a.substring(0,s),a=a.substring(s+1).trimStart());let u=c;if(n){let e=c.indexOf(`:`);e!==-1&&(c=c.substr(e+1),l=c!==i.data.substr(e+1))}return{tagName:c,tagExp:a,closeIndex:o,attrExpPresent:l,rawTagName:u}}function readStopNodeData(e,t,n){let r=n,i=1;for(;n<e.length;n++)if(e[n]===`<`)if(e[n+1]===`/`){let a=findClosingIndex(e,`>`,n,`${t} is not closed`);if(e.substring(n+2,a).trim()===t&&(i--,i===0))return{tagContent:e.substring(r,n),i:a};n=a}else if(e[n+1]===`?`)n=findClosingIndex(e,`?>`,n+1,`StopNode is not closed.`);else if(e.substr(n+1,3)===`!--`)n=findClosingIndex(e,`-->`,n+3,`StopNode is not closed.`);else if(e.substr(n+1,2)===`![`)n=findClosingIndex(e,`]]>`,n,`StopNode is not closed.`)-2;else{let r=readTagExp(e,n,`>`);r&&((r&&r.tagName)===t&&r.tagExp[r.tagExp.length-1]!==`/`&&i++,n=r.closeIndex)}}function parseValue(e,t,n){if(t&&typeof e==`string`){let t=e.trim();return t===`true`?!0:t===`false`?!1:toNumber(e,n)}else if(isExist(e))return e;else return``}const Mt=XmlNode.getMetaDataSymbol();function prettify(e,t){return compress(e,t)}function compress(e,t,n){let r,i={};for(let a=0;a<e.length;a++){let o=e[a],s=propName$1(o),c=``;if(c=n===void 0?s:n+`.`+s,s===t.textNodeName)r===void 0?r=o[s]:r+=``+o[s];else if(s===void 0)continue;else if(o[s]){let e=compress(o[s],t,c),n=isLeafTag(e,t);o[Mt]!==void 0&&(e[Mt]=o[Mt]),o[`:@`]?assignAttributes(e,o[`:@`],c,t):Object.keys(e).length===1&&e[t.textNodeName]!==void 0&&!t.alwaysCreateTextNode?e=e[t.textNodeName]:Object.keys(e).length===0&&(t.alwaysCreateTextNode?e[t.textNodeName]=``:e=``),i[s]!==void 0&&i.hasOwnProperty(s)?(Array.isArray(i[s])||(i[s]=[i[s]]),i[s].push(e)):t.isArray(s,c,n)?i[s]=[e]:i[s]=e}}return typeof r==`string`?r.length>0&&(i[t.textNodeName]=r):r!==void 0&&(i[t.textNodeName]=r),i}function propName$1(e){let t=Object.keys(e);for(let e=0;e<t.length;e++){let n=t[e];if(n!==`:@`)return n}}e(propName$1,`propName`);function assignAttributes(e,t,n,r){if(t){let i=Object.keys(t),a=i.length;for(let o=0;o<a;o++){let a=i[o];r.isArray(a,n+`.`+a,!0,!0)?e[a]=[t[a]]:e[a]=t[a]}}}function isLeafTag(e,t){let{textNodeName:n}=t,r=Object.keys(e).length;return!!(r===0||r===1&&(e[n]||typeof e[n]==`boolean`||e[n]===0))}var XMLParser=class{constructor(e){this.externalEntities={},this.options=buildOptions(e)}parse(e,t){if(typeof e!=`string`)if(e.toString)e=e.toString();else throw Error(`XML data is accepted in String or Bytes[] form.`);if(t){t===!0&&(t={});let n=validate(e,t);if(n!==!0)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}let n=new OrderedObjParser(this.options);n.addExternalEntities(this.externalEntities);let r=n.parseXml(e);return this.options.preserveOrder||r===void 0?r:prettify(r,this.options)}addEntity(e,t){if(t.indexOf(`&`)!==-1)throw Error(`Entity value can't have '&'`);if(e.indexOf(`&`)!==-1||e.indexOf(`;`)!==-1)throw Error(`An entity must be set without '&' and ';'. Eg. use '#xD' for '
'`);if(t===`&`)throw Error(`An entity with value '&' is not permitted`);this.externalEntities[e]=t}static getMetaDataSymbol(){return XmlNode.getMetaDataSymbol()}};function toXml(e,t){let n=``;return t.format&&t.indentBy.length>0&&(n=`
|
|
175
|
-
`)
|
|
173
|
+
`||e===`\r`}function readPI(e,t){let n=t;for(;t<e.length;t++)if(e[t]==`?`||e[t]==` `){let r=e.substr(n,t-n);if(t>5&&r===`xml`)return getErrorObject(`InvalidXml`,`XML declaration allowed only at the start of the document.`,getLineNumberForPosition(e,t));if(e[t]==`?`&&e[t+1]==`>`){t++;break}else continue}return t}function readCommentAndCDATA(e,t){if(e.length>t+5&&e[t+1]===`-`&&e[t+2]===`-`){for(t+=3;t<e.length;t++)if(e[t]===`-`&&e[t+1]===`-`&&e[t+2]===`>`){t+=2;break}}else if(e.length>t+8&&e[t+1]===`D`&&e[t+2]===`O`&&e[t+3]===`C`&&e[t+4]===`T`&&e[t+5]===`Y`&&e[t+6]===`P`&&e[t+7]===`E`){let n=1;for(t+=8;t<e.length;t++)if(e[t]===`<`)n++;else if(e[t]===`>`&&(n--,n===0))break}else if(e.length>t+9&&e[t+1]===`[`&&e[t+2]===`C`&&e[t+3]===`D`&&e[t+4]===`A`&&e[t+5]===`T`&&e[t+6]===`A`&&e[t+7]===`[`){for(t+=8;t<e.length;t++)if(e[t]===`]`&&e[t+1]===`]`&&e[t+2]===`>`){t+=2;break}}return t}function readAttributeStr(e,t){let n=``,r=``,i=!1;for(;t<e.length;t++){if(e[t]===`"`||e[t]===`'`)r===``?r=e[t]:r!==e[t]||(r=``);else if(e[t]===`>`&&r===``){i=!0;break}n+=e[t]}return r===``?{value:n,index:t,tagClosed:i}:!1}const Ct=RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,`g`);function validateAttributeString(e,t){let n=getAllMatches(e,Ct),r={};for(let e=0;e<n.length;e++){if(n[e][1].length===0)return getErrorObject(`InvalidAttr`,`Attribute '`+n[e][2]+`' has no space in starting.`,getPositionFromMatch(n[e]));if(n[e][3]!==void 0&&n[e][4]===void 0)return getErrorObject(`InvalidAttr`,`Attribute '`+n[e][2]+`' is without value.`,getPositionFromMatch(n[e]));if(n[e][3]===void 0&&!t.allowBooleanAttributes)return getErrorObject(`InvalidAttr`,`boolean attribute '`+n[e][2]+`' is not allowed.`,getPositionFromMatch(n[e]));let i=n[e][2];if(!validateAttrName(i))return getErrorObject(`InvalidAttr`,`Attribute '`+i+`' is an invalid name.`,getPositionFromMatch(n[e]));if(!Object.prototype.hasOwnProperty.call(r,i))r[i]=1;else return getErrorObject(`InvalidAttr`,`Attribute '`+i+`' is repeated.`,getPositionFromMatch(n[e]))}return!0}function validateNumberAmpersand(e,t){let n=/\d/;for(e[t]===`x`&&(t++,n=/[\da-fA-F]/);t<e.length;t++){if(e[t]===`;`)return t;if(!e[t].match(n))break}return-1}function validateAmpersand(e,t){if(t++,e[t]===`;`)return-1;if(e[t]===`#`)return t++,validateNumberAmpersand(e,t);let n=0;for(;t<e.length;t++,n++)if(!(e[t].match(/\w/)&&n<20)){if(e[t]===`;`)break;return-1}return t}function getErrorObject(e,t,n){return{err:{code:e,msg:t,line:n.line||n,col:n.col}}}function validateAttrName(e){return isName(e)}function validateTagName(e){return isName(e)}function getLineNumberForPosition(e,t){let n=e.substring(0,t).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function getPositionFromMatch(e){return e.startIndex+e[1].length}const wt={preserveOrder:!1,attributeNamePrefix:`@_`,attributesGroupName:!1,textNodeName:`#text`,ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(e,t){return t},attributeValueProcessor:function(e,t){return t},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(e,t,n){return e},captureMetaData:!1,maxNestedTags:100,strictReservedNames:!0};function normalizeProcessEntities(e){return typeof e==`boolean`?{enabled:e,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,maxEntityCount:100,allowedTags:null,tagFilter:null}:typeof e==`object`&&e?{enabled:e.enabled!==!1,maxEntitySize:e.maxEntitySize??1e4,maxExpansionDepth:e.maxExpansionDepth??10,maxTotalExpansions:e.maxTotalExpansions??1e3,maxExpandedLength:e.maxExpandedLength??1e5,maxEntityCount:e.maxEntityCount??100,allowedTags:e.allowedTags??null,tagFilter:e.tagFilter??null}:normalizeProcessEntities(!0)}const buildOptions=function(e){let t=Object.assign({},wt,e);return t.processEntities=normalizeProcessEntities(t.processEntities),t};let Tt;Tt=typeof Symbol==`function`?Symbol(`XML Node Metadata`):`@@xmlMetadata`;var XmlNode=class{constructor(e){this.tagname=e,this.child=[],this[`:@`]=Object.create(null)}add(e,t){e===`__proto__`&&(e=`#__proto__`),this.child.push({[e]:t})}addChild(e,t){e.tagname===`__proto__`&&(e.tagname=`#__proto__`),e[`:@`]&&Object.keys(e[`:@`]).length>0?this.child.push({[e.tagname]:e.child,":@":e[`:@`]}):this.child.push({[e.tagname]:e.child}),t!==void 0&&(this.child[this.child.length-1][Tt]={startIndex:t})}static getMetaDataSymbol(){return Tt}},DocTypeReader=class{constructor(e){this.suppressValidationErr=!e,this.options=e}readDocType(e,t){let n=Object.create(null),r=0;if(e[t+3]===`O`&&e[t+4]===`C`&&e[t+5]===`T`&&e[t+6]===`Y`&&e[t+7]===`P`&&e[t+8]===`E`){t+=9;let i=1,a=!1,o=!1,s=``;for(;t<e.length;t++)if(e[t]===`<`&&!o){if(a&&hasSeq(e,`!ENTITY`,t)){t+=7;let i,a;if([i,a,t]=this.readEntityExp(e,t+1,this.suppressValidationErr),a.indexOf(`&`)===-1){if(this.options.enabled!==!1&&this.options.maxEntityCount&&r>=this.options.maxEntityCount)throw Error(`Entity count (${r+1}) exceeds maximum allowed (${this.options.maxEntityCount})`);let e=i.replace(/[.\-+*:]/g,`\\.`);n[i]={regx:RegExp(`&${e};`,`g`),val:a},r++}}else if(a&&hasSeq(e,`!ELEMENT`,t)){t+=8;let{index:n}=this.readElementExp(e,t+1);t=n}else if(a&&hasSeq(e,`!ATTLIST`,t))t+=8;else if(a&&hasSeq(e,`!NOTATION`,t)){t+=9;let{index:n}=this.readNotationExp(e,t+1,this.suppressValidationErr);t=n}else if(hasSeq(e,`!--`,t))o=!0;else throw Error(`Invalid DOCTYPE`);i++,s=``}else if(e[t]===`>`){if(o?e[t-1]===`-`&&e[t-2]===`-`&&(o=!1,i--):i--,i===0)break}else e[t]===`[`?a=!0:s+=e[t];if(i!==0)throw Error(`Unclosed DOCTYPE`)}else throw Error(`Invalid Tag instead of DOCTYPE`);return{entities:n,i:t}}readEntityExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t])&&e[t]!==`"`&&e[t]!==`'`;)n+=e[t],t++;if(validateEntityName(n),t=skipWhitespace(e,t),!this.suppressValidationErr){if(e.substring(t,t+6).toUpperCase()===`SYSTEM`)throw Error(`External entities are not supported`);if(e[t]===`%`)throw Error(`Parameter entities are not supported`)}let r=``;if([t,r]=this.readIdentifierVal(e,t,`entity`),this.options.enabled!==!1&&this.options.maxEntitySize&&r.length>this.options.maxEntitySize)throw Error(`Entity "${n}" size (${r.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return t--,[n,r,t]}readNotationExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;!this.suppressValidationErr&&validateEntityName(n),t=skipWhitespace(e,t);let r=e.substring(t,t+6).toUpperCase();if(!this.suppressValidationErr&&r!==`SYSTEM`&&r!==`PUBLIC`)throw Error(`Expected SYSTEM or PUBLIC, found "${r}"`);t+=r.length,t=skipWhitespace(e,t);let i=null,a=null;if(r===`PUBLIC`)[t,i]=this.readIdentifierVal(e,t,`publicIdentifier`),t=skipWhitespace(e,t),(e[t]===`"`||e[t]===`'`)&&([t,a]=this.readIdentifierVal(e,t,`systemIdentifier`));else if(r===`SYSTEM`&&([t,a]=this.readIdentifierVal(e,t,`systemIdentifier`),!this.suppressValidationErr&&!a))throw Error(`Missing mandatory system identifier for SYSTEM notation`);return{notationName:n,publicIdentifier:i,systemIdentifier:a,index:--t}}readIdentifierVal(e,t,n){let r=``,i=e[t];if(i!==`"`&&i!==`'`)throw Error(`Expected quoted string, found "${i}"`);for(t++;t<e.length&&e[t]!==i;)r+=e[t],t++;if(e[t]!==i)throw Error(`Unterminated ${n} value`);return t++,[t,r]}readElementExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;if(!this.suppressValidationErr&&!isName(n))throw Error(`Invalid element name: "${n}"`);t=skipWhitespace(e,t);let r=``;if(e[t]===`E`&&hasSeq(e,`MPTY`,t))t+=4;else if(e[t]===`A`&&hasSeq(e,`NY`,t))t+=2;else if(e[t]===`(`){for(t++;t<e.length&&e[t]!==`)`;)r+=e[t],t++;if(e[t]!==`)`)throw Error(`Unterminated content model`)}else if(!this.suppressValidationErr)throw Error(`Invalid Element Expression, found "${e[t]}"`);return{elementName:n,contentModel:r.trim(),index:t}}readAttlistExp(e,t){t=skipWhitespace(e,t);let n=``;for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;validateEntityName(n),t=skipWhitespace(e,t);let r=``;for(;t<e.length&&!/\s/.test(e[t]);)r+=e[t],t++;if(!validateEntityName(r))throw Error(`Invalid attribute name: "${r}"`);t=skipWhitespace(e,t);let i=``;if(e.substring(t,t+8).toUpperCase()===`NOTATION`){if(i=`NOTATION`,t+=8,t=skipWhitespace(e,t),e[t]!==`(`)throw Error(`Expected '(', found "${e[t]}"`);t++;let n=[];for(;t<e.length&&e[t]!==`)`;){let r=``;for(;t<e.length&&e[t]!==`|`&&e[t]!==`)`;)r+=e[t],t++;if(r=r.trim(),!validateEntityName(r))throw Error(`Invalid notation name: "${r}"`);n.push(r),e[t]===`|`&&(t++,t=skipWhitespace(e,t))}if(e[t]!==`)`)throw Error(`Unterminated list of notations`);t++,i+=` (`+n.join(`|`)+`)`}else{for(;t<e.length&&!/\s/.test(e[t]);)i+=e[t],t++;if(!this.suppressValidationErr&&![`CDATA`,`ID`,`IDREF`,`IDREFS`,`ENTITY`,`ENTITIES`,`NMTOKEN`,`NMTOKENS`].includes(i.toUpperCase()))throw Error(`Invalid attribute type: "${i}"`)}t=skipWhitespace(e,t);let a=``;return e.substring(t,t+8).toUpperCase()===`#REQUIRED`?(a=`#REQUIRED`,t+=8):e.substring(t,t+7).toUpperCase()===`#IMPLIED`?(a=`#IMPLIED`,t+=7):[t,a]=this.readIdentifierVal(e,t,`ATTLIST`),{elementName:n,attributeName:r,attributeType:i,defaultValue:a,index:t}}};const skipWhitespace=(e,t)=>{for(;t<e.length&&/\s/.test(e[t]);)t++;return t};function hasSeq(e,t,n){for(let r=0;r<t.length;r++)if(t[r]!==e[n+r+1])return!1;return!0}function validateEntityName(e){if(isName(e))return e;throw Error(`Invalid entity name ${e}`)}const Et=/^[-+]?0x[a-fA-F0-9]+$/,Dt=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,Ot={hex:!0,leadingZeros:!0,decimalPoint:`.`,eNotation:!0,infinity:`original`};function toNumber(e,t={}){if(t=Object.assign({},Ot,t),!e||typeof e!=`string`)return e;let n=e.trim();if(t.skipLike!==void 0&&t.skipLike.test(n))return e;if(e===`0`)return 0;if(t.hex&&Et.test(n))return parse_int(n,16);if(isFinite(n)){if(n.includes(`e`)||n.includes(`E`))return resolveEnotation(e,n,t);{let r=Dt.exec(n);if(r){let i=r[1]||``,a=r[2],o=trimZeros(r[3]),s=i?e[a.length+1]===`.`:e[a.length]===`.`;if(!t.leadingZeros&&(a.length>1||a.length===1&&!s))return e;{let r=Number(n),s=String(r);if(r===0)return r;if(s.search(/[eE]/)!==-1)return t.eNotation?r:e;if(n.indexOf(`.`)!==-1)return s===`0`||s===o||s===`${i}${o}`?r:e;let c=a?o:n;return a?c===s||i+c===s?r:e:c===s||c===i+s?r:e}}else return e}}else return handleInfinity(e,Number(n),t)}const kt=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function resolveEnotation(e,t,n){if(!n.eNotation)return e;let r=t.match(kt);if(r){let i=r[1]||``,a=r[3].indexOf(`e`)===-1?`E`:`e`,o=r[2],s=i?e[o.length+1]===a:e[o.length]===a;return o.length>1&&s?e:o.length===1&&(r[3].startsWith(`.${a}`)||r[3][0]===a)?Number(t):n.leadingZeros&&!s?(t=(r[1]||``)+r[3],Number(t)):e}else return e}function trimZeros(e){return e&&e.indexOf(`.`)!==-1?(e=e.replace(/0+$/,``),e===`.`?e=`0`:e[0]===`.`?e=`0`+e:e[e.length-1]===`.`&&(e=e.substring(0,e.length-1)),e):e}function parse_int(e,t){if(parseInt)return parseInt(e,t);if(Number.parseInt)return Number.parseInt(e,t);if(window&&window.parseInt)return window.parseInt(e,t);throw Error(`parseInt, Number.parseInt, window.parseInt are not supported`)}function handleInfinity(e,t,n){let r=t===1/0;switch(n.infinity.toLowerCase()){case`null`:return null;case`infinity`:return t;case`string`:return r?`Infinity`:`-Infinity`;case`original`:default:return e}}function getIgnoreAttributesFn$1(e){return typeof e==`function`?e:Array.isArray(e)?t=>{for(let n of e)if(typeof n==`string`&&t===n||n instanceof RegExp&&n.test(t))return!0}:()=>!1}e(getIgnoreAttributesFn$1,`getIgnoreAttributesFn`);var OrderedObjParser=class{constructor(e){if(this.options=e,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:`'`},gt:{regex:/&(gt|#62|#x3E);/g,val:`>`},lt:{regex:/&(lt|#60|#x3C);/g,val:`<`},quot:{regex:/&(quot|#34|#x22);/g,val:`"`}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:`&`},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:` `},cent:{regex:/&(cent|#162);/g,val:`¢`},pound:{regex:/&(pound|#163);/g,val:`£`},yen:{regex:/&(yen|#165);/g,val:`¥`},euro:{regex:/&(euro|#8364);/g,val:`€`},copyright:{regex:/&(copy|#169);/g,val:`©`},reg:{regex:/&(reg|#174);/g,val:`®`},inr:{regex:/&(inr|#8377);/g,val:`₹`},num_dec:{regex:/&#([0-9]{1,7});/g,val:(e,t)=>fromCodePoint(t,10,`&#`)},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(e,t)=>fromCodePoint(t,16,`&#x`)}},this.addExternalEntities=addExternalEntities,this.parseXml=parseXml,this.parseTextData=parseTextData,this.resolveNameSpace=resolveNameSpace,this.buildAttributesMap=buildAttributesMap,this.isItStopNode=isItStopNode,this.replaceEntitiesValue=jt,this.readStopNodeData=readStopNodeData,this.saveTextToParentTag=saveTextToParentTag,this.addChild=addChild,this.ignoreAttributesFn=getIgnoreAttributesFn$1(this.options.ignoreAttributes),this.entityExpansionCount=0,this.currentExpandedLength=0,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodesExact=new Set,this.stopNodesWildcard=new Set;for(let e=0;e<this.options.stopNodes.length;e++){let t=this.options.stopNodes[e];typeof t==`string`&&(t.startsWith(`*.`)?this.stopNodesWildcard.add(t.substring(2)):this.stopNodesExact.add(t))}}}};function addExternalEntities(e){let t=Object.keys(e);for(let n=0;n<t.length;n++){let r=t[n],i=r.replace(/[.\-+*:]/g,`\\.`);this.lastEntities[r]={regex:RegExp(`&`+i+`;`,`g`),val:e[r]}}}function parseTextData(e,t,n,r,i,a,o){if(e!==void 0&&(this.options.trimValues&&!r&&(e=e.trim()),e.length>0)){o||(e=this.replaceEntitiesValue(e,t,n));let r=this.options.tagValueProcessor(t,e,n,i,a);return r==null?e:typeof r!=typeof e||r!==e?r:this.options.trimValues||e.trim()===e?parseValue(e,this.options.parseTagValue,this.options.numberParseOptions):e}}function resolveNameSpace(e){if(this.options.removeNSPrefix){let t=e.split(`:`),n=e.charAt(0)===`/`?`/`:``;if(t[0]===`xmlns`)return``;t.length===2&&(e=n+t[1])}return e}const At=RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,`gm`);function buildAttributesMap(e,t,n){if(this.options.ignoreAttributes!==!0&&typeof e==`string`){let r=getAllMatches(e,At),i=r.length,a={};for(let e=0;e<i;e++){let i=this.resolveNameSpace(r[e][1]);if(this.ignoreAttributesFn(i,t))continue;let o=r[e][4],s=this.options.attributeNamePrefix+i;if(i.length)if(this.options.transformAttributeName&&(s=this.options.transformAttributeName(s)),s===`__proto__`&&(s=`#__proto__`),o!==void 0){this.options.trimValues&&(o=o.trim()),o=this.replaceEntitiesValue(o,n,t);let e=this.options.attributeValueProcessor(i,o,t);e==null?a[s]=o:typeof e!=typeof o||e!==o?a[s]=e:a[s]=parseValue(o,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(a[s]=!0)}if(!Object.keys(a).length)return;if(this.options.attributesGroupName){let e={};return e[this.options.attributesGroupName]=a,e}return a}}const parseXml=function(e){e=e.replace(/\r\n?/g,`
|
|
174
|
+
`);let t=new XmlNode(`!xml`),n=t,r=``,i=``;this.entityExpansionCount=0,this.currentExpandedLength=0;let a=new DocTypeReader(this.options.processEntities);for(let o=0;o<e.length;o++)if(e[o]===`<`)if(e[o+1]===`/`){let t=findClosingIndex(e,`>`,o,`Closing Tag is not closed.`),a=e.substring(o+2,t).trim();if(this.options.removeNSPrefix){let e=a.indexOf(`:`);e!==-1&&(a=a.substr(e+1))}this.options.transformTagName&&(a=this.options.transformTagName(a)),n&&(r=this.saveTextToParentTag(r,n,i));let s=i.substring(i.lastIndexOf(`.`)+1);if(a&&this.options.unpairedTags.indexOf(a)!==-1)throw Error(`Unpaired tag can not be used as closing tag: </${a}>`);let c=0;s&&this.options.unpairedTags.indexOf(s)!==-1?(c=i.lastIndexOf(`.`,i.lastIndexOf(`.`)-1),this.tagsNodeStack.pop()):c=i.lastIndexOf(`.`),i=i.substring(0,c),n=this.tagsNodeStack.pop(),r=``,o=t}else if(e[o+1]===`?`){let t=readTagExp(e,o,!1,`?>`);if(!t)throw Error(`Pi Tag is not closed.`);if(r=this.saveTextToParentTag(r,n,i),!(this.options.ignoreDeclaration&&t.tagName===`?xml`||this.options.ignorePiTags)){let e=new XmlNode(t.tagName);e.add(this.options.textNodeName,``),t.tagName!==t.tagExp&&t.attrExpPresent&&(e[`:@`]=this.buildAttributesMap(t.tagExp,i,t.tagName)),this.addChild(n,e,i,o)}o=t.closeIndex+1}else if(e.substr(o+1,3)===`!--`){let t=findClosingIndex(e,`-->`,o+4,`Comment is not closed.`);if(this.options.commentPropName){let a=e.substring(o+4,t-2);r=this.saveTextToParentTag(r,n,i),n.add(this.options.commentPropName,[{[this.options.textNodeName]:a}])}o=t}else if(e.substr(o+1,2)===`!D`){let t=a.readDocType(e,o);this.docTypeEntities=t.entities,o=t.i}else if(e.substr(o+1,2)===`![`){let t=findClosingIndex(e,`]]>`,o,`CDATA is not closed.`)-2,a=e.substring(o+9,t);r=this.saveTextToParentTag(r,n,i);let s=this.parseTextData(a,n.tagname,i,!0,!1,!0,!0);s??=``,this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:a}]):n.add(this.options.textNodeName,s),o=t+2}else{let a=readTagExp(e,o,this.options.removeNSPrefix),s=a.tagName,c=a.rawTagName,l=a.tagExp,u=a.attrExpPresent,d=a.closeIndex;if(this.options.transformTagName){let e=this.options.transformTagName(s);l===s&&(l=e),s=e}if(this.options.strictReservedNames&&(s===this.options.commentPropName||s===this.options.cdataPropName))throw Error(`Invalid tag name: ${s}`);n&&r&&n.tagname!==`!xml`&&(r=this.saveTextToParentTag(r,n,i,!1));let f=n;f&&this.options.unpairedTags.indexOf(f.tagname)!==-1&&(n=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf(`.`))),s!==t.tagname&&(i+=i?`.`+s:s);let p=o;if(this.isItStopNode(this.stopNodesExact,this.stopNodesWildcard,i,s)){let t=``;if(l.length>0&&l.lastIndexOf(`/`)===l.length-1)s[s.length-1]===`/`?(s=s.substr(0,s.length-1),i=i.substr(0,i.length-1),l=s):l=l.substr(0,l.length-1),o=a.closeIndex;else if(this.options.unpairedTags.indexOf(s)!==-1)o=a.closeIndex;else{let n=this.readStopNodeData(e,c,d+1);if(!n)throw Error(`Unexpected end of ${c}`);o=n.i,t=n.tagContent}let r=new XmlNode(s);s!==l&&u&&(r[`:@`]=this.buildAttributesMap(l,i,s)),t&&=this.parseTextData(t,s,i,!0,u,!0,!0),i=i.substr(0,i.lastIndexOf(`.`)),r.add(this.options.textNodeName,t),this.addChild(n,r,i,p)}else{if(l.length>0&&l.lastIndexOf(`/`)===l.length-1){if(s[s.length-1]===`/`?(s=s.substr(0,s.length-1),i=i.substr(0,i.length-1),l=s):l=l.substr(0,l.length-1),this.options.transformTagName){let e=this.options.transformTagName(s);l===s&&(l=e),s=e}let e=new XmlNode(s);s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i,s)),this.addChild(n,e,i,p),i=i.substr(0,i.lastIndexOf(`.`))}else if(this.options.unpairedTags.indexOf(s)!==-1){let e=new XmlNode(s);s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i)),this.addChild(n,e,i,p),i=i.substr(0,i.lastIndexOf(`.`)),o=a.closeIndex;continue}else{let e=new XmlNode(s);if(this.tagsNodeStack.length>this.options.maxNestedTags)throw Error(`Maximum nested tags exceeded`);this.tagsNodeStack.push(n),s!==l&&u&&(e[`:@`]=this.buildAttributesMap(l,i,s)),this.addChild(n,e,i,p),n=e}r=``,o=d}}else r+=e[o];return t.child};function addChild(e,t,n,r){this.options.captureMetaData||(r=void 0);let i=this.options.updateTag(t.tagname,n,t[`:@`]);i===!1||(typeof i==`string`&&(t.tagname=i),e.addChild(t,r))}const jt=e(function(e,t,n){if(e.indexOf(`&`)===-1)return e;let r=this.options.processEntities;if(!r.enabled||r.allowedTags&&!r.allowedTags.includes(t)||r.tagFilter&&!r.tagFilter(t,n))return e;for(let t in this.docTypeEntities){let n=this.docTypeEntities[t],i=e.match(n.regx);if(i){if(this.entityExpansionCount+=i.length,r.maxTotalExpansions&&this.entityExpansionCount>r.maxTotalExpansions)throw Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${r.maxTotalExpansions}`);let t=e.length;if(e=e.replace(n.regx,n.val),r.maxExpandedLength&&(this.currentExpandedLength+=e.length-t,this.currentExpandedLength>r.maxExpandedLength))throw Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${r.maxExpandedLength}`)}}if(e.indexOf(`&`)===-1)return e;for(let t in this.lastEntities){let n=this.lastEntities[t];e=e.replace(n.regex,n.val)}if(e.indexOf(`&`)===-1)return e;if(this.options.htmlEntities)for(let t in this.htmlEntities){let n=this.htmlEntities[t];e=e.replace(n.regex,n.val)}return e=e.replace(this.ampEntity.regex,this.ampEntity.val),e},`replaceEntitiesValue`);function saveTextToParentTag(e,t,n,r){return e&&=(r===void 0&&(r=t.child.length===0),e=this.parseTextData(e,t.tagname,n,!1,t[`:@`]?Object.keys(t[`:@`]).length!==0:!1,r),e!==void 0&&e!==``&&t.add(this.options.textNodeName,e),``),e}function isItStopNode(e,t,n,r){return!!(t&&t.has(r)||e&&e.has(n))}function tagExpWithClosingIndex(e,t,n=`>`){let r,i=``;for(let a=t;a<e.length;a++){let t=e[a];if(r)t===r&&(r=``);else if(t===`"`||t===`'`)r=t;else if(t===n[0])if(n[1]){if(e[a+1]===n[1])return{data:i,index:a}}else return{data:i,index:a};else t===` `&&(t=` `);i+=t}}function findClosingIndex(e,t,n,r){let i=e.indexOf(t,n);if(i===-1)throw Error(r);return i+t.length-1}function readTagExp(e,t,n,r=`>`){let i=tagExpWithClosingIndex(e,t+1,r);if(!i)return;let a=i.data,o=i.index,s=a.search(/\s/),c=a,l=!0;s!==-1&&(c=a.substring(0,s),a=a.substring(s+1).trimStart());let u=c;if(n){let e=c.indexOf(`:`);e!==-1&&(c=c.substr(e+1),l=c!==i.data.substr(e+1))}return{tagName:c,tagExp:a,closeIndex:o,attrExpPresent:l,rawTagName:u}}function readStopNodeData(e,t,n){let r=n,i=1;for(;n<e.length;n++)if(e[n]===`<`)if(e[n+1]===`/`){let a=findClosingIndex(e,`>`,n,`${t} is not closed`);if(e.substring(n+2,a).trim()===t&&(i--,i===0))return{tagContent:e.substring(r,n),i:a};n=a}else if(e[n+1]===`?`)n=findClosingIndex(e,`?>`,n+1,`StopNode is not closed.`);else if(e.substr(n+1,3)===`!--`)n=findClosingIndex(e,`-->`,n+3,`StopNode is not closed.`);else if(e.substr(n+1,2)===`![`)n=findClosingIndex(e,`]]>`,n,`StopNode is not closed.`)-2;else{let r=readTagExp(e,n,`>`);r&&((r&&r.tagName)===t&&r.tagExp[r.tagExp.length-1]!==`/`&&i++,n=r.closeIndex)}}function parseValue(e,t,n){if(t&&typeof e==`string`){let t=e.trim();return t===`true`?!0:t===`false`?!1:toNumber(e,n)}else if(isExist(e))return e;else return``}function fromCodePoint(e,t,n){let r=Number.parseInt(e,t);return r>=0&&r<=1114111?String.fromCodePoint(r):n+e+`;`}const Mt=XmlNode.getMetaDataSymbol();function prettify(e,t){return compress(e,t)}function compress(e,t,n){let r,i={};for(let a=0;a<e.length;a++){let o=e[a],s=propName$1(o),c=``;if(c=n===void 0?s:n+`.`+s,s===t.textNodeName)r===void 0?r=o[s]:r+=``+o[s];else if(s===void 0)continue;else if(o[s]){let e=compress(o[s],t,c),n=isLeafTag(e,t);o[`:@`]?assignAttributes(e,o[`:@`],c,t):Object.keys(e).length===1&&e[t.textNodeName]!==void 0&&!t.alwaysCreateTextNode?e=e[t.textNodeName]:Object.keys(e).length===0&&(t.alwaysCreateTextNode?e[t.textNodeName]=``:e=``),o[Mt]!==void 0&&typeof e==`object`&&e&&(e[Mt]=o[Mt]),i[s]!==void 0&&Object.prototype.hasOwnProperty.call(i,s)?(Array.isArray(i[s])||(i[s]=[i[s]]),i[s].push(e)):t.isArray(s,c,n)?i[s]=[e]:i[s]=e}}return typeof r==`string`?r.length>0&&(i[t.textNodeName]=r):r!==void 0&&(i[t.textNodeName]=r),i}function propName$1(e){let t=Object.keys(e);for(let e=0;e<t.length;e++){let n=t[e];if(n!==`:@`)return n}}e(propName$1,`propName`);function assignAttributes(e,t,n,r){if(t){let i=Object.keys(t),a=i.length;for(let o=0;o<a;o++){let a=i[o];r.isArray(a,n+`.`+a,!0,!0)?e[a]=[t[a]]:e[a]=t[a]}}}function isLeafTag(e,t){let{textNodeName:n}=t,r=Object.keys(e).length;return!!(r===0||r===1&&(e[n]||typeof e[n]==`boolean`||e[n]===0))}var XMLParser=class{constructor(e){this.externalEntities={},this.options=buildOptions(e)}parse(e,t){if(typeof e!=`string`&&e.toString)e=e.toString();else if(typeof e!=`string`)throw Error(`XML data is accepted in String or Bytes[] form.`);if(t){t===!0&&(t={});let n=validate(e,t);if(n!==!0)throw Error(`${n.err.msg}:${n.err.line}:${n.err.col}`)}let n=new OrderedObjParser(this.options);n.addExternalEntities(this.externalEntities);let r=n.parseXml(e);return this.options.preserveOrder||r===void 0?r:prettify(r,this.options)}addEntity(e,t){if(t.indexOf(`&`)!==-1)throw Error(`Entity value can't have '&'`);if(e.indexOf(`&`)!==-1||e.indexOf(`;`)!==-1)throw Error(`An entity must be set without '&' and ';'. Eg. use '#xD' for '
'`);if(t===`&`)throw Error(`An entity with value '&' is not permitted`);this.externalEntities[e]=t}static getMetaDataSymbol(){return XmlNode.getMetaDataSymbol()}},Expression=class{constructor(e,t={}){this.pattern=e,this.separator=t.separator||`.`,this.segments=this._parse(e),this._hasDeepWildcard=this.segments.some(e=>e.type===`deep-wildcard`),this._hasAttributeCondition=this.segments.some(e=>e.attrName!==void 0),this._hasPositionSelector=this.segments.some(e=>e.position!==void 0)}_parse(e){let t=[],n=0,r=``;for(;n<e.length;)e[n]===this.separator?n+1<e.length&&e[n+1]===this.separator?(r.trim()&&(t.push(this._parseSegment(r.trim())),r=``),t.push({type:`deep-wildcard`}),n+=2):(r.trim()&&t.push(this._parseSegment(r.trim())),r=``,n++):(r+=e[n],n++);return r.trim()&&t.push(this._parseSegment(r.trim())),t}_parseSegment(e){let t={type:`tag`},n=null,r=e,i=e.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);if(i&&(r=i[1]+i[3],i[2])){let e=i[2].slice(1,-1);e&&(n=e)}let a,o=r;if(r.includes(`::`)){let t=r.indexOf(`::`);if(a=r.substring(0,t).trim(),o=r.substring(t+2).trim(),!a)throw Error(`Invalid namespace in pattern: ${e}`)}let s,c=null;if(o.includes(`:`)){let e=o.lastIndexOf(`:`),t=o.substring(0,e).trim(),n=o.substring(e+1).trim();[`first`,`last`,`odd`,`even`].includes(n)||/^nth\(\d+\)$/.test(n)?(s=t,c=n):s=o}else s=o;if(!s)throw Error(`Invalid segment pattern: ${e}`);if(t.tag=s,a&&(t.namespace=a),n)if(n.includes(`=`)){let e=n.indexOf(`=`);t.attrName=n.substring(0,e).trim(),t.attrValue=n.substring(e+1).trim()}else t.attrName=n.trim();if(c){let e=c.match(/^nth\((\d+)\)$/);e?(t.position=`nth`,t.positionValue=parseInt(e[1],10)):t.position=c}return t}get length(){return this.segments.length}hasDeepWildcard(){return this._hasDeepWildcard}hasAttributeCondition(){return this._hasAttributeCondition}hasPositionSelector(){return this._hasPositionSelector}toString(){return this.pattern}},Matcher=class{constructor(e={}){this.separator=e.separator||`.`,this.path=[],this.siblingStacks=[]}push(e,t=null,n=null){if(this.path.length>0){let e=this.path[this.path.length-1];e.values=void 0}let r=this.path.length;this.siblingStacks[r]||(this.siblingStacks[r]=new Map);let i=this.siblingStacks[r],a=n?`${n}:${e}`:e,o=i.get(a)||0,s=0;for(let e of i.values())s+=e;i.set(a,o+1);let c={tag:e,position:s,counter:o};n!=null&&(c.namespace=n),t!=null&&(c.values=t),this.path.push(c)}pop(){if(this.path.length===0)return;let e=this.path.pop();return this.siblingStacks.length>this.path.length+1&&(this.siblingStacks.length=this.path.length+1),e}updateCurrent(e){if(this.path.length>0){let t=this.path[this.path.length-1];e!=null&&(t.values=e)}}getCurrentTag(){return this.path.length>0?this.path[this.path.length-1].tag:void 0}getCurrentNamespace(){return this.path.length>0?this.path[this.path.length-1].namespace:void 0}getAttrValue(e){if(this.path.length!==0)return this.path[this.path.length-1].values?.[e]}hasAttr(e){if(this.path.length===0)return!1;let t=this.path[this.path.length-1];return t.values!==void 0&&e in t.values}getPosition(){return this.path.length===0?-1:this.path[this.path.length-1].position??0}getCounter(){return this.path.length===0?-1:this.path[this.path.length-1].counter??0}getIndex(){return this.getPosition()}getDepth(){return this.path.length}toString(e,t=!0){let n=e||this.separator;return this.path.map(e=>t&&e.namespace?`${e.namespace}:${e.tag}`:e.tag).join(n)}toArray(){return this.path.map(e=>e.tag)}reset(){this.path=[],this.siblingStacks=[]}matches(e){let t=e.segments;return t.length===0?!1:e.hasDeepWildcard()?this._matchWithDeepWildcard(t):this._matchSimple(t)}_matchSimple(e){if(this.path.length!==e.length)return!1;for(let t=0;t<e.length;t++){let n=e[t],r=this.path[t],i=t===this.path.length-1;if(!this._matchSegment(n,r,i))return!1}return!0}_matchWithDeepWildcard(e){let t=this.path.length-1,n=e.length-1;for(;n>=0&&t>=0;){let r=e[n];if(r.type===`deep-wildcard`){if(n--,n<0)return!0;let r=e[n],i=!1;for(let e=t;e>=0;e--){let a=e===this.path.length-1;if(this._matchSegment(r,this.path[e],a)){t=e-1,n--,i=!0;break}}if(!i)return!1}else{let e=t===this.path.length-1;if(!this._matchSegment(r,this.path[t],e))return!1;t--,n--}}return n<0}_matchSegment(e,t,n){if(e.tag!==`*`&&e.tag!==t.tag||e.namespace!==void 0&&e.namespace!==`*`&&e.namespace!==t.namespace)return!1;if(e.attrName!==void 0){if(!n||!t.values||!(e.attrName in t.values))return!1;if(e.attrValue!==void 0){let n=t.values[e.attrName];if(String(n)!==String(e.attrValue))return!1}}if(e.position!==void 0){if(!n)return!1;let r=t.counter??0;if(e.position===`first`&&r!==0||e.position===`odd`&&r%2!=1||e.position===`even`&&r%2!=0||e.position===`nth`&&r!==e.positionValue)return!1}return!0}snapshot(){return{path:this.path.map(e=>({...e})),siblingStacks:this.siblingStacks.map(e=>new Map(e))}}restore(e){this.path=e.path.map(e=>({...e})),this.siblingStacks=e.siblingStacks.map(e=>new Map(e))}};function toXml(e,t){let n=``;t.format&&t.indentBy.length>0&&(n=`
|
|
175
|
+
`);let r=[];if(t.stopNodes&&Array.isArray(t.stopNodes))for(let e=0;e<t.stopNodes.length;e++){let n=t.stopNodes[e];typeof n==`string`?r.push(new Expression(n)):n instanceof Expression&&r.push(n)}let i=new Matcher;return arrToStr(e,t,n,i,r)}function arrToStr(e,t,n,r,i){let a=``,o=!1;if(!Array.isArray(e)){if(e!=null){let n=e.toString();return n=replaceEntitiesValue(n,t),n}return``}for(let s=0;s<e.length;s++){let c=e[s],l=propName(c);if(l===void 0)continue;let u=extractAttributeValues(c[`:@`],t);r.push(l,u);let d=checkStopNode(r,i);if(l===t.textNodeName){let e=c[l];d||(e=t.tagValueProcessor(l,e),e=replaceEntitiesValue(e,t)),o&&(a+=n),a+=e,o=!1,r.pop();continue}else if(l===t.cdataPropName){o&&(a+=n),a+=`<![CDATA[${c[l][0][t.textNodeName]}]]>`,o=!1,r.pop();continue}else if(l===t.commentPropName){a+=n+`<!--${c[l][0][t.textNodeName]}-->`,o=!0,r.pop();continue}else if(l[0]===`?`){let e=attr_to_str(c[`:@`],t,d),i=l===`?xml`?``:n,s=c[l][0][t.textNodeName];s=s.length===0?``:` `+s,a+=i+`<${l}${s}${e}?>`,o=!0,r.pop();continue}let f=n;f!==``&&(f+=t.indentBy);let p=n+`<${l}${attr_to_str(c[`:@`],t,d)}`,m;m=d?getRawContent(c[l],t):arrToStr(c[l],t,f,r,i),t.unpairedTags.indexOf(l)===-1?(!m||m.length===0)&&t.suppressEmptyNode?a+=p+`/>`:m&&m.endsWith(`>`)?a+=p+`>${m}${n}</${l}>`:(a+=p+`>`,m&&n!==``&&(m.includes(`/>`)||m.includes(`</`))?a+=n+t.indentBy+m+n:a+=m,a+=`</${l}>`):t.suppressUnpairedNode?a+=p+`>`:a+=p+`/>`,o=!0,r.pop()}return a}function extractAttributeValues(e,t){if(!e||t.ignoreAttributes)return null;let n={},r=!1;for(let i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;let a=i.startsWith(t.attributeNamePrefix)?i.substr(t.attributeNamePrefix.length):i;n[a]=e[i],r=!0}return r?n:null}function getRawContent(e,t){if(!Array.isArray(e))return e==null?``:e.toString();let n=``;for(let r=0;r<e.length;r++){let i=e[r],a=propName(i);if(a===t.textNodeName)n+=i[a];else if(a===t.cdataPropName)n+=i[a][0][t.textNodeName];else if(a===t.commentPropName)n+=i[a][0][t.textNodeName];else if(a&&a[0]===`?`)continue;else if(a){let e=attr_to_str_raw(i[`:@`],t),r=getRawContent(i[a],t);!r||r.length===0?n+=`<${a}${e}/>`:n+=`<${a}${e}>${r}</${a}>`}}return n}function attr_to_str_raw(e,t){let n=``;if(e&&!t.ignoreAttributes)for(let r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;let i=e[r];i===!0&&t.suppressBooleanAttributes?n+=` ${r.substr(t.attributeNamePrefix.length)}`:n+=` ${r.substr(t.attributeNamePrefix.length)}="${i}"`}return n}function propName(e){let t=Object.keys(e);for(let n=0;n<t.length;n++){let r=t[n];if(Object.prototype.hasOwnProperty.call(e,r)&&r!==`:@`)return r}}function attr_to_str(e,t,n){let r=``;if(e&&!t.ignoreAttributes)for(let i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;let a;n?a=e[i]:(a=t.attributeValueProcessor(i,e[i]),a=replaceEntitiesValue(a,t)),a===!0&&t.suppressBooleanAttributes?r+=` ${i.substr(t.attributeNamePrefix.length)}`:r+=` ${i.substr(t.attributeNamePrefix.length)}="${a}"`}return r}function checkStopNode(e,t){if(!t||t.length===0)return!1;for(let n=0;n<t.length;n++)if(e.matches(t[n]))return!0;return!1}function replaceEntitiesValue(e,t){if(e&&e.length>0&&t.processEntities)for(let n=0;n<t.entities.length;n++){let r=t.entities[n];e=e.replace(r.regex,r.val)}return e}function getIgnoreAttributesFn(e){return typeof e==`function`?e:Array.isArray(e)?t=>{for(let n of e)if(typeof n==`string`&&t===n||n instanceof RegExp&&n.test(t))return!0}:()=>!1}const Nt={attributeNamePrefix:`@_`,attributesGroupName:!1,textNodeName:`#text`,ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:` `,suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(e,t){return t},attributeValueProcessor:function(e,t){return t},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:RegExp(`&`,`g`),val:`&`},{regex:RegExp(`>`,`g`),val:`>`},{regex:RegExp(`<`,`g`),val:`<`},{regex:RegExp(`'`,`g`),val:`'`},{regex:RegExp(`"`,`g`),val:`"`}],processEntities:!0,stopNodes:[],oneListGroup:!1,jPath:!0};function Builder(e){if(this.options=Object.assign({},Nt,e),this.options.stopNodes&&Array.isArray(this.options.stopNodes)&&(this.options.stopNodes=this.options.stopNodes.map(e=>typeof e==`string`&&e.startsWith(`*.`)?`..`+e.substring(2):e)),this.stopNodeExpressions=[],this.options.stopNodes&&Array.isArray(this.options.stopNodes))for(let e=0;e<this.options.stopNodes.length;e++){let t=this.options.stopNodes[e];typeof t==`string`?this.stopNodeExpressions.push(new Expression(t)):t instanceof Expression&&this.stopNodeExpressions.push(t)}this.options.ignoreAttributes===!0||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn=getIgnoreAttributesFn(this.options.ignoreAttributes),this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=isAttribute),this.processTextOrObjNode=processTextOrObjNode,this.options.format?(this.indentate=indentate,this.tagEndChar=`>
|
|
176
176
|
`,this.newLine=`
|
|
177
|
-
`):(this.indentate=function(){return``},this.tagEndChar=`>`,this.newLine=``)}Builder.prototype.build=function(e){return this.options.preserveOrder?toXml(e,this.options):(Array.isArray(e)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(e={[this.options.arrayNodeName]:e}),this.j2x(e,0,[]).val)},Builder.prototype.j2x=function(e,t,n){let r=``,i=``,a=n.join(`.`);for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o))if(e[o]===void 0)this.isAttribute(o)&&(i+=``);else if(e[o]===null)this.isAttribute(o)||o===this.options.cdataPropName?i+=``:o[0]===`?`?i+=this.indentate(t)+`<`+o+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+o+`/`+this.tagEndChar;else if(e[o]instanceof Date)i+=this.buildTextValNode(e[o],o,``,t);else if(typeof e[o]!=`object`){let n=this.isAttribute(o);if(n&&!this.ignoreAttributesFn(n,a))r+=this.buildAttrPairStr(n,``+e[o]);else if(!n)if(o===this.options.textNodeName){let t=this.options.tagValueProcessor(o,``+e[o]);i+=this.replaceEntitiesValue(t)}else i+=this.buildTextValNode(e[o],o,``,t)}else if(Array.isArray(e[o])){let r=e[o].length,a=``,s=``;for(let c=0;c<r;c++){let r=e[o][c];if(r!==void 0)if(r===null)o[0]===`?`?i+=this.indentate(t)+`<`+o+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+o+`/`+this.tagEndChar;else if(typeof r==`object`)if(this.options.oneListGroup){let e=this.j2x(r,t+1,n.concat(o));a+=e.val,this.options.attributesGroupName&&r.hasOwnProperty(this.options.attributesGroupName)&&(s+=e.attrStr)}else a+=this.processTextOrObjNode(r,o,t,n);else if(this.options.oneListGroup){let e=this.options.tagValueProcessor(o,r);e=this.replaceEntitiesValue(e),a+=e}else a+=this.buildTextValNode(r,o,``,t)}this.options.oneListGroup&&(a=this.buildObjectNode(a,o,s,t)),i+=a}else if(this.options.attributesGroupName&&o===this.options.attributesGroupName){let t=Object.keys(e[o]),n=t.length;for(let i=0;i<n;i++)r+=this.buildAttrPairStr(t[i],``+e[o][t[i]])}else i+=this.processTextOrObjNode(e[o],o,t,n);return{attrStr:r,val:i}},Builder.prototype.buildAttrPairStr=function(e,t){return t=this.options.attributeValueProcessor(e,``+t),t=this.replaceEntitiesValue(t),this.options.suppressBooleanAttributes&&t===`true`?` `+e:` `+e+`="`+t+`"`};function processTextOrObjNode(e,t,n,r){let i=this.j2x(e,n+1,r.concat(t));return e[this.options.textNodeName]!==void 0&&Object.keys(e).length===1?this.buildTextValNode(e[this.options.textNodeName],t,i.attrStr,n):this.buildObjectNode(i.val,t,i.attrStr,n)}Builder.prototype.buildObjectNode=function(e,t,n,r){if(e===``)return t[0]===`?`?this.indentate(r)+`<`+t+n+`?`+this.tagEndChar:this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar;{let i=`</`+t+this.tagEndChar,a=``;return t[0]===`?`&&(a=`?`,i=``),(n||n===``)&&e.indexOf(`<`)===-1?this.indentate(r)+`<`+t+n+a+`>`+e+i:this.options.commentPropName!==!1&&t===this.options.commentPropName&&a.length===0?this.indentate(r)+`<!--${e}-->`+this.newLine:this.indentate(r)+`<`+t+n+a+this.tagEndChar+e+this.indentate(r)+i}},Builder.prototype.closeTag=function(e){let t=``;return this.options.unpairedTags.indexOf(e)===-1?t=this.options.suppressEmptyNode?`/`:`></${e}`:this.options.suppressUnpairedNode||(t=`/`),t},Builder.prototype.buildTextValNode=function(e,t,n,r){if(this.options.cdataPropName!==!1&&t===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${e}]]>`+this.newLine;if(this.options.commentPropName!==!1&&t===this.options.commentPropName)return this.indentate(r)+`<!--${e}-->`+this.newLine;if(t[0]===`?`)return this.indentate(r)+`<`+t+n+`?`+this.tagEndChar;{let i=this.options.tagValueProcessor(t,e);return i=this.replaceEntitiesValue(i),i===``?this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar:this.indentate(r)+`<`+t+n+`>`+i+`</`+t+this.tagEndChar}},Builder.prototype.replaceEntitiesValue=function(e){if(e&&e.length>0&&this.options.processEntities)for(let t=0;t<this.options.entities.length;t++){let n=this.options.entities[t];e=e.replace(n.regex,n.val)}return e};function indentate(e){return this.options.indentBy.repeat(e)}function isAttribute(e){return e.startsWith(this.options.attributeNamePrefix)&&e!==this.options.textNodeName?e.substr(this.attrPrefixLen):!1}const Pt={validate};var SoapClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:o,requestConfig:s}){let c;if(c=typeof s?.envelope==`string`?s.envelope:typeof s?.envelope==`object`?Ft.build(s.envelope):await buildEnvelope(a,s),Pt.validate(c,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);let u,d={"Content-Type":`application/xml`,...r};s?.soapAction&&(d.SOAPAction=s.soapAction);try{u=await e?.request({method:n,url:t,headers:d,queryParams:i,maxRedirects:0,payload:c,requestConfig:s})}catch(e){if(l(e?.response))throw e;u=e.response}let f=It.parse(u.data),p=f.Envelope||f,m=p.Body||p,h=m.Fault;if(h)throw new me({...u,status:500,data:h,message:h.faultstring??h.faultcode??`SOAP Fault`},h.faultstring??`SOAP Fault occurred`);u.data=m;let g=translateCustomError(u,o);if(isFailedStatusCode(g?.status))throw new me(g,g.message);return g}};const Ft=new Builder({attributeNamePrefix:`@_`,ignoreAttributes:!1,suppressBooleanAttributes:!1}),It=new XMLParser({ignoreAttributes:!1,attributeNamePrefix:`_`,removeNSPrefix:!0,numberParseOptions:{leadingZeros:!1,hex:!1}}),buildEnvelope=async(e,t)=>{if(p(t?.envelope)){let e=typeof t.envelope==`string`?t.envelope:Ft.build(t.envelope);if(Pt.validate(e,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return e}let n=await buildSoapEnvelope(t,e),r=Ft.build(n);if(Pt.validate(r,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return r},buildSoapEnvelope=async(e,t)=>{let n=await Promise.all((e?.namespaces||[]).map(async e=>({identifier:await _(e.namespaceIdentifier),namespace:await _(e.namespace)})));n.forEach(({identifier:e,namespace:t})=>{if(l(e)||l(t)||e===``||t===``)throw Error(`Invalid namespace config: both identifier and namespace are required`)});let r=n.reduce((e,{identifier:t,namespace:n})=>(e[`@_xmlns:${t}`]=n,e),{});return{"soapenv:Envelope":{"soapenv:Header":await buildSoapHeaders(t,e??{}),"soapenv:Body":await buildSoapBody(t,e?.soapOperation??``,n[0]?.identifier??``),"@_xmlns:soapenv":`http://schemas.xmlsoap.org/soap/envelope/`,...r}}},buildSoapHeaders=async(e,t)=>[await buildSoapSecurity(e,t)],buildSoapSecurity=async(e,t)=>{if(l(t.soapContext))return{};let{username:n,password:r}=t.soapContext;return{"wsse:Security":{"wsse:UsernameToken":{"wsse:Username":n,"wsse:Password":{"#text":r,"@_Type":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText`}},"@_soapenv:mustUnderstand":`1`,"@_xmlns:wsse":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd`,"@_xmlns:wsu":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd`}}},buildSoapBody=async(e,t,n)=>{if(l(t))throw Error(`Missing soapOperation in config`);let r=expandArrayAttributes({[t]:e});return(Array.isArray(r)?r:[r]).map(e=>applyNamespace(e,n))},expandArrayAttributes=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e)){if(e.length===1){let t=e[0];if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.keys(t).filter(e=>!e.startsWith(`@_`));if(e.length===1){let n=e[0],r=t[n];if(typeof r==`object`&&r&&!Array.isArray(r)){let e=Object.keys(r),t=e.filter(e=>e.startsWith(`@_`)),i=e.filter(e=>!e.startsWith(`@_`)),a=t.find(e=>Array.isArray(r[e]));if(a&&i.length===0){let e=r[a],i=t.filter(e=>e!==a),o=e.map(e=>{let t={[a]:e};for(let e of i)t[e]=r[e];return t});return{[n]:o}}}}}}return e.map(e=>expandArrayAttributes(e))}let t={};for(let n of Object.keys(e)){let r=e[n];t[n]=expandArrayAttributes(r)}return t},applyNamespace=(e,t)=>{if(typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>applyNamespace(e,t));let n={};for(let r in e){let i=applyNamespaceToKey(r,t);n[i]=applyNamespace(e[r],t)}return n},applyNamespaceToKey=(e,t)=>{let n=e.split(`:`);return n.length>1&&n[0]||e.indexOf(`${t}:`)===0||e===`#text`?e:e.startsWith(`@_`)?`@_${t}:${e.slice(2)}`:`${t}:${e}`};var RequestClientFactory=class{static build(e=`rest`){if(e===`rest`)return new RestClient;if(e===`soap`)return new SoapClient;throw Error(`Unknown request client type: ${e}`)}};export{pe as CUSTOM_ERROR_CONFIG_SCHEMA,ConcurrencyManager,EventClient,HttpClient,HttpClientManager,fe as HttpErrorMessages,ht as HttpMethods,me as HttpResponseError,HttpTransportFactory,he as InstanceManager,LockManager,MemoryStore,yt as QueryArrayFormats,QueueManager,RateLimitManager,ee as RedisClient,RequestClientFactory,vt as RequestParameterLocations,ScriptManager,SubscriptionManager,buildHttpClientInstance,convertError,createAuthorizationHeaders,getRetryAfterWaitTime,getTransportInstance,getTransportManagers,initializeTransportSystem,isFailedStatusCode,isInfoStatusCode,isSuccessStatusCode,isTransportSystemReady,parseRequestParameters,serializeHttpResponseError,shutdownTransportSystem,superNormalizeHeaders,translateCustomError};
|
|
177
|
+
`):(this.indentate=function(){return``},this.tagEndChar=`>`,this.newLine=``)}Builder.prototype.build=function(e){if(this.options.preserveOrder)return toXml(e,this.options);{Array.isArray(e)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(e={[this.options.arrayNodeName]:e});let t=new Matcher;return this.j2x(e,0,t).val}},Builder.prototype.j2x=function(e,t,n){let r=``,i=``,a=this.options.jPath?n.toString():n,o=this.checkStopNode(n);for(let s in e)if(Object.prototype.hasOwnProperty.call(e,s))if(e[s]===void 0)this.isAttribute(s)&&(i+=``);else if(e[s]===null)this.isAttribute(s)||s===this.options.cdataPropName?i+=``:s[0]===`?`?i+=this.indentate(t)+`<`+s+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+s+`/`+this.tagEndChar;else if(e[s]instanceof Date)i+=this.buildTextValNode(e[s],s,``,t,n);else if(typeof e[s]!=`object`){let c=this.isAttribute(s);if(c&&!this.ignoreAttributesFn(c,a))r+=this.buildAttrPairStr(c,``+e[s],o);else if(!c)if(s===this.options.textNodeName){let t=this.options.tagValueProcessor(s,``+e[s]);i+=this.replaceEntitiesValue(t)}else{n.push(s);let r=this.checkStopNode(n);if(n.pop(),r){let n=``+e[s];n===``?i+=this.indentate(t)+`<`+s+this.closeTag(s)+this.tagEndChar:i+=this.indentate(t)+`<`+s+`>`+n+`</`+s+this.tagEndChar}else i+=this.buildTextValNode(e[s],s,``,t,n)}}else if(Array.isArray(e[s])){let r=e[s].length,a=``,o=``;for(let c=0;c<r;c++){let r=e[s][c];if(r!==void 0)if(r===null)s[0]===`?`?i+=this.indentate(t)+`<`+s+`?`+this.tagEndChar:i+=this.indentate(t)+`<`+s+`/`+this.tagEndChar;else if(typeof r==`object`)if(this.options.oneListGroup){n.push(s);let e=this.j2x(r,t+1,n);n.pop(),a+=e.val,this.options.attributesGroupName&&r.hasOwnProperty(this.options.attributesGroupName)&&(o+=e.attrStr)}else a+=this.processTextOrObjNode(r,s,t,n);else if(this.options.oneListGroup){let e=this.options.tagValueProcessor(s,r);e=this.replaceEntitiesValue(e),a+=e}else{n.push(s);let e=this.checkStopNode(n);if(n.pop(),e){let e=``+r;e===``?a+=this.indentate(t)+`<`+s+this.closeTag(s)+this.tagEndChar:a+=this.indentate(t)+`<`+s+`>`+e+`</`+s+this.tagEndChar}else a+=this.buildTextValNode(r,s,``,t,n)}}this.options.oneListGroup&&(a=this.buildObjectNode(a,s,o,t)),i+=a}else if(this.options.attributesGroupName&&s===this.options.attributesGroupName){let t=Object.keys(e[s]),n=t.length;for(let i=0;i<n;i++)r+=this.buildAttrPairStr(t[i],``+e[s][t[i]],o)}else i+=this.processTextOrObjNode(e[s],s,t,n);return{attrStr:r,val:i}},Builder.prototype.buildAttrPairStr=function(e,t,n){return n||(t=this.options.attributeValueProcessor(e,``+t),t=this.replaceEntitiesValue(t)),this.options.suppressBooleanAttributes&&t===`true`?` `+e:` `+e+`="`+t+`"`};function processTextOrObjNode(e,t,n,r){let i=this.extractAttributes(e);if(r.push(t,i),this.checkStopNode(r)){let i=this.buildRawContent(e),a=this.buildAttributesForStopNode(e);return r.pop(),this.buildObjectNode(i,t,a,n)}let a=this.j2x(e,n+1,r);return r.pop(),e[this.options.textNodeName]!==void 0&&Object.keys(e).length===1?this.buildTextValNode(e[this.options.textNodeName],t,a.attrStr,n,r):this.buildObjectNode(a.val,t,a.attrStr,n)}Builder.prototype.extractAttributes=function(e){if(!e||typeof e!=`object`)return null;let t={},n=!1;if(this.options.attributesGroupName&&e[this.options.attributesGroupName]){let r=e[this.options.attributesGroupName];for(let e in r){if(!Object.prototype.hasOwnProperty.call(r,e))continue;let i=e.startsWith(this.options.attributeNamePrefix)?e.substring(this.options.attributeNamePrefix.length):e;t[i]=r[e],n=!0}}else for(let r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;let i=this.isAttribute(r);i&&(t[i]=e[r],n=!0)}return n?t:null},Builder.prototype.buildRawContent=function(e){if(typeof e==`string`)return e;if(typeof e!=`object`||!e)return String(e);if(e[this.options.textNodeName]!==void 0)return e[this.options.textNodeName];let t=``;for(let n in e){if(!Object.prototype.hasOwnProperty.call(e,n)||this.isAttribute(n)||this.options.attributesGroupName&&n===this.options.attributesGroupName)continue;let r=e[n];if(n===this.options.textNodeName)t+=r;else if(Array.isArray(r)){for(let e of r)if(typeof e==`string`||typeof e==`number`)t+=`<${n}>${e}</${n}>`;else if(typeof e==`object`&&e){let r=this.buildRawContent(e),i=this.buildAttributesForStopNode(e);r===``?t+=`<${n}${i}/>`:t+=`<${n}${i}>${r}</${n}>`}}else if(typeof r==`object`&&r){let e=this.buildRawContent(r),i=this.buildAttributesForStopNode(r);e===``?t+=`<${n}${i}/>`:t+=`<${n}${i}>${e}</${n}>`}else t+=`<${n}>${r}</${n}>`}return t},Builder.prototype.buildAttributesForStopNode=function(e){if(!e||typeof e!=`object`)return``;let t=``;if(this.options.attributesGroupName&&e[this.options.attributesGroupName]){let n=e[this.options.attributesGroupName];for(let e in n){if(!Object.prototype.hasOwnProperty.call(n,e))continue;let r=e.startsWith(this.options.attributeNamePrefix)?e.substring(this.options.attributeNamePrefix.length):e,i=n[e];i===!0&&this.options.suppressBooleanAttributes?t+=` `+r:t+=` `+r+`="`+i+`"`}}else for(let n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;let r=this.isAttribute(n);if(r){let i=e[n];i===!0&&this.options.suppressBooleanAttributes?t+=` `+r:t+=` `+r+`="`+i+`"`}}return t},Builder.prototype.buildObjectNode=function(e,t,n,r){if(e===``)return t[0]===`?`?this.indentate(r)+`<`+t+n+`?`+this.tagEndChar:this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar;{let i=`</`+t+this.tagEndChar,a=``;return t[0]===`?`&&(a=`?`,i=``),(n||n===``)&&e.indexOf(`<`)===-1?this.indentate(r)+`<`+t+n+a+`>`+e+i:this.options.commentPropName!==!1&&t===this.options.commentPropName&&a.length===0?this.indentate(r)+`<!--${e}-->`+this.newLine:this.indentate(r)+`<`+t+n+a+this.tagEndChar+e+this.indentate(r)+i}},Builder.prototype.closeTag=function(e){let t=``;return this.options.unpairedTags.indexOf(e)===-1?t=this.options.suppressEmptyNode?`/`:`></${e}`:this.options.suppressUnpairedNode||(t=`/`),t},Builder.prototype.checkStopNode=function(e){if(!this.stopNodeExpressions||this.stopNodeExpressions.length===0)return!1;for(let t=0;t<this.stopNodeExpressions.length;t++)if(e.matches(this.stopNodeExpressions[t]))return!0;return!1},Builder.prototype.buildTextValNode=function(e,t,n,r,i){if(this.options.cdataPropName!==!1&&t===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${e}]]>`+this.newLine;if(this.options.commentPropName!==!1&&t===this.options.commentPropName)return this.indentate(r)+`<!--${e}-->`+this.newLine;if(t[0]===`?`)return this.indentate(r)+`<`+t+n+`?`+this.tagEndChar;{let i=this.options.tagValueProcessor(t,e);return i=this.replaceEntitiesValue(i),i===``?this.indentate(r)+`<`+t+n+this.closeTag(t)+this.tagEndChar:this.indentate(r)+`<`+t+n+`>`+i+`</`+t+this.tagEndChar}},Builder.prototype.replaceEntitiesValue=function(e){if(e&&e.length>0&&this.options.processEntities)for(let t=0;t<this.options.entities.length;t++){let n=this.options.entities[t];e=e.replace(n.regex,n.val)}return e};function indentate(e){return this.options.indentBy.repeat(e)}function isAttribute(e){return e.startsWith(this.options.attributeNamePrefix)&&e!==this.options.textNodeName?e.substr(this.attrPrefixLen):!1}var Pt=Builder;const Ft={validate};var SoapClient=class{async performRequest({httpClient:e,url:t,method:n,headers:r,queryParams:i,body:a,customErrorConfigs:o,requestConfig:s}){let c;if(c=typeof s?.envelope==`string`?s.envelope:typeof s?.envelope==`object`?It.build(s.envelope):await buildEnvelope(a,s),Ft.validate(c,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);let u,d={"Content-Type":`application/xml`,...r};s?.soapAction&&(d.SOAPAction=s.soapAction);try{u=await e?.request({method:n,url:t,headers:d,queryParams:i,maxRedirects:0,payload:c,requestConfig:s})}catch(e){if(l(e?.response))throw e;u=e.response}let f=Lt.parse(u.data),p=f.Envelope||f,m=p.Body||p,h=m.Fault;if(h)throw new me({...u,status:500,data:h,message:h.faultstring??h.faultcode??`SOAP Fault`},h.faultstring??`SOAP Fault occurred`);u.data=m;let g=translateCustomError(u,o);if(isFailedStatusCode(g?.status))throw new me(g,g.message);return g}};const It=new Pt({attributeNamePrefix:`@_`,ignoreAttributes:!1,suppressBooleanAttributes:!1}),Lt=new XMLParser({ignoreAttributes:!1,attributeNamePrefix:`_`,removeNSPrefix:!0,numberParseOptions:{leadingZeros:!1,hex:!1}}),buildEnvelope=async(e,t)=>{if(p(t?.envelope)){let e=typeof t.envelope==`string`?t.envelope:It.build(t.envelope);if(Ft.validate(e,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return e}let n=await buildSoapEnvelope(t,e),r=It.build(n);if(Ft.validate(r,{allowBooleanAttributes:!0})!==!0)throw Error(`Invalid XML envelope`);return r},buildSoapEnvelope=async(e,t)=>{let n=await Promise.all((e?.namespaces||[]).map(async e=>({identifier:await _(e.namespaceIdentifier),namespace:await _(e.namespace)})));n.forEach(({identifier:e,namespace:t})=>{if(l(e)||l(t)||e===``||t===``)throw Error(`Invalid namespace config: both identifier and namespace are required`)});let r=n.reduce((e,{identifier:t,namespace:n})=>(e[`@_xmlns:${t}`]=n,e),{});return{"soapenv:Envelope":{"soapenv:Header":await buildSoapHeaders(t,e??{}),"soapenv:Body":await buildSoapBody(t,e?.soapOperation??``,n[0]?.identifier??``),"@_xmlns:soapenv":`http://schemas.xmlsoap.org/soap/envelope/`,...r}}},buildSoapHeaders=async(e,t)=>[await buildSoapSecurity(e,t)],buildSoapSecurity=async(e,t)=>{if(l(t.soapContext))return{};let{username:n,password:r}=t.soapContext;return{"wsse:Security":{"wsse:UsernameToken":{"wsse:Username":n,"wsse:Password":{"#text":r,"@_Type":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText`}},"@_soapenv:mustUnderstand":`1`,"@_xmlns:wsse":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd`,"@_xmlns:wsu":`http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd`}}},buildSoapBody=async(e,t,n)=>{if(l(t))throw Error(`Missing soapOperation in config`);let r=expandArrayAttributes({[t]:e});return(Array.isArray(r)?r:[r]).map(e=>applyNamespace(e,n))},expandArrayAttributes=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e)){if(e.length===1){let t=e[0];if(typeof t==`object`&&t&&!Array.isArray(t)){let e=Object.keys(t).filter(e=>!e.startsWith(`@_`));if(e.length===1){let n=e[0],r=t[n];if(typeof r==`object`&&r&&!Array.isArray(r)){let e=Object.keys(r),t=e.filter(e=>e.startsWith(`@_`)),i=e.filter(e=>!e.startsWith(`@_`)),a=t.find(e=>Array.isArray(r[e]));if(a&&i.length===0){let e=r[a],i=t.filter(e=>e!==a),o=e.map(e=>{let t={[a]:e};for(let e of i)t[e]=r[e];return t});return{[n]:o}}}}}}return e.map(e=>expandArrayAttributes(e))}let t={};for(let n of Object.keys(e)){let r=e[n];t[n]=expandArrayAttributes(r)}return t},applyNamespace=(e,t)=>{if(typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>applyNamespace(e,t));let n={};for(let r in e){let i=applyNamespaceToKey(r,t);n[i]=applyNamespace(e[r],t)}return n},applyNamespaceToKey=(e,t)=>{let n=e.split(`:`);return n.length>1&&n[0]||e.indexOf(`${t}:`)===0||e===`#text`?e:e.startsWith(`@_`)?`@_${t}:${e.slice(2)}`:`${t}:${e}`};var RequestClientFactory=class{static build(e=`rest`){if(e===`rest`)return new RestClient;if(e===`soap`)return new SoapClient;throw Error(`Unknown request client type: ${e}`)}};export{pe as CUSTOM_ERROR_CONFIG_SCHEMA,ConcurrencyManager,EventClient,HttpClient,HttpClientManager,fe as HttpErrorMessages,ht as HttpMethods,me as HttpResponseError,HttpTransportFactory,he as InstanceManager,LockManager,MemoryStore,yt as QueryArrayFormats,QueueManager,RateLimitManager,ee as RedisClient,RequestClientFactory,vt as RequestParameterLocations,ScriptManager,SubscriptionManager,buildHttpClientInstance,convertError,createAuthorizationHeaders,getRetryAfterWaitTime,getTransportInstance,getTransportManagers,initializeTransportSystem,isFailedStatusCode,isInfoStatusCode,isSuccessStatusCode,isTransportSystemReady,parseRequestParameters,serializeHttpResponseError,shutdownTransportSystem,superNormalizeHeaders,translateCustomError};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackone/transport",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@stackone/logger": "*",
|
|
46
46
|
"@stackone/redaction": "*",
|
|
47
47
|
"@stackone/utils": "*",
|
|
48
|
-
"axios": "1.
|
|
48
|
+
"axios": "1.13.6",
|
|
49
49
|
"jsonpath-plus": "10.3.0",
|
|
50
50
|
"qs": "6.14.1",
|
|
51
51
|
"redis": "4.7.1"
|