UNPKG

@redocly/portal-plugin-soap-api

Version:

SOAP API plugin for Redocly products

13 lines (10 loc) 3.65 kB
var u=function(e,n,i,c){function a(r){return r instanceof i?r:new i(function(t){t(r)})}return new(i||(i=Promise))(function(r,t){function s(o){try{p(c.next(o))}catch(d){t(d)}}function l(o){try{p(c.throw(o))}catch(d){t(d)}}function p(o){o.done?r(o.value):a(o.value).then(s,l)}p((c=c.apply(e,n||[])).next())})};import{WSDL as S,Client as O}from"soap";import g from"xml-formatter";import{fileURLToPath as b}from"url";import h,{resolve as P,join as N}from"node:path";import{searchResolver as w}from"./search-resolver.js";const k="soap-docs",E=`HTTP/1.0 200 OK Content-Type: text/xml; charset = utf-8 Content-Length: 42 <?xml version = "1.0"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://www.w3.org/2001/12/soap-envelope" SOAP-ENV:encodingStyle = "http://www.w3.org/2001/12/soap-encoding"> <SOAP-ENV:Body xmlns:m = "http://www.xyz.org/quotation"> </SOAP-ENV:Body> </SOAP-ENV:Envelope>`;function _(){return{id:"soap",requiredEntitlements:["soap"],loaders:{wsdl:(e,n)=>u(this,void 0,void 0,function*(){const i=yield n.getConfig(e),{metadata:c}=x(i.apis,e),a=yield n.fs.read(e),r=yield new Promise(d=>{const f=new S(a,e,{});f.onReady(()=>d(f))}),t=new O(r,void 0,{httpClient:{request:(d,f,m)=>{m(void 0,{status:200},E)}}}),s=t.describe(),l=Object.keys(s)[0],p=Object.keys(s[l])[0];return{endpoints:s[l][p],metadata:c,serviceName:l,info:t,content:a}})},processContent:(e,n)=>u(this,void 0,void 0,function*(){const i=e.createTemplate(k,T(import.meta.url,"./template.js"));for(const c of yield n.fs.scan(/(\.wsdl)$/)){if(yield n.isPathIgnored(c.relativePath))continue;const a=yield n.cache.load(c.relativePath,"wsdl"),{endpoints:r,metadata:t,serviceName:s,info:l,content:p}=a.data;for(const o of Object.keys(r??{}))e.addRoute({fsPath:c.relativePath,slugSuffix:v(o),templateId:i,getNavText:()=>u(this,void 0,void 0,function*(){return o}),getSearchDocuments:w(e),getStaticData:()=>u(this,void 0,void 0,function*(){return{props:{title:o,meta:{},endpointName:o,request:yield j(o,l,r[o].input,n.logger)}}})});e.addRoute({fsPath:c.relativePath,templateId:i,metadata:Object.assign({type:"soap",title:s,description:"",tags:["SOAP"]},t),getSidebar:o=>{const d=[];for(const f of Object.keys(r)){const m=N(o.slug,v(f));d.push({type:"link",link:m,label:f,routeSlug:m})}return[{type:"link",link:o.slug,routeSlug:o.slug,label:s},{type:"group",label:"Operations",items:d}]},getNavText:()=>u(this,void 0,void 0,function*(){return s}),getSearchDocuments:w(e),getStaticData:()=>u(this,void 0,void 0,function*(){return{props:{title:s,wsdl:g(p,{indentation:" "})}}})})}})}}const j=(e,n,i,c)=>u(void 0,void 0,void 0,function*(){const a=y(e,i,1,c),r=yield new Promise(t=>{n[e](a,(...s)=>{t(s[4])})});return g(r,{indentation:" ",throwOnFailure:!1})}),y=(e,n,i,c)=>{const a={};if(i>10)return a;const r=Object.keys(n||{});for(let t of r){if(["targetNamespace","targetNSAlias"].includes(t))continue;const s=n[t];if(t.endsWith("[]")&&(t=t.slice(0,-2)),s&&typeof s=="object")a[t]=y(e,s,i+1,c);else if(typeof s=="string")switch(s.split(":")[1]){case"string":a[t]="Lorem ipsum";break;case"date":a[t]="2023-07-06";break;case"decimal":a[t]=42;break;default:a[t]=t}else{const l=`Can't generate request example. Request param ${t} not supported in endpoint ${e}`;a[t]={error:l},c.warn(l);continue}}return a},v=e=>e.trim().replace(/[^\w\-]/g,"-").replaceAll(/-+/g,"-").toLowerCase().replace(/^-|-$/g,"");function A(e){const n=b(e);return h.dirname(n)}function T(e,n){return P(A(e),n)}function x(e,n){for(const i of Object.values(e||{}))if(h.posix.normalize(i.root)===n)return Object.assign(Object.assign(Object.assign({},i.theme),i),{theme:void 0});return{}}export{_ as default};