@stackone/transport 2.11.0 → 2.12.0
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 +1 -1
- package/dist/index.d.cts +36 -2
- package/dist/index.d.mts +36 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -175,4 +175,4 @@ Example:
|
|
|
175
175
|
`;function toXml(e,t){let n=``;return t.format&&t.indentBy.length>0&&(n=`
|
|
176
176
|
`),arrToStr(e,t,``,n)}function arrToStr(e,t,n,r){let i=``,a=!1;for(let o=0;o<e.length;o++){let s=e[o],c=propName(s);if(c===void 0)continue;let l=``;if(l=n.length===0?c:`${n}.${c}`,c===t.textNodeName){let e=s[c];isStopNode(l,t)||(e=t.tagValueProcessor(c,e),e=replaceEntitiesValue(e,t)),a&&(i+=r),i+=e,a=!1;continue}else if(c===t.cdataPropName){a&&(i+=r),i+=`<![CDATA[${s[c][0][t.textNodeName]}]]>`,a=!1;continue}else if(c===t.commentPropName){i+=r+`<!--${s[c][0][t.textNodeName]}-->`,a=!0;continue}else if(c[0]===`?`){let e=attr_to_str(s[`:@`],t),n=c===`?xml`?``:r,o=s[c][0][t.textNodeName];o=o.length===0?``:` `+o,i+=n+`<${c}${o}${e}?>`,a=!0;continue}let u=r;u!==``&&(u+=t.indentBy);let d=r+`<${c}${attr_to_str(s[`:@`],t)}`,f=arrToStr(s[c],t,l,u);t.unpairedTags.indexOf(c)===-1?(!f||f.length===0)&&t.suppressEmptyNode?i+=d+`/>`:f&&f.endsWith(`>`)?i+=d+`>${f}${r}</${c}>`:(i+=d+`>`,f&&r!==``&&(f.includes(`/>`)||f.includes(`</`))?i+=r+t.indentBy+f+r:i+=f,i+=`</${c}>`):t.suppressUnpairedNode?i+=d+`>`:i+=d+`/>`,a=!0}return i}function propName(e){let t=Object.keys(e);for(let n=0;n<t.length;n++){let r=t[n];if(e.hasOwnProperty(r)&&r!==`:@`)return r}}function attr_to_str(e,t){let n=``;if(e&&!t.ignoreAttributes)for(let r in e){if(!e.hasOwnProperty(r))continue;let i=t.attributeValueProcessor(r,e[r]);i=replaceEntitiesValue(i,t),i===!0&&t.suppressBooleanAttributes?n+=` ${r.substr(t.attributeNamePrefix.length)}`:n+=` ${r.substr(t.attributeNamePrefix.length)}="${i}"`}return n}function isStopNode(e,t){e=e.substr(0,e.length-t.textNodeName.length-1);let n=e.substr(e.lastIndexOf(`.`)+1);for(let r in t.stopNodes)if(t.stopNodes[r]===e||t.stopNodes[r]===`*.`+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}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};function Builder(e){this.options=Object.assign({},zn,e),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={...r,"Content-Type":`text/xml`};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.createAuthorizationHeaders=createAuthorizationHeaders,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.translateCustomError=translateCustomError;
|
|
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={...r,"Content-Type":`text/xml`};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;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as redis from "redis";
|
|
2
|
-
import { AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
|
|
2
|
+
import { AxiosError, AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
|
|
3
3
|
import http, { AgentOptions } from "node:http";
|
|
4
4
|
import https from "node:https";
|
|
5
5
|
import { Readable } from "node:stream";
|
|
@@ -354,6 +354,27 @@ declare class RateLimitManager extends ScriptManager<RateLimitMethods, RateLimit
|
|
|
354
354
|
}
|
|
355
355
|
//#endregion
|
|
356
356
|
//#region src/interceptors/types.d.ts
|
|
357
|
+
type AxiosErrorWithRetryCount = AxiosError & {
|
|
358
|
+
config: InternalAxiosRequestConfig & {
|
|
359
|
+
_retryCount: number;
|
|
360
|
+
requestId: string;
|
|
361
|
+
};
|
|
362
|
+
response: AxiosResponse & {
|
|
363
|
+
config: InternalAxiosRequestConfig & {
|
|
364
|
+
requestId: string;
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
type AxiosErrorWithRequestMetadata = AxiosErrorWithRetryCount & {
|
|
369
|
+
config: AxiosErrorWithRetryCount['config'] & {
|
|
370
|
+
requestMetadata: RequestMetadata;
|
|
371
|
+
};
|
|
372
|
+
response: AxiosResponse & {
|
|
373
|
+
config: AxiosErrorWithRetryCount['response']['config'] & {
|
|
374
|
+
requestMetadata: RequestMetadata;
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
};
|
|
357
378
|
type RequestInterceptor = (value: InternalAxiosRequestConfig<unknown>) => InternalAxiosRequestConfig<unknown> | Promise<InternalAxiosRequestConfig<unknown>>;
|
|
358
379
|
type ResponseInterceptor = (value: AxiosResponse<unknown, unknown>) => AxiosResponse<unknown, unknown> | Promise<AxiosResponse<unknown, unknown>>;
|
|
359
380
|
type ErrorInterceptor = (error: unknown) => unknown;
|
|
@@ -888,6 +909,12 @@ declare class InstanceManager {
|
|
|
888
909
|
close(): void;
|
|
889
910
|
}
|
|
890
911
|
//#endregion
|
|
912
|
+
//#region src/interceptors/retryError.interceptor.d.ts
|
|
913
|
+
declare const convertError: (response?: Partial<AxiosResponse>, context?: RequestContext, requestConfig?: RequestConfig, logger?: ILogger) => {
|
|
914
|
+
status: number | undefined;
|
|
915
|
+
retryAfter: number | null;
|
|
916
|
+
};
|
|
917
|
+
//#endregion
|
|
891
918
|
//#region src/memoryStore/index.d.ts
|
|
892
919
|
declare class MemoryStore<T> implements ICacheClient {
|
|
893
920
|
private config;
|
|
@@ -997,6 +1024,13 @@ declare class SubscriptionManager {
|
|
|
997
1024
|
close(): void;
|
|
998
1025
|
}
|
|
999
1026
|
//#endregion
|
|
1027
|
+
//#region src/utils/extractRatelimitHeaders.d.ts
|
|
1028
|
+
declare const superNormalizeHeaders: (headers: AxiosResponse["headers"]) => Record<string, number | null>;
|
|
1029
|
+
//#endregion
|
|
1030
|
+
//#region src/utils/retryAfter.d.ts
|
|
1031
|
+
type RetryAfter = string | number | null;
|
|
1032
|
+
declare const getRetryAfterWaitTime: (retryAfter: RetryAfter, maxWaitTime?: number, defaultWaitTime?: number) => number;
|
|
1033
|
+
//#endregion
|
|
1000
1034
|
//#region src/validators/statusCodes.d.ts
|
|
1001
1035
|
declare const isSuccessStatusCode: (status: number | undefined) => boolean;
|
|
1002
1036
|
declare const isFailedStatusCode: (status: number | undefined) => boolean;
|
|
@@ -1010,4 +1044,4 @@ type LockEntry = {
|
|
|
1010
1044
|
unlock: Unlock;
|
|
1011
1045
|
};
|
|
1012
1046
|
//#endregion
|
|
1013
|
-
export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
|
|
1047
|
+
export { type AxiosErrorWithRequestMetadata, type AxiosErrorWithRetryCount, CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, convertError, createAuthorizationHeaders, getRetryAfterWaitTime, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, superNormalizeHeaders, translateCustomError };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as __name } from "./chunk-hhuvQGXm.mjs";
|
|
2
2
|
import { z } from "@stackone/utils";
|
|
3
3
|
import * as redis from "redis";
|
|
4
|
-
import { AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
|
|
4
|
+
import { AxiosError, AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
|
|
5
5
|
import https from "node:https";
|
|
6
6
|
import http, { AgentOptions } from "node:http";
|
|
7
7
|
import { Readable } from "node:stream";
|
|
@@ -353,6 +353,27 @@ declare class RateLimitManager extends ScriptManager<RateLimitMethods, RateLimit
|
|
|
353
353
|
}
|
|
354
354
|
//#endregion
|
|
355
355
|
//#region src/interceptors/types.d.ts
|
|
356
|
+
type AxiosErrorWithRetryCount = AxiosError & {
|
|
357
|
+
config: InternalAxiosRequestConfig & {
|
|
358
|
+
_retryCount: number;
|
|
359
|
+
requestId: string;
|
|
360
|
+
};
|
|
361
|
+
response: AxiosResponse & {
|
|
362
|
+
config: InternalAxiosRequestConfig & {
|
|
363
|
+
requestId: string;
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
type AxiosErrorWithRequestMetadata = AxiosErrorWithRetryCount & {
|
|
368
|
+
config: AxiosErrorWithRetryCount['config'] & {
|
|
369
|
+
requestMetadata: RequestMetadata;
|
|
370
|
+
};
|
|
371
|
+
response: AxiosResponse & {
|
|
372
|
+
config: AxiosErrorWithRetryCount['response']['config'] & {
|
|
373
|
+
requestMetadata: RequestMetadata;
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
};
|
|
356
377
|
type RequestInterceptor = (value: InternalAxiosRequestConfig<unknown>) => InternalAxiosRequestConfig<unknown> | Promise<InternalAxiosRequestConfig<unknown>>;
|
|
357
378
|
type ResponseInterceptor = (value: AxiosResponse<unknown, unknown>) => AxiosResponse<unknown, unknown> | Promise<AxiosResponse<unknown, unknown>>;
|
|
358
379
|
type ErrorInterceptor = (error: unknown) => unknown;
|
|
@@ -887,6 +908,12 @@ declare class InstanceManager {
|
|
|
887
908
|
close(): void;
|
|
888
909
|
}
|
|
889
910
|
//#endregion
|
|
911
|
+
//#region src/interceptors/retryError.interceptor.d.ts
|
|
912
|
+
declare const convertError: (response?: Partial<AxiosResponse>, context?: RequestContext, requestConfig?: RequestConfig, logger?: ILogger) => {
|
|
913
|
+
status: number | undefined;
|
|
914
|
+
retryAfter: number | null;
|
|
915
|
+
};
|
|
916
|
+
//#endregion
|
|
890
917
|
//#region src/memoryStore/index.d.ts
|
|
891
918
|
declare class MemoryStore<T> implements ICacheClient {
|
|
892
919
|
private config;
|
|
@@ -996,6 +1023,13 @@ declare class SubscriptionManager {
|
|
|
996
1023
|
close(): void;
|
|
997
1024
|
}
|
|
998
1025
|
//#endregion
|
|
1026
|
+
//#region src/utils/extractRatelimitHeaders.d.ts
|
|
1027
|
+
declare const superNormalizeHeaders: (headers: AxiosResponse["headers"]) => Record<string, number | null>;
|
|
1028
|
+
//#endregion
|
|
1029
|
+
//#region src/utils/retryAfter.d.ts
|
|
1030
|
+
type RetryAfter = string | number | null;
|
|
1031
|
+
declare const getRetryAfterWaitTime: (retryAfter: RetryAfter, maxWaitTime?: number, defaultWaitTime?: number) => number;
|
|
1032
|
+
//#endregion
|
|
999
1033
|
//#region src/validators/statusCodes.d.ts
|
|
1000
1034
|
declare const isSuccessStatusCode: (status: number | undefined) => boolean;
|
|
1001
1035
|
declare const isFailedStatusCode: (status: number | undefined) => boolean;
|
|
@@ -1009,4 +1043,4 @@ type LockEntry = {
|
|
|
1009
1043
|
unlock: Unlock;
|
|
1010
1044
|
};
|
|
1011
1045
|
//#endregion
|
|
1012
|
-
export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
|
|
1046
|
+
export { type AxiosErrorWithRequestMetadata, type AxiosErrorWithRetryCount, CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, convertError, createAuthorizationHeaders, getRetryAfterWaitTime, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, superNormalizeHeaders, translateCustomError };
|
package/dist/index.mjs
CHANGED
|
@@ -174,4 +174,4 @@ Example:
|
|
|
174
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
175
|
`),arrToStr(e,t,``,n)}function arrToStr(e,t,n,r){let i=``,a=!1;for(let o=0;o<e.length;o++){let s=e[o],c=propName(s);if(c===void 0)continue;let l=``;if(l=n.length===0?c:`${n}.${c}`,c===t.textNodeName){let e=s[c];isStopNode(l,t)||(e=t.tagValueProcessor(c,e),e=replaceEntitiesValue(e,t)),a&&(i+=r),i+=e,a=!1;continue}else if(c===t.cdataPropName){a&&(i+=r),i+=`<![CDATA[${s[c][0][t.textNodeName]}]]>`,a=!1;continue}else if(c===t.commentPropName){i+=r+`<!--${s[c][0][t.textNodeName]}-->`,a=!0;continue}else if(c[0]===`?`){let e=attr_to_str(s[`:@`],t),n=c===`?xml`?``:r,o=s[c][0][t.textNodeName];o=o.length===0?``:` `+o,i+=n+`<${c}${o}${e}?>`,a=!0;continue}let u=r;u!==``&&(u+=t.indentBy);let d=r+`<${c}${attr_to_str(s[`:@`],t)}`,f=arrToStr(s[c],t,l,u);t.unpairedTags.indexOf(c)===-1?(!f||f.length===0)&&t.suppressEmptyNode?i+=d+`/>`:f&&f.endsWith(`>`)?i+=d+`>${f}${r}</${c}>`:(i+=d+`>`,f&&r!==``&&(f.includes(`/>`)||f.includes(`</`))?i+=r+t.indentBy+f+r:i+=f,i+=`</${c}>`):t.suppressUnpairedNode?i+=d+`>`:i+=d+`/>`,a=!0}return i}function propName(e){let t=Object.keys(e);for(let n=0;n<t.length;n++){let r=t[n];if(e.hasOwnProperty(r)&&r!==`:@`)return r}}function attr_to_str(e,t){let n=``;if(e&&!t.ignoreAttributes)for(let r in e){if(!e.hasOwnProperty(r))continue;let i=t.attributeValueProcessor(r,e[r]);i=replaceEntitiesValue(i,t),i===!0&&t.suppressBooleanAttributes?n+=` ${r.substr(t.attributeNamePrefix.length)}`:n+=` ${r.substr(t.attributeNamePrefix.length)}="${i}"`}return n}function isStopNode(e,t){e=e.substr(0,e.length-t.textNodeName.length-1);let n=e.substr(e.lastIndexOf(`.`)+1);for(let r in t.stopNodes)if(t.stopNodes[r]===e||t.stopNodes[r]===`*.`+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}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};function Builder(e){this.options=Object.assign({},Nt,e),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={...r,"Content-Type":`text/xml`};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,createAuthorizationHeaders,getTransportInstance,getTransportManagers,initializeTransportSystem,isFailedStatusCode,isInfoStatusCode,isSuccessStatusCode,isTransportSystemReady,parseRequestParameters,serializeHttpResponseError,shutdownTransportSystem,translateCustomError};
|
|
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={...r,"Content-Type":`text/xml`};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};
|