@pb33f/cowboy-components 0.3.4 → 0.3.5

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.
@@ -155,15 +155,15 @@ let TheDoctor = class TheDoctor extends LitElement {
155
155
  //@ts-ignore
156
156
  this.explorer.equalizer.addEventListener(ExplorerEqualizerFiltered, this.filterTreeModel.bind(this));
157
157
  // extract port from session storage.
158
- this.busPort = localStorage.getItem("pb33f-doctor-port");
159
- this.busHost = localStorage.getItem("pb33f-doctor-host");
158
+ this.busPort = sessionStorage.getItem("pb33f-doctor-port");
159
+ this.busHost = sessionStorage.getItem("pb33f-doctor-host");
160
160
  if (!this.busPort) {
161
161
  this.busPort = "9090"; // default port
162
162
  }
163
163
  if (!this.busHost) {
164
164
  this.busHost = "localhost"; // default host
165
165
  }
166
- const useTLS = localStorage.getItem("pb33f-doctor-tls");
166
+ const useTLS = sessionStorage.getItem("pb33f-doctor-tls");
167
167
  if (useTLS && useTLS == 'true') {
168
168
  this.useTLS = true;
169
169
  }
@@ -9282,7 +9282,7 @@ ${w0t(g)}`}}))}render(){var Y,de,V,ye,Le;let g=B.html``,p=B.html``,f=B.html``,v=
9282
9282
  ${p}
9283
9283
  </div>
9284
9284
  </div>
9285
- `}renderPath(){return this.node.type===Pe.DOCUMENT?B.html``:this.node.label.charAt(0)!=="/"?B.html` <span class="node-path">$.<pb33f-render-json-path path="${this.node.id}"></pb33f-render-json-path></span>`:B.html``}renderLabel(g){return g=="GET"?B.html`<pb33f-http-method method="GET" large>`:g=="POST"?B.html`<pb33f-http-method method="POST" large>`:g=="PUT"?B.html`<pb33f-http-method method="PUT" large>`:g=="PATCH"?B.html`<pb33f-http-method method="PATCH" large>`:g=="DELETE"?B.html`<pb33f-http-method method="DELETE" large>`:g=="OPTIONS"?B.html`<pb33f-http-method method="OPTIONS" large>`:g=="HEAD"?B.html`<pb33f-http-method method="HEAD" large>`:g=="TRACE"?B.html`<pb33f-http-method method="TRACE" large>`:g.charAt(0)==="/"||g.charAt(0)==="{"?B.html`<pb33f-render-operation-path path="${g}"></pb33f-render-operation-path>`:B.html`${g}`}};LI.styles=[Zr,L2t,Rs],d2e([H.property()],LI.prototype,"node",2),LI=d2e([H.customElement("pb33f-rendered-node")],LI);const dP="doctor-service",BV="spec-stream",p2e="/q/";function j2t(g){return typeof g=="object"&&g!==null&&typeof g.broker=="string"}var g2e=(g=>(g.WhoAmI="whoami",g))(g2e||{}),R2t=Object.defineProperty,$2t=Object.getOwnPropertyDescriptor,wc=(g,p,f,v)=>{for(var m=v>1?void 0:v?$2t(p,f):p,E=g.length-1,C;E>=0;E--)(C=g[E])&&(m=(v?C(p,f,m):C(m))||m);return v&&m&&R2t(p,f,m),m};const pP="pb33f-doctor-graph",U2t="pb33f-doctor-editor",z2t="pb33f-doctor-howtofix",H2t="pb33f-doctor-funcdocs",G2t="pb33f-doctor-ruledocs",CV="pb33f-doctor-diagnostic",MV="pb33f-doctor-default-ruleset",IV="pb33f-doctor-owasp-ruleset",DV="pb33f-doctor-all-ruleset",FI="pb33f-doctor-functions",OI="pb33f-doctor-function-schema",TI="pb33f-doctor-custom-ruleset",dC="pb33f-doctor-rule-configuration",gP="pb33f-doctor-session-rulesetmap",PI="document",bP="problems",Y2t="doctor-endpoint";let $s=class extends B.LitElement{constructor(g="https://doctor.pb33f.io"){super(),this.debounceTime=400,this.debounceTimeRuleset=900,this.bounceId=0,this.useTLS=!1,this.bus=Yvt(),this.doctorServiceChannel=this.bus.createChannel(dP),this.specStreamChannel=this.bus.createChannel(BV),this.bus.mapChannelToBrokerDestination(p2e+dP,dP),this.bus.mapChannelToBrokerDestination(p2e+BV,BV),this.doctorChannelSubscription=this.doctorServiceChannel.subscribe(this.doctorServiceHandler()),this.specChannelSubscription=this.specStreamChannel.subscribe(this.specStreamHandler()),this.bagManager=Fve(!0),this.bagManager.loadStatefulBags().then(this.loadState.bind(this)),this.editor=new sm,this.rulesetEditor=new sm("ruleset"),this.problemList=new pT,this.detailsDrawer=new ZB,this.problemsOverview=new A2,this.errorBanner=new O4,this.statusBar=new T4,this.ruleDocsWorker=new a0t,this.unavailable=!1,this.feedback=new w2,this.activitySpinner=new xT,this.manageRuleset=new M1,this.toastManager=new BT,this.editorMap=new Map,this.editorMap.set("spec",this.editor),this.editorMap.set("ruleset",this.rulesetEditor),this.selectedEditorTab="spec",this.sidebarClosed=!1,this.explorerVisible=!1,this.explorerBooted=!1,this.nodeMap=new Map,this.nodeIdMap=new Map,this.nodeIdHashMap=new Map,this.renderedNodeMap=new Map,this.filteredNodes=new Map,this.modelTree=new um(this.nodeMap,this.nodeIdMap,this.nodeIdHashMap),this.explorer=new fw,this.renderedNode=new LI,this.nodeLimit=150;const p=sessionStorage.getItem(Y2t);p?this.doctorEndpoint=p:this.doctorEndpoint=g,this.editor.language="yaml",this.addEventListener(zq,this.specChanged),this.addEventListener(Xme,this.specClicked),this.addEventListener(aT,this.problemClicked),this.addEventListener(Qh,this.ruleDocsClicked),this.addEventListener(ove,this.ruleGroupClicked),this.addEventListener(Hq,this.customRulesetEnabled),this.addEventListener(Gq,this.rulesetSaved),this.addEventListener(N4,this.addToastEvent),this.addEventListener(uve,this.exportRuleset),this.addEventListener(ave,this.ruleClicked),this.addEventListener(uT,this.builtInRulesetSelected),this.addEventListener(im,this.modelTreeNodeClicked),this.addEventListener(Jq,this.explorerReferenceClicked),this.addEventListener(Yq,this.explorerNodeClicked.bind(this)),this.explorer.equalizer.addEventListener(Kq,this.filterTreeModel.bind(this)),this.explorer.equalizer.addEventListener(qq,this.filterTreeModel.bind(this)),this.busPort=localStorage.getItem("pb33f-doctor-port"),this.busHost=localStorage.getItem("pb33f-doctor-host"),this.busPort||(this.busPort="9090"),this.busHost||(this.busHost="localhost");const f=localStorage.getItem("pb33f-doctor-tls");f&&f=="true"&&(this.useTLS=!0),window.addEventListener("popstate",v=>{const m=v.state;m&&m.activeNode&&this.modelTreeNodeClicked(new CustomEvent(Yq,{detail:{nodeHashId:m.activeNode,noState:!0}}))})}whoAmI(){this.bus.publish({destination:"/p/q/"+dP,body:JSON.stringify({request:g2e.WhoAmI})})}connectToBroker(){let g="ws://";this.useTLS&&(g="wss://");const p={brokerURL:g+this.busHost+":"+this.busPort+"/ranch",heartbeatIncoming:0,heartbeatOutgoing:0,onConnect:()=>{console.log("💊 Connected to the %cOpenAPI Doctor%c, we are ready to communicate.","background: #0d1117; color: #62C4FFFF; font-weight: bold","color: default"),this.whoAmI()}};this.bus.connectToBroker(p)}addClickTrack(g){history.pushState({activeNode:g.idHash},"",`?view=explore&node=${g.idHash}`)}doctorServiceHandler(){return g=>{var p;((p=g.payload)==null?void 0:p.payload)!=null&&j2t(g.payload.payload)&&(this.brokerConnectionId=g.payload.payload.broker,console.log("💊 Welcome patient %c"+this.brokerConnectionId,"color: #62C4FFFF; font-weight: bold"),this.boostrap(),this.loadingOverlay.hide())}}specStreamHandler(){return g=>{var p,f;if(((p=g.payload)==null?void 0:p.payload)!=null){const v=atob(g.payload.payload);this.docBag&&this.docBag.set(PI,v),(f=this.editor)==null||f.setValue(v,!0),this.requestUpdate()}}}filterTreeModel(g){this.filteredNodes=new Map,g.detail.graph.nodes.forEach(p=>{this.filteredNodes.set(p.idHash,p)}),this.modelTree.filteredNodes=this.filteredNodes,this.modelTree.renderedNodes=this.renderedNodeMap}explorerReferenceClicked(g){let p="";this.explorer.nodeComponents.forEach(f=>{var v,m;if(f.body.node.nodePath===g.detail.nodePath){const E=this.renderedNodeMap.get(f.body.node.idHash);E&&((v=this.editor.editor)==null||v.setPosition({lineNumber:E.keyLine,column:0}),(m=this.editor.editor)==null||m.revealLineInCenter(E.keyLine),this.renderedNode.node=E,p=f.body.node.idHash,this.explorer.moveToNode(f.body.node),this.activeNode=f.body.node,this.explorer.activeNode=f.body.node,this.explorer.equalizer.activeNode=f.body.node),f.body.active=!0}else f.body.active=!1}),p&&(this.modelTree.explorerClicked(p),this.explorer.requestUpdate(),this.viewerPanel.click())}modelTreeNodeClicked(g){var f,v;const p=this.nodeIdHashMap.get(g.detail.nodeHashId);if(p){(f=this.editor.editor)==null||f.setPosition({lineNumber:p.keyLine,column:0}),(v=this.editor.editor)==null||v.revealLineInCenter(p.keyLine),this.explorerVisible&&this.explorer.moveToNode(p,g.detail.first),this.activeNode=p,this.explorer.activeNode=p,this.explorer.equalizer.activeNode=p;const m=this.renderedNodeMap.get(p.idHash);m&&(this.renderedNode.node=m),g.detail.noState||(this.addClickTrack(p),g.detail.noState=!0),this.explorerNodeClicked(g),this.viewerPanel.click()}}explorerNodeClicked(g){let p=!1;if(this.explorer.nodeComponents.forEach(f=>{if(f.id===g.detail.nodeHashId){const v=this.renderedNodeMap.get(f.id);v&&(this.renderedNode.node=v),this.selectedNodeHashId=f.body.node.idHash,f.body.active=!0,this.activeNode=f.body.node,this.explorer.activeNode=f.body.node,p=!0,g.detail.noState||this.addClickTrack(f.body.node)}else f.body.active=!1}),!p){const f=this.nodeIdHashMap.get(g.detail.nodeHashId);f&&(this.selectedNodeHashId=g.detail.nodeHashId,this.activeNode=f,this.explorer.activeNode=f,this.explorer.equalizer.activeNode=f)}this.modelTree.explorerClicked(g.detail.nodeHashId),this.viewerPanel.click(),this.explorer.requestUpdate()}exportRuleset(){this.exportRulesetDialog.show()}addToastEvent(g){this.sendToast(g.detail.toast)}sendToast(g){this.toastManager.addToastManually(g)}ruleGroupClicked(g){this.problemsPanel.focus();const p=new CustomEvent(ive,{bubbles:!0,composed:!0,detail:{rule:g.detail.rule}});this.problemsPanel.focus(),this.problemList.dispatchEvent(p),history.pushState({rule:g.detail.rule},"",`/${Oa.Problems}?rule=${g.detail.rule}`),this.controlTabGroup.show(Oa.Problems)}ruleDocsClicked(g){var f,v,m;const p=g.detail.rule;if(p)switch(g.detail.type){case ia.RULE_DOCS:const E=(f=this.ruleDocsBag)==null?void 0:f.get(p);E?(g.detail.body=E.body,this.detailsDrawer.open(g.detail)):this.sendToast({id:crypto.randomUUID(),type:Fl.INFO,title:"Rule documentation unavailable",body:`Documentation for '${p}' not available`});break;case ia.HOW_TO_FIX:const C=(v=this.howToFixBag)==null?void 0:v.get(p);C?(g.detail.body=C.howToFix,this.detailsDrawer.open(g.detail)):this.sendToast({id:crypto.randomUUID(),type:Fl.INFO,title:"How to fix unavailable",body:`Information on how to fix '${p}' not available`});break;case ia.FUNCTION_DOCS:const q=(m=this.functionDocsBag)==null?void 0:m.get(p);q?(g.detail.body=q.body,this.detailsDrawer.open(g.detail)):this.sendToast({id:crypto.randomUUID(),type:Fl.INFO,title:"Function documentation unavailable",body:`Documentation for '${p}' not available`});break}else switch(g.detail.type){case ia.RENDERED_EXAMPLE:case ia.MARKDOWN:this.detailsDrawer.open(g.detail)}}rulesetSaved(g){var p,f,v;if(this.docBag){const m=this.docBag.get(PI),E=(p=this.RuleConfigBag)==null?void 0:p.get(dC);if(g.detail.rules){if((f=this.CustomRulesetBag)==null||f.set(TI,g.detail.rules),E){const C=g.detail.config;C&&this.RuleConfigBag&&(C.returnedRuleset=g.detail.returnedRules,(v=this.RuleConfigBag)==null||v.set(dC,C))}jh.getSessionRulesetAsYAML().then(C=>{this.selectedEditorTab=="spec"&&(this.rulesetPulse=!0),this.rulesetEditor.setValue(C,!0),this.fetchRulesetMap()}),this.lintSpec(m)}}}lintSpec(g,p){this.activitySpinner.show(),p&&(this.urlProblem.style.display="none",this.urlOverlay.style.display="block",this.urlSpinner.style.display="block"),p2.lintFile(g,this.brokerConnectionId,p).then(f=>{var v,m;p&&(this.urlOverlay.style.display="none",this.urlSpinner.style.display="none",this.urlProblem.style.display="none"),f&&!Array.isArray(f)&&(this.editor.setMarkers([f]),(v=this.problemBag)==null||v.set(bP,[f]),this.problemList.problems=[f],this.problems=[f],this.problemsOverview.problems=this.problemList.problemItems),f&&Array.isArray(f)&&(this.editor.setMarkers(f),(m=this.problemBag)==null||m.set(bP,f),this.problemList.problems=f,this.problems=f,this.problemsOverview.problems=this.problemList.problemItems),S4.createGraph().then(E=>{this.extractGraph(E)}),p2.fetchStatistics().then(E=>{var q;let C=0;if(this.problemsOverview.statistics&&(C=this.problemsOverview.statistics.statistics.overallScore),(q=this.diagnosticBag)==null||q.set(CV,E),this.activitySpinner.hide(),(E==null?void 0:E.remainingCredit)<=10&&(this.statusBar.callsRemaining=E.remainingCredit,this.statusBar.visible=!0,console.warn("You are running low on credit, you will need to authenticate soon. "+E.remainingCredit+" credits remaining.")),this.problemsOverview.statistics=E,this.problemsOverview.statistics){const Y=E.statistics.overallScore;C>Y&&this.sendToast({id:crypto.randomUUID(),type:Fl.SCOREDOWN,body:"Your score has decreased. It is now "+Y+"%",title:"Score went down by "+(C-Y)+"%"}),C<Y&&this.sendToast({id:crypto.randomUUID(),type:Fl.SCOREUP,body:"Your score has increased to "+Y+"%",title:"Score went up by "+(Y-C)+"%"})}}).catch(E=>{console.error("statistics service is down",E),this.platformUnavailable(E)})}).catch(f=>{p?this.showUrlError(f):(this.platformUnavailable(f),console.error("so sorry, the doctor cannot see you right now, the clinic is closed."),f&&(console.error(f.detail),f.instance==="https://pb33f.io/errors/no-credit-remaining"&&(this.statusBar.callsRemaining=0,this.statusBar.visible=!0,this.sendToast({id:crypto.randomUUID(),type:Fl.ERROR,body:"Run out of credit, please authenticate for more or wait 24 hours.",title:"Credit exhausted!"}))))})}platformUnavailable(g){this.unavailable||(this.loadingOverlay.hide(),this.activitySpinner.hide(),this.errorBanner.errorTitle="The doctor is out.",g?this.errorBanner.errorMessage="The clinic is <strong>closed!</strong> The doctor is currently unavailable because "+g.detail:this.errorBanner.errorMessage="The clinic is <strong>closed!</strong> The doctor is currently unavailable because there is no response from the platform.",this.errorBanner.visible=!0,this.unavailable=!0,this.problemsOverview.unavailable=!0,this.controlTabGroup.show(Oa.Overview))}specClicked(g){var p,f,v;if(this.detailsDrawer.close(),this.selectedEditorTab=="spec"){let m=!1;for(let C=0;C<((p=this.problems)==null?void 0:p.length);C++)if(this.problems[C].startLineNumber===g.detail.line){this.problemList.lineClicked(g.detail.line,!0),this.controlTabGroup.show(Oa.Problems),this.sidebarClosed&&this.toggleSidebar(),m=!0;break}const E=(f=this.graphBag)==null?void 0:f.get(pP);if(E&&E.graphMap&&g.detail.line){const C=E.graphMap[g.detail.line];if(C){this.modelTree.explorerClicked(C);const q=this.renderedNodeMap.get(C);q&&(this.renderedNode.node=q),m||this.viewerPanel.click();const Y=this.nodeIdHashMap.get(C);Y&&(this.explorer.activeNode=Y,this.explorer.equalizer.activeNode=Y)}}}if(this.selectedEditorTab==Oa.Ruleset){const m=(v=this.sessionRulesetMapBag)==null?void 0:v.get(gP);if(m!=null&&m.rulesMap){for(let E=0;E<m.rulesMap.length;E++)if(m.rulesMap[E].line===g.detail.line){this.controlTabGroup.show(Oa.Ruleset),this.sidebarClosed&&this.toggleSidebar();break}}}}problemClicked(g){var p,f;this.selectedEditorTab!="spec"&&(this.editorTabGroup.show("spec"),this.selectedEditorTab="spec"),this.controlTabGroup.show(Oa.Problems),(p=this.editor.editor)==null||p.revealLineInCenter(g.detail.problem.line),(f=this.editor.editor)==null||f.setPosition({lineNumber:g.detail.problem.line,column:g.detail.problem.column}),this.detailsDrawer.close(),g.detail.launchedFromProblems||this.problemList.lineClicked(g.detail.problem.problemObject.startLineNumber)}loadState(){if(p2.doctorEndpoint=this.doctorEndpoint,yT.doctorEndpoint=this.doctorEndpoint,jh.doctorEndpoint=this.doctorEndpoint,S4.doctorEndpoint=this.doctorEndpoint,this.connectToBroker(),this.graphBag=this.bagManager.getBag(pP),this.docBag=this.bagManager.getBag(U2t),this.docBag){const p=this.docBag.get(PI);p&&this.editor.setValue(p,!0)}if(this.problemBag=this.bagManager.getBag(bP),this.problemBag){const p=this.problemBag.get(bP);if(p){this.problems=p,this.editor.setMarkers(p);for(let f=0;f<p.length;f++)p[f]=rm.reconstruct(p[f]);this.problemList.problems=p,this.problemsOverview.problems=this.problemList.problemItems}}if(this.howToFixBag=this.bagManager.getBag(z2t),this.diagnosticBag=this.bagManager.getBag(CV),this.diagnosticBag){const p=this.diagnosticBag.get(CV);p&&(this.problemsOverview.statistics=p)}if(this.graphBag){const p=this.graphBag.get(pP);p&&this.extractGraph(p)}const g=[];if(this.DefaultRulesetBag=this.bagManager.getBag(MV),this.DefaultRulesetBag){const p=this.DefaultRulesetBag.get(MV);p?this.defaultRuleset=p:g.push(this.fetchDefaultRuleset())}if(this.OWASPRulesetBag=this.bagManager.getBag(IV),this.OWASPRulesetBag){const p=this.OWASPRulesetBag.get(IV);p?this.OWASPRuleset=p:g.push(this.fetchOWASPRuleset())}if(this.AllRulesetBag=this.bagManager.getBag(DV),this.AllRulesetBag){const p=this.AllRulesetBag.get(DV);p?this.AllRuleset=p:g.push(this.fetchAllRuleset())}if(this.FunctionsBag=this.bagManager.getBag(FI),this.FunctionSchemaBag=this.bagManager.getBag(OI),this.FunctionsBag){const p=this.FunctionsBag.get(FI);p?this.functions=p:g.push(this.fetchFunctions())}if(this.CustomRulesetBag=this.bagManager.getBag(TI),this.CustomRulesetBag){const p=this.CustomRulesetBag.get(TI);p&&(this.CustomRuleset=p)}this.RuleConfigBag=this.bagManager.getBag(dC),this.sessionRulesetMapBag=this.bagManager.getBag(gP),Promise.all(g).then(()=>{var f;this.manageRuleset.defaultRuleset=this.defaultRuleset,this.manageRuleset.owaspRuleset=this.OWASPRuleset,this.manageRuleset.allRuleset=this.AllRuleset,this.manageRuleset.functions=this.functions;const p=(f=this.RuleConfigBag)==null?void 0:f.get(dC);p?this.manageRuleset.rulesetConfig=p:this.manageRuleset.rulesetConfig={ruleMapping:new Map,allRulesSwitch:!0},setTimeout(()=>{this.manageRuleset.buildRulesets(),this.CustomRuleset&&this.CustomRuleset.rules.size>0&&(this.manageRuleset.customRuleset=this.CustomRuleset),this.fetchSessionRulesetAsYaml().then(v=>{var m;(m=this.rulesetEditor)==null||m.setValue(v,!0),this.fetchRulesetMap()}).catch(v=>{this.platformUnavailable(v)})},50)}),this.fetchDocs()}extractGraph(g){var f;g.stripped?(this.explorer.nodeLimitExceeded=!0,this.modelTree.nodeLimitExceeded=!0,g.strippedCount&&(this.explorer.nodeLimit=g.strippedCount,this.modelTree.nodeLimit=g.strippedCount)):(this.explorer.nodeLimitExceeded=!1,this.modelTree.nodeLimitExceeded=!1),this.explorer.renderedNodeMap.clear(),this.nodeMap.clear(),this.nodeIdMap.clear(),this.nodeIdHashMap.clear();const p=new Map;g.nodesRendered.forEach(v=>{this.explorer.renderedNodeMap.set(v.id,v),p.set(v.idHash,v)});for(let v=0;v<g.nodesRendered.length;v++)this.renderedNodeMap.set(g.nodesRendered[v].idHash,g.nodesRendered[v]);g.nodes.forEach(v=>{var E;this.nodeMap.set("model-"+v.idHash,v),this.nodeIdMap.set(v.id,v),this.nodeIdHashMap.set(v.idHash,v),v.filtered&&this.filteredNodes.set(v.idHash,v);const m=this.renderedNodeMap.get(v.idHash);((E=this.activeNode)==null?void 0:E.id)===v.id&&this.renderedNodeMap.get(v.idHash)&&this.renderedNode&&m&&(this.renderedNode.node=m)}),(f=this.graphBag)==null||f.set(pP,g),this.explorer.updateGraphResponse(g),this.modelTree.node=g.nodes[0],this.explorer.equalizer.runEQ()}customRulesetEnabled(g){var f,v,m;const p={rules:new Map};p.id=crypto.randomUUID(),p.owner=this.session.sessionId,g.detail.rules.forEach(E=>{E.rule.id!=E.ruleId&&(E.rule.id=E.ruleId),p.rules.set(E.ruleId,E.rule)}),(f=this.CustomRulesetBag)==null||f.set(TI,p),g.detail.ruleConfig?(v=this.RuleConfigBag)==null||v.set(dC,g.detail.ruleConfig):((m=this.RuleConfigBag)==null||m.reset(),jh.resetSessionRuleset(g.detail.rulesetReset).then(()=>{if(this.sendToast({id:crypto.randomUUID(),type:Fl.INFO,body:"Ruleset has been reset to the default",title:"Ruleset reset"}),this.docBag){const E=this.docBag.get(PI);this.lintSpec(E)}this.fetchSessionRulesetAsYaml().then(E=>{var C;(C=this.rulesetEditor)==null||C.setValue(E,!0)})}).catch(E=>{this.sendToast({id:crypto.randomUUID(),type:Fl.ERROR,body:E.detail,title:"Cannot reset ruleset"})}))}async fetchSessionRulesetAsYaml(){return new Promise(async(g,p)=>{jh.getSessionRulesetAsYAML().then(f=>{g(f)}).catch(f=>{console.error("cannot fetch session ruleset: ",f.title),p(f)})})}async fetchFunctions(){return new Promise(async g=>{jh.getFunctions().then(p=>{var v;this.functions=p,(v=this.FunctionsBag)==null||v.set(FI,p);const f=[];p.forEach(m=>{f.push(this.fetchFunctionSchema(m))}),Promise.all(f).then(()=>{g(p)})})})}async fetchFunctionSchema(g){return new Promise(async p=>{jh.getFunctionSchema(g).then(f=>{var m,E;let v=(m=this.FunctionSchemaBag)==null?void 0:m.get(OI);v||(v=new Map),v.set(g,f),(E=this.FunctionSchemaBag)==null||E.set(OI,v),p(f)})})}async fetchDefaultRuleset(){return new Promise(async g=>{jh.getDefaultRuleset().then(p=>{var f;this.defaultRuleset=p,(f=this.DefaultRulesetBag)==null||f.set(MV,p),g(p)})})}async fetchOWASPRuleset(){return new Promise(async g=>{jh.getOWASPRuleset().then(p=>{var f;this.OWASPRuleset=p,(f=this.OWASPRulesetBag)==null||f.set(IV,p),g(p)})})}async fetchAllRuleset(){return new Promise(async g=>{jh.getAllRuleset().then(p=>{var f;this.AllRuleset=p,(f=this.AllRulesetBag)==null||f.set(DV,p),g(p)})})}fetchDocs(){this.activitySpinner.show(),p2.startSession().then(g=>{this.session=g,p2.fetchAllHowToFix().then(p=>{p&&p.forEach(f=>{var v;(v=this.howToFixBag)==null||v.set(f.ruleId,f)})}).catch(p=>{this.platformUnavailable(p),console.error("documentation service is down")}),this.ruleDocsBag=this.bagManager.getBag(G2t),this.functionDocsBag=this.bagManager.getBag(H2t),this.ruleDocsWorker.addEventListener("message",p=>{const f=p.data;f&&(f.forEach(v=>{var m,E;v.ruleId&&((m=this.ruleDocsBag)==null||m.set(v.ruleId,v)),v.functionId&&((E=this.functionDocsBag)==null||E.set(v.functionId,v))}),this.activitySpinner.hide())}),this.ruleDocsWorker.postMessage({start:!0,endpoint:this.doctorEndpoint})}).catch(g=>{this.platformUnavailable(g),console.error("cannot start session")})}fetchRulesetMap(){jh.getSessionRulesetMap().then(g=>{var p;(p=this.sessionRulesetMapBag)==null||p.set(gP,g)}).catch(()=>{console.warn("map is empty, or unavailable, Did you submit an empty ruleset?"),this.sendToast({id:crypto.randomUUID(),type:Fl.WARNING,body:"map is empty, or unavailable, Did you submit an empty ruleset?",title:"Issue fetching ruleset map"})})}ruleClicked(g){var f,v,m;const p=(f=this.sessionRulesetMapBag)==null?void 0:f.get(gP);if(p){const E=p.rulesMap.find(C=>C.ruleId===g.detail.ruleId);E&&(this.selectedEditorTab="ruleset",this.editorTabGroup.show(Oa.Ruleset),(v=this.rulesetEditor.editor)==null||v.setPosition({lineNumber:E.line,column:E.start}),(m=this.rulesetEditor.editor)==null||m.revealLineInCenter(E.line))}}builtInRulesetSelected(){}rulesetManuallyChanged(){clearTimeout(this.bounceId),this.bounceId=window.setTimeout(()=>{var p;const g=(p=this.rulesetEditor.editor)==null?void 0:p.getValue();jh.validateRuleset(g).then(f=>{var m;this.manageRuleset.clearRuleProblems();let v={rules:new Map};v.id=crypto.randomUUID(),v.owner=this.session.sessionId,v.rules=new Map(Object.entries(f.rules)),v.rules.forEach((E,C)=>{E.id=C}),(m=this.CustomRulesetBag)==null||m.set(TI,v),this.CustomRuleset=v,v.rules.size>0&&(this.manageRuleset.customRulesetManual=v),this.selectedEditorTab=Oa.Ruleset,this.controlTabGroup.show(Oa.Ruleset),this.rulesetEditor.setMarkers([]),this.fetchRulesetMap()}).catch(f=>{this.sendToast({id:crypto.randomUUID(),type:Fl.ERROR,body:f.detail,title:f.title}),console.error("unable to validate ruleset",f);const v=f.body,m=[];v==null||v.forEach(E=>{m.push({severity:u2.MarkerSeverity.Error,message:E.ruleError,startLineNumber:E.line,startColumn:E.startCol,endLineNumber:E.line,endColumn:E.endCol})}),jh.convertToJSON(g).then(E=>{let C={rules:new Map};C.id=crypto.randomUUID(),C.owner=this.session.sessionId,C.rules=new Map(Object.entries(E.rules)),C.rules.forEach((q,Y)=>{q.id!=Y&&(q.id=Y)}),this.CustomRuleset=C,C.rules.size>0&&(this.manageRuleset.customRulesetManual=C),this.rulesetEditor.setMarkers([]),this.manageRuleset.clearRuleProblems(),this.rulesetEditor.setMarkers(m),this.manageRuleset.processBadRules(v),this.controlTabGroup.show(Oa.Ruleset)}).catch(E=>{console.error("unable to convert ruleset to JSON",E)})})},this.debounceTimeRuleset)}specChanged(g){if(this.editorMap.get(g.detail.id)&&g.detail.id==="ruleset"){this.rulesetManuallyChanged();return}this.docBag&&this.docBag.set(PI,g.detail.content),clearTimeout(this.bounceId),this.bounceId=window.setTimeout(()=>{this.lintSpec(g.detail.content)},this.debounceTime)}boostrap(){const p=new URL(window.location.href).searchParams.get("url");if(p){this.urlInput.value=p,this.lintSpec("",p);return}this.editor.getValue()===""&&p2.bootstrapEditor().then(f=>{this.editor.setValue(f,!0),this.specChanged(new CustomEvent(zq,{detail:{content:f,id:"spec"}}))})}exportJSON(){let g;if(this.RuleConfigBag){const p=this.RuleConfigBag.get(dC);p&&p.returnedRuleset&&(g=p.returnedRuleset)}if(g){let p="data:text/json;charset=utf-8,"+encodeURIComponent(JSON.stringify(g,null,2));this.downloadRulesetLink.download="ruleset.json",this.downloadRulesetLink.href=p,this.downloadRulesetLink.click(),this.exportRulesetDialog.hide()}}exportYAML(){jh.getSessionRulesetAsYAML().then(g=>{let p="data:text/yaml;charset=utf-8,"+encodeURIComponent(g);this.downloadRulesetLink.download="ruleset.yaml",this.downloadRulesetLink.href=p,this.downloadRulesetLink.click(),this.exportRulesetDialog.hide()})}confirmExport(){switch(this.exportSelection.value){case"json":this.exportJSON();break;case"yaml":this.exportYAML();break}}closeWelcome(){this.welcomeBox.hide(),localStorage.setItem("pb33f-doctor-welcome","closed")}selectEditorTab(g){switch(this.selectedEditorTab=g.detail.name,g.detail.name){case Oa.Ruleset:this.rulesetPulse&&(this.rulesetPulse=!1),this.controlTabGroup.show(Oa.Ruleset);break}}selectControlTab(g){switch(g.detail.name){case Oa.Problems:case Oa.Overview:this.selectedEditorTab!="spec"&&(this.selectedEditorTab="spec",this.editorTabGroup.show("spec"));break;case Oa.Ruleset:this.selectedEditorTab!=Oa.Ruleset&&(this.editorTabGroup.show(Oa.Ruleset),this.selectedEditorTab=Oa.Ruleset);break}}toggleSidebar(){var p;const g=(p=this.shadowRoot)==null?void 0:p.querySelector("sl-split-panel.split-panel");this.sidebarClosed?g&&(this.collapseButton.name="chevron-bar-right",g.style.setProperty("--min","600px"),g.style.setProperty("--max","calc(100vw - 600px)"),g.position=60,g.disabled=!1,this.problemsDataDiv.style.display="block",this.splitDivider.style.display="block",this.activitySpinner.classList.remove("spinner-draw-closed")):g&&(this.collapseButton.name="chevron-bar-left",this.problemsDataDiv.style.display="none",g.style.setProperty("--min","40px"),g.style.setProperty("--max","calc(100vw - 40px)"),g.position=99,g.disabled=!0,this.splitDivider.style.display="none",this.activitySpinner.classList.add("spinner-draw-closed")),this.sidebarClosed=!this.sidebarClosed}toggleExplorer(){this.explorerVisible=!0,this.explorerVisible&&this.explorer.moveToNode(this.activeNode),this.explorerBooted||(this.explorer.equalizer.initializeEqualizer(),this.explorerBooted=!0)}closeExplorer(){this.explorerVisible=!1}render(){let g=B.html``;this.unavailable&&(g=B.html`
9285
+ `}renderPath(){return this.node.type===Pe.DOCUMENT?B.html``:this.node.label.charAt(0)!=="/"?B.html` <span class="node-path">$.<pb33f-render-json-path path="${this.node.id}"></pb33f-render-json-path></span>`:B.html``}renderLabel(g){return g=="GET"?B.html`<pb33f-http-method method="GET" large>`:g=="POST"?B.html`<pb33f-http-method method="POST" large>`:g=="PUT"?B.html`<pb33f-http-method method="PUT" large>`:g=="PATCH"?B.html`<pb33f-http-method method="PATCH" large>`:g=="DELETE"?B.html`<pb33f-http-method method="DELETE" large>`:g=="OPTIONS"?B.html`<pb33f-http-method method="OPTIONS" large>`:g=="HEAD"?B.html`<pb33f-http-method method="HEAD" large>`:g=="TRACE"?B.html`<pb33f-http-method method="TRACE" large>`:g.charAt(0)==="/"||g.charAt(0)==="{"?B.html`<pb33f-render-operation-path path="${g}"></pb33f-render-operation-path>`:B.html`${g}`}};LI.styles=[Zr,L2t,Rs],d2e([H.property()],LI.prototype,"node",2),LI=d2e([H.customElement("pb33f-rendered-node")],LI);const dP="doctor-service",BV="spec-stream",p2e="/q/";function j2t(g){return typeof g=="object"&&g!==null&&typeof g.broker=="string"}var g2e=(g=>(g.WhoAmI="whoami",g))(g2e||{}),R2t=Object.defineProperty,$2t=Object.getOwnPropertyDescriptor,wc=(g,p,f,v)=>{for(var m=v>1?void 0:v?$2t(p,f):p,E=g.length-1,C;E>=0;E--)(C=g[E])&&(m=(v?C(p,f,m):C(m))||m);return v&&m&&R2t(p,f,m),m};const pP="pb33f-doctor-graph",U2t="pb33f-doctor-editor",z2t="pb33f-doctor-howtofix",H2t="pb33f-doctor-funcdocs",G2t="pb33f-doctor-ruledocs",CV="pb33f-doctor-diagnostic",MV="pb33f-doctor-default-ruleset",IV="pb33f-doctor-owasp-ruleset",DV="pb33f-doctor-all-ruleset",FI="pb33f-doctor-functions",OI="pb33f-doctor-function-schema",TI="pb33f-doctor-custom-ruleset",dC="pb33f-doctor-rule-configuration",gP="pb33f-doctor-session-rulesetmap",PI="document",bP="problems",Y2t="doctor-endpoint";let $s=class extends B.LitElement{constructor(g="https://doctor.pb33f.io"){super(),this.debounceTime=400,this.debounceTimeRuleset=900,this.bounceId=0,this.useTLS=!1,this.bus=Yvt(),this.doctorServiceChannel=this.bus.createChannel(dP),this.specStreamChannel=this.bus.createChannel(BV),this.bus.mapChannelToBrokerDestination(p2e+dP,dP),this.bus.mapChannelToBrokerDestination(p2e+BV,BV),this.doctorChannelSubscription=this.doctorServiceChannel.subscribe(this.doctorServiceHandler()),this.specChannelSubscription=this.specStreamChannel.subscribe(this.specStreamHandler()),this.bagManager=Fve(!0),this.bagManager.loadStatefulBags().then(this.loadState.bind(this)),this.editor=new sm,this.rulesetEditor=new sm("ruleset"),this.problemList=new pT,this.detailsDrawer=new ZB,this.problemsOverview=new A2,this.errorBanner=new O4,this.statusBar=new T4,this.ruleDocsWorker=new a0t,this.unavailable=!1,this.feedback=new w2,this.activitySpinner=new xT,this.manageRuleset=new M1,this.toastManager=new BT,this.editorMap=new Map,this.editorMap.set("spec",this.editor),this.editorMap.set("ruleset",this.rulesetEditor),this.selectedEditorTab="spec",this.sidebarClosed=!1,this.explorerVisible=!1,this.explorerBooted=!1,this.nodeMap=new Map,this.nodeIdMap=new Map,this.nodeIdHashMap=new Map,this.renderedNodeMap=new Map,this.filteredNodes=new Map,this.modelTree=new um(this.nodeMap,this.nodeIdMap,this.nodeIdHashMap),this.explorer=new fw,this.renderedNode=new LI,this.nodeLimit=150;const p=sessionStorage.getItem(Y2t);p?this.doctorEndpoint=p:this.doctorEndpoint=g,this.editor.language="yaml",this.addEventListener(zq,this.specChanged),this.addEventListener(Xme,this.specClicked),this.addEventListener(aT,this.problemClicked),this.addEventListener(Qh,this.ruleDocsClicked),this.addEventListener(ove,this.ruleGroupClicked),this.addEventListener(Hq,this.customRulesetEnabled),this.addEventListener(Gq,this.rulesetSaved),this.addEventListener(N4,this.addToastEvent),this.addEventListener(uve,this.exportRuleset),this.addEventListener(ave,this.ruleClicked),this.addEventListener(uT,this.builtInRulesetSelected),this.addEventListener(im,this.modelTreeNodeClicked),this.addEventListener(Jq,this.explorerReferenceClicked),this.addEventListener(Yq,this.explorerNodeClicked.bind(this)),this.explorer.equalizer.addEventListener(Kq,this.filterTreeModel.bind(this)),this.explorer.equalizer.addEventListener(qq,this.filterTreeModel.bind(this)),this.busPort=sessionStorage.getItem("pb33f-doctor-port"),this.busHost=sessionStorage.getItem("pb33f-doctor-host"),this.busPort||(this.busPort="9090"),this.busHost||(this.busHost="localhost");const f=sessionStorage.getItem("pb33f-doctor-tls");f&&f=="true"&&(this.useTLS=!0),window.addEventListener("popstate",v=>{const m=v.state;m&&m.activeNode&&this.modelTreeNodeClicked(new CustomEvent(Yq,{detail:{nodeHashId:m.activeNode,noState:!0}}))})}whoAmI(){this.bus.publish({destination:"/p/q/"+dP,body:JSON.stringify({request:g2e.WhoAmI})})}connectToBroker(){let g="ws://";this.useTLS&&(g="wss://");const p={brokerURL:g+this.busHost+":"+this.busPort+"/ranch",heartbeatIncoming:0,heartbeatOutgoing:0,onConnect:()=>{console.log("💊 Connected to the %cOpenAPI Doctor%c, we are ready to communicate.","background: #0d1117; color: #62C4FFFF; font-weight: bold","color: default"),this.whoAmI()}};this.bus.connectToBroker(p)}addClickTrack(g){history.pushState({activeNode:g.idHash},"",`?view=explore&node=${g.idHash}`)}doctorServiceHandler(){return g=>{var p;((p=g.payload)==null?void 0:p.payload)!=null&&j2t(g.payload.payload)&&(this.brokerConnectionId=g.payload.payload.broker,console.log("💊 Welcome patient %c"+this.brokerConnectionId,"color: #62C4FFFF; font-weight: bold"),this.boostrap(),this.loadingOverlay.hide())}}specStreamHandler(){return g=>{var p,f;if(((p=g.payload)==null?void 0:p.payload)!=null){const v=atob(g.payload.payload);this.docBag&&this.docBag.set(PI,v),(f=this.editor)==null||f.setValue(v,!0),this.requestUpdate()}}}filterTreeModel(g){this.filteredNodes=new Map,g.detail.graph.nodes.forEach(p=>{this.filteredNodes.set(p.idHash,p)}),this.modelTree.filteredNodes=this.filteredNodes,this.modelTree.renderedNodes=this.renderedNodeMap}explorerReferenceClicked(g){let p="";this.explorer.nodeComponents.forEach(f=>{var v,m;if(f.body.node.nodePath===g.detail.nodePath){const E=this.renderedNodeMap.get(f.body.node.idHash);E&&((v=this.editor.editor)==null||v.setPosition({lineNumber:E.keyLine,column:0}),(m=this.editor.editor)==null||m.revealLineInCenter(E.keyLine),this.renderedNode.node=E,p=f.body.node.idHash,this.explorer.moveToNode(f.body.node),this.activeNode=f.body.node,this.explorer.activeNode=f.body.node,this.explorer.equalizer.activeNode=f.body.node),f.body.active=!0}else f.body.active=!1}),p&&(this.modelTree.explorerClicked(p),this.explorer.requestUpdate(),this.viewerPanel.click())}modelTreeNodeClicked(g){var f,v;const p=this.nodeIdHashMap.get(g.detail.nodeHashId);if(p){(f=this.editor.editor)==null||f.setPosition({lineNumber:p.keyLine,column:0}),(v=this.editor.editor)==null||v.revealLineInCenter(p.keyLine),this.explorerVisible&&this.explorer.moveToNode(p,g.detail.first),this.activeNode=p,this.explorer.activeNode=p,this.explorer.equalizer.activeNode=p;const m=this.renderedNodeMap.get(p.idHash);m&&(this.renderedNode.node=m),g.detail.noState||(this.addClickTrack(p),g.detail.noState=!0),this.explorerNodeClicked(g),this.viewerPanel.click()}}explorerNodeClicked(g){let p=!1;if(this.explorer.nodeComponents.forEach(f=>{if(f.id===g.detail.nodeHashId){const v=this.renderedNodeMap.get(f.id);v&&(this.renderedNode.node=v),this.selectedNodeHashId=f.body.node.idHash,f.body.active=!0,this.activeNode=f.body.node,this.explorer.activeNode=f.body.node,p=!0,g.detail.noState||this.addClickTrack(f.body.node)}else f.body.active=!1}),!p){const f=this.nodeIdHashMap.get(g.detail.nodeHashId);f&&(this.selectedNodeHashId=g.detail.nodeHashId,this.activeNode=f,this.explorer.activeNode=f,this.explorer.equalizer.activeNode=f)}this.modelTree.explorerClicked(g.detail.nodeHashId),this.viewerPanel.click(),this.explorer.requestUpdate()}exportRuleset(){this.exportRulesetDialog.show()}addToastEvent(g){this.sendToast(g.detail.toast)}sendToast(g){this.toastManager.addToastManually(g)}ruleGroupClicked(g){this.problemsPanel.focus();const p=new CustomEvent(ive,{bubbles:!0,composed:!0,detail:{rule:g.detail.rule}});this.problemsPanel.focus(),this.problemList.dispatchEvent(p),history.pushState({rule:g.detail.rule},"",`/${Oa.Problems}?rule=${g.detail.rule}`),this.controlTabGroup.show(Oa.Problems)}ruleDocsClicked(g){var f,v,m;const p=g.detail.rule;if(p)switch(g.detail.type){case ia.RULE_DOCS:const E=(f=this.ruleDocsBag)==null?void 0:f.get(p);E?(g.detail.body=E.body,this.detailsDrawer.open(g.detail)):this.sendToast({id:crypto.randomUUID(),type:Fl.INFO,title:"Rule documentation unavailable",body:`Documentation for '${p}' not available`});break;case ia.HOW_TO_FIX:const C=(v=this.howToFixBag)==null?void 0:v.get(p);C?(g.detail.body=C.howToFix,this.detailsDrawer.open(g.detail)):this.sendToast({id:crypto.randomUUID(),type:Fl.INFO,title:"How to fix unavailable",body:`Information on how to fix '${p}' not available`});break;case ia.FUNCTION_DOCS:const q=(m=this.functionDocsBag)==null?void 0:m.get(p);q?(g.detail.body=q.body,this.detailsDrawer.open(g.detail)):this.sendToast({id:crypto.randomUUID(),type:Fl.INFO,title:"Function documentation unavailable",body:`Documentation for '${p}' not available`});break}else switch(g.detail.type){case ia.RENDERED_EXAMPLE:case ia.MARKDOWN:this.detailsDrawer.open(g.detail)}}rulesetSaved(g){var p,f,v;if(this.docBag){const m=this.docBag.get(PI),E=(p=this.RuleConfigBag)==null?void 0:p.get(dC);if(g.detail.rules){if((f=this.CustomRulesetBag)==null||f.set(TI,g.detail.rules),E){const C=g.detail.config;C&&this.RuleConfigBag&&(C.returnedRuleset=g.detail.returnedRules,(v=this.RuleConfigBag)==null||v.set(dC,C))}jh.getSessionRulesetAsYAML().then(C=>{this.selectedEditorTab=="spec"&&(this.rulesetPulse=!0),this.rulesetEditor.setValue(C,!0),this.fetchRulesetMap()}),this.lintSpec(m)}}}lintSpec(g,p){this.activitySpinner.show(),p&&(this.urlProblem.style.display="none",this.urlOverlay.style.display="block",this.urlSpinner.style.display="block"),p2.lintFile(g,this.brokerConnectionId,p).then(f=>{var v,m;p&&(this.urlOverlay.style.display="none",this.urlSpinner.style.display="none",this.urlProblem.style.display="none"),f&&!Array.isArray(f)&&(this.editor.setMarkers([f]),(v=this.problemBag)==null||v.set(bP,[f]),this.problemList.problems=[f],this.problems=[f],this.problemsOverview.problems=this.problemList.problemItems),f&&Array.isArray(f)&&(this.editor.setMarkers(f),(m=this.problemBag)==null||m.set(bP,f),this.problemList.problems=f,this.problems=f,this.problemsOverview.problems=this.problemList.problemItems),S4.createGraph().then(E=>{this.extractGraph(E)}),p2.fetchStatistics().then(E=>{var q;let C=0;if(this.problemsOverview.statistics&&(C=this.problemsOverview.statistics.statistics.overallScore),(q=this.diagnosticBag)==null||q.set(CV,E),this.activitySpinner.hide(),(E==null?void 0:E.remainingCredit)<=10&&(this.statusBar.callsRemaining=E.remainingCredit,this.statusBar.visible=!0,console.warn("You are running low on credit, you will need to authenticate soon. "+E.remainingCredit+" credits remaining.")),this.problemsOverview.statistics=E,this.problemsOverview.statistics){const Y=E.statistics.overallScore;C>Y&&this.sendToast({id:crypto.randomUUID(),type:Fl.SCOREDOWN,body:"Your score has decreased. It is now "+Y+"%",title:"Score went down by "+(C-Y)+"%"}),C<Y&&this.sendToast({id:crypto.randomUUID(),type:Fl.SCOREUP,body:"Your score has increased to "+Y+"%",title:"Score went up by "+(Y-C)+"%"})}}).catch(E=>{console.error("statistics service is down",E),this.platformUnavailable(E)})}).catch(f=>{p?this.showUrlError(f):(this.platformUnavailable(f),console.error("so sorry, the doctor cannot see you right now, the clinic is closed."),f&&(console.error(f.detail),f.instance==="https://pb33f.io/errors/no-credit-remaining"&&(this.statusBar.callsRemaining=0,this.statusBar.visible=!0,this.sendToast({id:crypto.randomUUID(),type:Fl.ERROR,body:"Run out of credit, please authenticate for more or wait 24 hours.",title:"Credit exhausted!"}))))})}platformUnavailable(g){this.unavailable||(this.loadingOverlay.hide(),this.activitySpinner.hide(),this.errorBanner.errorTitle="The doctor is out.",g?this.errorBanner.errorMessage="The clinic is <strong>closed!</strong> The doctor is currently unavailable because "+g.detail:this.errorBanner.errorMessage="The clinic is <strong>closed!</strong> The doctor is currently unavailable because there is no response from the platform.",this.errorBanner.visible=!0,this.unavailable=!0,this.problemsOverview.unavailable=!0,this.controlTabGroup.show(Oa.Overview))}specClicked(g){var p,f,v;if(this.detailsDrawer.close(),this.selectedEditorTab=="spec"){let m=!1;for(let C=0;C<((p=this.problems)==null?void 0:p.length);C++)if(this.problems[C].startLineNumber===g.detail.line){this.problemList.lineClicked(g.detail.line,!0),this.controlTabGroup.show(Oa.Problems),this.sidebarClosed&&this.toggleSidebar(),m=!0;break}const E=(f=this.graphBag)==null?void 0:f.get(pP);if(E&&E.graphMap&&g.detail.line){const C=E.graphMap[g.detail.line];if(C){this.modelTree.explorerClicked(C);const q=this.renderedNodeMap.get(C);q&&(this.renderedNode.node=q),m||this.viewerPanel.click();const Y=this.nodeIdHashMap.get(C);Y&&(this.explorer.activeNode=Y,this.explorer.equalizer.activeNode=Y)}}}if(this.selectedEditorTab==Oa.Ruleset){const m=(v=this.sessionRulesetMapBag)==null?void 0:v.get(gP);if(m!=null&&m.rulesMap){for(let E=0;E<m.rulesMap.length;E++)if(m.rulesMap[E].line===g.detail.line){this.controlTabGroup.show(Oa.Ruleset),this.sidebarClosed&&this.toggleSidebar();break}}}}problemClicked(g){var p,f;this.selectedEditorTab!="spec"&&(this.editorTabGroup.show("spec"),this.selectedEditorTab="spec"),this.controlTabGroup.show(Oa.Problems),(p=this.editor.editor)==null||p.revealLineInCenter(g.detail.problem.line),(f=this.editor.editor)==null||f.setPosition({lineNumber:g.detail.problem.line,column:g.detail.problem.column}),this.detailsDrawer.close(),g.detail.launchedFromProblems||this.problemList.lineClicked(g.detail.problem.problemObject.startLineNumber)}loadState(){if(p2.doctorEndpoint=this.doctorEndpoint,yT.doctorEndpoint=this.doctorEndpoint,jh.doctorEndpoint=this.doctorEndpoint,S4.doctorEndpoint=this.doctorEndpoint,this.connectToBroker(),this.graphBag=this.bagManager.getBag(pP),this.docBag=this.bagManager.getBag(U2t),this.docBag){const p=this.docBag.get(PI);p&&this.editor.setValue(p,!0)}if(this.problemBag=this.bagManager.getBag(bP),this.problemBag){const p=this.problemBag.get(bP);if(p){this.problems=p,this.editor.setMarkers(p);for(let f=0;f<p.length;f++)p[f]=rm.reconstruct(p[f]);this.problemList.problems=p,this.problemsOverview.problems=this.problemList.problemItems}}if(this.howToFixBag=this.bagManager.getBag(z2t),this.diagnosticBag=this.bagManager.getBag(CV),this.diagnosticBag){const p=this.diagnosticBag.get(CV);p&&(this.problemsOverview.statistics=p)}if(this.graphBag){const p=this.graphBag.get(pP);p&&this.extractGraph(p)}const g=[];if(this.DefaultRulesetBag=this.bagManager.getBag(MV),this.DefaultRulesetBag){const p=this.DefaultRulesetBag.get(MV);p?this.defaultRuleset=p:g.push(this.fetchDefaultRuleset())}if(this.OWASPRulesetBag=this.bagManager.getBag(IV),this.OWASPRulesetBag){const p=this.OWASPRulesetBag.get(IV);p?this.OWASPRuleset=p:g.push(this.fetchOWASPRuleset())}if(this.AllRulesetBag=this.bagManager.getBag(DV),this.AllRulesetBag){const p=this.AllRulesetBag.get(DV);p?this.AllRuleset=p:g.push(this.fetchAllRuleset())}if(this.FunctionsBag=this.bagManager.getBag(FI),this.FunctionSchemaBag=this.bagManager.getBag(OI),this.FunctionsBag){const p=this.FunctionsBag.get(FI);p?this.functions=p:g.push(this.fetchFunctions())}if(this.CustomRulesetBag=this.bagManager.getBag(TI),this.CustomRulesetBag){const p=this.CustomRulesetBag.get(TI);p&&(this.CustomRuleset=p)}this.RuleConfigBag=this.bagManager.getBag(dC),this.sessionRulesetMapBag=this.bagManager.getBag(gP),Promise.all(g).then(()=>{var f;this.manageRuleset.defaultRuleset=this.defaultRuleset,this.manageRuleset.owaspRuleset=this.OWASPRuleset,this.manageRuleset.allRuleset=this.AllRuleset,this.manageRuleset.functions=this.functions;const p=(f=this.RuleConfigBag)==null?void 0:f.get(dC);p?this.manageRuleset.rulesetConfig=p:this.manageRuleset.rulesetConfig={ruleMapping:new Map,allRulesSwitch:!0},setTimeout(()=>{this.manageRuleset.buildRulesets(),this.CustomRuleset&&this.CustomRuleset.rules.size>0&&(this.manageRuleset.customRuleset=this.CustomRuleset),this.fetchSessionRulesetAsYaml().then(v=>{var m;(m=this.rulesetEditor)==null||m.setValue(v,!0),this.fetchRulesetMap()}).catch(v=>{this.platformUnavailable(v)})},50)}),this.fetchDocs()}extractGraph(g){var f;g.stripped?(this.explorer.nodeLimitExceeded=!0,this.modelTree.nodeLimitExceeded=!0,g.strippedCount&&(this.explorer.nodeLimit=g.strippedCount,this.modelTree.nodeLimit=g.strippedCount)):(this.explorer.nodeLimitExceeded=!1,this.modelTree.nodeLimitExceeded=!1),this.explorer.renderedNodeMap.clear(),this.nodeMap.clear(),this.nodeIdMap.clear(),this.nodeIdHashMap.clear();const p=new Map;g.nodesRendered.forEach(v=>{this.explorer.renderedNodeMap.set(v.id,v),p.set(v.idHash,v)});for(let v=0;v<g.nodesRendered.length;v++)this.renderedNodeMap.set(g.nodesRendered[v].idHash,g.nodesRendered[v]);g.nodes.forEach(v=>{var E;this.nodeMap.set("model-"+v.idHash,v),this.nodeIdMap.set(v.id,v),this.nodeIdHashMap.set(v.idHash,v),v.filtered&&this.filteredNodes.set(v.idHash,v);const m=this.renderedNodeMap.get(v.idHash);((E=this.activeNode)==null?void 0:E.id)===v.id&&this.renderedNodeMap.get(v.idHash)&&this.renderedNode&&m&&(this.renderedNode.node=m)}),(f=this.graphBag)==null||f.set(pP,g),this.explorer.updateGraphResponse(g),this.modelTree.node=g.nodes[0],this.explorer.equalizer.runEQ()}customRulesetEnabled(g){var f,v,m;const p={rules:new Map};p.id=crypto.randomUUID(),p.owner=this.session.sessionId,g.detail.rules.forEach(E=>{E.rule.id!=E.ruleId&&(E.rule.id=E.ruleId),p.rules.set(E.ruleId,E.rule)}),(f=this.CustomRulesetBag)==null||f.set(TI,p),g.detail.ruleConfig?(v=this.RuleConfigBag)==null||v.set(dC,g.detail.ruleConfig):((m=this.RuleConfigBag)==null||m.reset(),jh.resetSessionRuleset(g.detail.rulesetReset).then(()=>{if(this.sendToast({id:crypto.randomUUID(),type:Fl.INFO,body:"Ruleset has been reset to the default",title:"Ruleset reset"}),this.docBag){const E=this.docBag.get(PI);this.lintSpec(E)}this.fetchSessionRulesetAsYaml().then(E=>{var C;(C=this.rulesetEditor)==null||C.setValue(E,!0)})}).catch(E=>{this.sendToast({id:crypto.randomUUID(),type:Fl.ERROR,body:E.detail,title:"Cannot reset ruleset"})}))}async fetchSessionRulesetAsYaml(){return new Promise(async(g,p)=>{jh.getSessionRulesetAsYAML().then(f=>{g(f)}).catch(f=>{console.error("cannot fetch session ruleset: ",f.title),p(f)})})}async fetchFunctions(){return new Promise(async g=>{jh.getFunctions().then(p=>{var v;this.functions=p,(v=this.FunctionsBag)==null||v.set(FI,p);const f=[];p.forEach(m=>{f.push(this.fetchFunctionSchema(m))}),Promise.all(f).then(()=>{g(p)})})})}async fetchFunctionSchema(g){return new Promise(async p=>{jh.getFunctionSchema(g).then(f=>{var m,E;let v=(m=this.FunctionSchemaBag)==null?void 0:m.get(OI);v||(v=new Map),v.set(g,f),(E=this.FunctionSchemaBag)==null||E.set(OI,v),p(f)})})}async fetchDefaultRuleset(){return new Promise(async g=>{jh.getDefaultRuleset().then(p=>{var f;this.defaultRuleset=p,(f=this.DefaultRulesetBag)==null||f.set(MV,p),g(p)})})}async fetchOWASPRuleset(){return new Promise(async g=>{jh.getOWASPRuleset().then(p=>{var f;this.OWASPRuleset=p,(f=this.OWASPRulesetBag)==null||f.set(IV,p),g(p)})})}async fetchAllRuleset(){return new Promise(async g=>{jh.getAllRuleset().then(p=>{var f;this.AllRuleset=p,(f=this.AllRulesetBag)==null||f.set(DV,p),g(p)})})}fetchDocs(){this.activitySpinner.show(),p2.startSession().then(g=>{this.session=g,p2.fetchAllHowToFix().then(p=>{p&&p.forEach(f=>{var v;(v=this.howToFixBag)==null||v.set(f.ruleId,f)})}).catch(p=>{this.platformUnavailable(p),console.error("documentation service is down")}),this.ruleDocsBag=this.bagManager.getBag(G2t),this.functionDocsBag=this.bagManager.getBag(H2t),this.ruleDocsWorker.addEventListener("message",p=>{const f=p.data;f&&(f.forEach(v=>{var m,E;v.ruleId&&((m=this.ruleDocsBag)==null||m.set(v.ruleId,v)),v.functionId&&((E=this.functionDocsBag)==null||E.set(v.functionId,v))}),this.activitySpinner.hide())}),this.ruleDocsWorker.postMessage({start:!0,endpoint:this.doctorEndpoint})}).catch(g=>{this.platformUnavailable(g),console.error("cannot start session")})}fetchRulesetMap(){jh.getSessionRulesetMap().then(g=>{var p;(p=this.sessionRulesetMapBag)==null||p.set(gP,g)}).catch(()=>{console.warn("map is empty, or unavailable, Did you submit an empty ruleset?"),this.sendToast({id:crypto.randomUUID(),type:Fl.WARNING,body:"map is empty, or unavailable, Did you submit an empty ruleset?",title:"Issue fetching ruleset map"})})}ruleClicked(g){var f,v,m;const p=(f=this.sessionRulesetMapBag)==null?void 0:f.get(gP);if(p){const E=p.rulesMap.find(C=>C.ruleId===g.detail.ruleId);E&&(this.selectedEditorTab="ruleset",this.editorTabGroup.show(Oa.Ruleset),(v=this.rulesetEditor.editor)==null||v.setPosition({lineNumber:E.line,column:E.start}),(m=this.rulesetEditor.editor)==null||m.revealLineInCenter(E.line))}}builtInRulesetSelected(){}rulesetManuallyChanged(){clearTimeout(this.bounceId),this.bounceId=window.setTimeout(()=>{var p;const g=(p=this.rulesetEditor.editor)==null?void 0:p.getValue();jh.validateRuleset(g).then(f=>{var m;this.manageRuleset.clearRuleProblems();let v={rules:new Map};v.id=crypto.randomUUID(),v.owner=this.session.sessionId,v.rules=new Map(Object.entries(f.rules)),v.rules.forEach((E,C)=>{E.id=C}),(m=this.CustomRulesetBag)==null||m.set(TI,v),this.CustomRuleset=v,v.rules.size>0&&(this.manageRuleset.customRulesetManual=v),this.selectedEditorTab=Oa.Ruleset,this.controlTabGroup.show(Oa.Ruleset),this.rulesetEditor.setMarkers([]),this.fetchRulesetMap()}).catch(f=>{this.sendToast({id:crypto.randomUUID(),type:Fl.ERROR,body:f.detail,title:f.title}),console.error("unable to validate ruleset",f);const v=f.body,m=[];v==null||v.forEach(E=>{m.push({severity:u2.MarkerSeverity.Error,message:E.ruleError,startLineNumber:E.line,startColumn:E.startCol,endLineNumber:E.line,endColumn:E.endCol})}),jh.convertToJSON(g).then(E=>{let C={rules:new Map};C.id=crypto.randomUUID(),C.owner=this.session.sessionId,C.rules=new Map(Object.entries(E.rules)),C.rules.forEach((q,Y)=>{q.id!=Y&&(q.id=Y)}),this.CustomRuleset=C,C.rules.size>0&&(this.manageRuleset.customRulesetManual=C),this.rulesetEditor.setMarkers([]),this.manageRuleset.clearRuleProblems(),this.rulesetEditor.setMarkers(m),this.manageRuleset.processBadRules(v),this.controlTabGroup.show(Oa.Ruleset)}).catch(E=>{console.error("unable to convert ruleset to JSON",E)})})},this.debounceTimeRuleset)}specChanged(g){if(this.editorMap.get(g.detail.id)&&g.detail.id==="ruleset"){this.rulesetManuallyChanged();return}this.docBag&&this.docBag.set(PI,g.detail.content),clearTimeout(this.bounceId),this.bounceId=window.setTimeout(()=>{this.lintSpec(g.detail.content)},this.debounceTime)}boostrap(){const p=new URL(window.location.href).searchParams.get("url");if(p){this.urlInput.value=p,this.lintSpec("",p);return}this.editor.getValue()===""&&p2.bootstrapEditor().then(f=>{this.editor.setValue(f,!0),this.specChanged(new CustomEvent(zq,{detail:{content:f,id:"spec"}}))})}exportJSON(){let g;if(this.RuleConfigBag){const p=this.RuleConfigBag.get(dC);p&&p.returnedRuleset&&(g=p.returnedRuleset)}if(g){let p="data:text/json;charset=utf-8,"+encodeURIComponent(JSON.stringify(g,null,2));this.downloadRulesetLink.download="ruleset.json",this.downloadRulesetLink.href=p,this.downloadRulesetLink.click(),this.exportRulesetDialog.hide()}}exportYAML(){jh.getSessionRulesetAsYAML().then(g=>{let p="data:text/yaml;charset=utf-8,"+encodeURIComponent(g);this.downloadRulesetLink.download="ruleset.yaml",this.downloadRulesetLink.href=p,this.downloadRulesetLink.click(),this.exportRulesetDialog.hide()})}confirmExport(){switch(this.exportSelection.value){case"json":this.exportJSON();break;case"yaml":this.exportYAML();break}}closeWelcome(){this.welcomeBox.hide(),localStorage.setItem("pb33f-doctor-welcome","closed")}selectEditorTab(g){switch(this.selectedEditorTab=g.detail.name,g.detail.name){case Oa.Ruleset:this.rulesetPulse&&(this.rulesetPulse=!1),this.controlTabGroup.show(Oa.Ruleset);break}}selectControlTab(g){switch(g.detail.name){case Oa.Problems:case Oa.Overview:this.selectedEditorTab!="spec"&&(this.selectedEditorTab="spec",this.editorTabGroup.show("spec"));break;case Oa.Ruleset:this.selectedEditorTab!=Oa.Ruleset&&(this.editorTabGroup.show(Oa.Ruleset),this.selectedEditorTab=Oa.Ruleset);break}}toggleSidebar(){var p;const g=(p=this.shadowRoot)==null?void 0:p.querySelector("sl-split-panel.split-panel");this.sidebarClosed?g&&(this.collapseButton.name="chevron-bar-right",g.style.setProperty("--min","600px"),g.style.setProperty("--max","calc(100vw - 600px)"),g.position=60,g.disabled=!1,this.problemsDataDiv.style.display="block",this.splitDivider.style.display="block",this.activitySpinner.classList.remove("spinner-draw-closed")):g&&(this.collapseButton.name="chevron-bar-left",this.problemsDataDiv.style.display="none",g.style.setProperty("--min","40px"),g.style.setProperty("--max","calc(100vw - 40px)"),g.position=99,g.disabled=!0,this.splitDivider.style.display="none",this.activitySpinner.classList.add("spinner-draw-closed")),this.sidebarClosed=!this.sidebarClosed}toggleExplorer(){this.explorerVisible=!0,this.explorerVisible&&this.explorer.moveToNode(this.activeNode),this.explorerBooted||(this.explorer.equalizer.initializeEqualizer(),this.explorerBooted=!0)}closeExplorer(){this.explorerVisible=!1}render(){let g=B.html``;this.unavailable&&(g=B.html`
9286
9286
  <div class="overlay" @click="return false"></div>`);let p=B.html`
9287
9287
  <pb33f-attention-box id="welcome" type="success"
9288
9288
  headerText="Welcome to the clinic, I am the OpenAPI doctor." closeable>
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Princess Beef Heavy Industries Cowboy Components",
4
4
  "private": false,
5
5
  "license": "BUSL-1.1",
6
- "version": "0.3.4",
6
+ "version": "0.3.5",
7
7
  "type": "module",
8
8
  "main": "./dist/cowboy-components.umd.cjs",
9
9
  "module": "./dist/cowboy-components.js",