(this.webpackJsonpclient=this.webpackJsonpclient||[]).push([[0],{48:function(e,t,n){},53:function(e,t,n){"use strict";n.r(t);var s=n(0),r=n.n(s),a=n(18),c=n.n(a),o=(n(47),n(15)),i=n(16),l=n(21),d=n(20),h=n(41),u=n(7),j=n(9),b=(n(48),n(19)),f=n(13),p=n(10),O=n(34),v=n(24),w=n(1),x=function(e){Object(l.a)(n,e);var t=Object(d.a)(n);function n(e){var s;return Object(o.a)(this,n),(s=t.call(this,e)).state={show:!1,rule:{method:"ALL",url:"",action:"1"},haveRules:!1},s.handleClose=s.handleClose.bind(Object(f.a)(s)),s.handleShow=s.handleShow.bind(Object(f.a)(s)),s.handleSave=s.handleSave.bind(Object(f.a)(s)),s}return Object(i.a)(n,[{key:"handleClose",value:function(){this.setState({show:!1})}},{key:"handleShow",value:function(){this.setState({show:!0})}},{key:"handleSave",value:function(){var e=this.state.rule,t=[];e.url&&t.push({method:"ALL"===e.method?"":e.method,url:e.url,action:parseInt(e.action)}),this.props.onSave(t),this.handleClose(),this.setState({haveRules:!!t.length})}},{key:"render",value:function(){var e=this,t=this.state,n=t.rule,s=t.haveRules?"success":"primary";return Object(w.jsxs)("div",{children:[Object(w.jsx)(j.a,{variant:s,size:"sm",onClick:this.handleShow,children:"BreakPoint"}),Object(w.jsxs)(p.a,{show:this.state.show,onHide:this.handleClose,children:[Object(w.jsx)(p.a.Header,{closeButton:!0,children:Object(w.jsx)(p.a.Title,{children:"Set BreakPoint"})}),Object(w.jsxs)(p.a.Body,{children:[Object(w.jsxs)(u.a.Group,{as:O.a,children:[Object(w.jsx)(u.a.Label,{column:!0,sm:2,children:"Method"}),Object(w.jsx)(v.a,{sm:10,children:Object(w.jsxs)(u.a.Control,{as:"select",value:n.method,onChange:function(t){e.setState({rule:Object(b.a)(Object(b.a)({},n),{},{method:t.target.value})})},children:[Object(w.jsx)("option",{children:"ALL"}),Object(w.jsx)("option",{children:"GET"}),Object(w.jsx)("option",{children:"POST"}),Object(w.jsx)("option",{children:"PUT"}),Object(w.jsx)("option",{children:"DELETE"})]})})]}),Object(w.jsxs)(u.a.Group,{as:O.a,children:[Object(w.jsx)(u.a.Label,{column:!0,sm:2,children:"URL"}),Object(w.jsx)(v.a,{sm:10,children:Object(w.jsx)(u.a.Control,{value:n.url,onChange:function(t){e.setState({rule:Object(b.a)(Object(b.a)({},n),{},{url:t.target.value})})}})})]}),Object(w.jsxs)(u.a.Group,{as:O.a,children:[Object(w.jsx)(u.a.Label,{column:!0,sm:2,children:"Action"}),Object(w.jsx)(v.a,{sm:10,children:Object(w.jsxs)(u.a.Control,{as:"select",value:n.action,onChange:function(t){e.setState({rule:Object(b.a)(Object(b.a)({},n),{},{action:t.target.value})})},children:[Object(w.jsx)("option",{value:"1",children:"Request"}),Object(w.jsx)("option",{value:"2",children:"Response"}),Object(w.jsx)("option",{value:"3",children:"Both"})]})})]})]}),Object(w.jsxs)(p.a.Footer,{children:[Object(w.jsx)(j.a,{variant:"secondary",onClick:this.handleClose,children:"Close"}),Object(w.jsx)(j.a,{variant:"primary",onClick:this.handleSave,children:"Save"})]})]})]})}}]),n}(r.a.Component),y=n(39),m=n(26),g=n(42),C=n(40),S={request:1,requestBody:2,response:3,responseBody:4},k=Object.keys(S).map((function(e){return S[e]})),T=Object.keys(S).reduce((function(e,t){return e[S[t]]=t,e}),{}),L=11,q=12,N=13,R=14,M=21,B=function(e,t){if(e===N||e===R){var n=new Uint8Array(38);return n[0]=1,n[1]=e,n.set((new TextEncoder).encode(t.id),2),n}var s,r;if(e===L){var a=t.request;r=a.body,s=Object(C.a)(a,["body"])}else{if(e!==q)throw new Error("invalid message type");var c=t.response;r=c.body,s=Object(C.a)(c,["body"])}var o=r&&r.byteLength?r.byteLength:0,i=(new TextEncoder).encode(JSON.stringify(s)),l=42+i.byteLength+4+o,d=new ArrayBuffer(l),h=new Uint8Array(d);h[0]=1,h[1]=e,h.set((new TextEncoder).encode(t.id),2),h.set(i,42),o&&h.set(r,42+i.byteLength+4);var u=new DataView(d);return u.setUint32(38,i.byteLength),u.setUint32(42+i.byteLength,o),h},E=function(e){return!!e&&(!!e.header&&(!!e.header["Content-Type"]&&/text|javascript|json/.test(e.header["Content-Type"].join(""))))},I=function(e){return e&&e.header?(e.header["Content-Length"]?t=parseInt(e.header["Content-Length"][0]):e&&e.body&&(t=e.body.byteLength),t?isNaN(t)||t<=0?"0":t<1024?"".concat(t," B"):t<1048576?"".concat((t/1024).toFixed(2)," KB"):"".concat((t/1048576).toFixed(2)," MB"):"0"):"0";var t},F=function(e){Object(l.a)(n,e);var t=Object(d.a)(n);function n(e){var s;return Object(o.a)(this,n),(s=t.call(this,e)).state={show:!1,alertMsg:"",content:""},s.handleClose=s.handleClose.bind(Object(f.a)(s)),s.handleShow=s.handleShow.bind(Object(f.a)(s)),s.handleSave=s.handleSave.bind(Object(f.a)(s)),s}return Object(i.a)(n,[{key:"showAlert",value:function(e){this.setState({alertMsg:e})}},{key:"handleClose",value:function(){this.setState({show:!1})}},{key:"handleShow",value:function(){var e=this.props.flow,t="";t="request"===(e.response?"response":"request")?function(e){var t="".concat(e.method," ").concat(e.url),n=Object.keys(e.header).map((function(t){var n=e.header[t].join(" \t ");return"".concat(t,": ").concat(n)})).join("\n"),s="";return e.body&&E(e)&&(s=(new TextDecoder).decode(e.body)),"".concat(t,"\n\n").concat(n,"\n\n").concat(s)}(e.request):function(e){var t="".concat(e.statusCode),n=Object.keys(e.header).map((function(t){var n=e.header[t].join(" \t ");return"".concat(t,": ").concat(n)})).join("\n"),s="";return e.body&&E(e)&&(s=(new TextDecoder).decode(e.body)),"".concat(t,"\n\n").concat(n,"\n\n").concat(s)}(e.response),this.setState({show:!0,alertMsg:"",content:t})}},{key:"handleSave",value:function(){var e=this.props.flow.response?"response":"request",t=this.state.content;if("request"===e){var n=function(e){var t=e.split("\n\n");if(3===t.length){var n=Object(m.a)(t,3),s=n[0],r=n[1],a=n[2],c=s.split(" "),o=Object(m.a)(c,2),i=o[0],l=o[1];if(i&&l){var d,h={},u=Object(y.a)(r.split("\n"));try{for(u.s();!(d=u.n()).done;){var j=d.value.split(": "),b=Object(m.a)(j,2),f=b[0],p=b[1];if(!f||!p)return;h[f]=p.split(" \t ")}}catch(v){u.e(v)}finally{u.f()}var O=null;return a&&(O=(new TextEncoder).encode(a)),{method:i,url:l,header:h,body:O}}}}(t);if(!n)return void this.showAlert("parse error");this.props.onChangeRequest(n),this.handleClose()}else{var s=function(e){var t=e.split("\n\n");if(3===t.length){var n=Object(m.a)(t,3),s=n[0],r=n[1],a=n[2],c=parseInt(s);if(!isNaN(c)){var o,i={},l=Object(y.a)(r.split("\n"));try{for(l.s();!(o=l.n()).done;){var d=o.value.split(": "),h=Object(m.a)(d,2),u=h[0],j=h[1];if(!u||!j)return;i[u]=j.split(" \t ")}}catch(f){l.e(f)}finally{l.f()}var b=null;return a&&(b=(new TextEncoder).encode(a)),{statusCode:c,header:i,body:b}}}}(t);if(!s)return void this.showAlert("parse error");this.props.onChangeResponse(s),this.handleClose()}}},{key:"render",value:function(){var e=this,t=this.props.flow;if(!t.waitIntercept)return null;var n=this.state.alertMsg,s=t.response?"response":"request";return Object(w.jsxs)("div",{className:"flow-wait-area",children:[Object(w.jsx)(j.a,{size:"sm",onClick:this.handleShow,children:"Edit"}),Object(w.jsx)(j.a,{size:"sm",onClick:function(){var n=B("response"===s?q:L,t);e.props.onMessage(n)},children:"Continue"}),Object(w.jsx)(j.a,{size:"sm",onClick:function(){var n=B("response"===s?R:N,t);e.props.onMessage(n)},children:"Drop"}),Object(w.jsxs)(p.a,{size:"lg",show:this.state.show,onHide:this.handleClose,children:[Object(w.jsx)(p.a.Header,{closeButton:!0,children:Object(w.jsxs)(p.a.Title,{children:["Edit ","request"===s?"Request":"Response"]})}),Object(w.jsxs)(p.a.Body,{children:[Object(w.jsx)(u.a.Group,{children:Object(w.jsx)(u.a.Control,{as:"textarea",rows:10,value:this.state.content,onChange:function(t){e.setState({content:t.target.value})}})}),n?Object(w.jsx)(g.a,{variant:"danger",children:n}):null]}),Object(w.jsxs)(p.a.Footer,{children:[Object(w.jsx)(j.a,{variant:"secondary",onClick:this.handleClose,children:"Close"}),Object(w.jsx)(j.a,{variant:"primary",onClick:this.handleSave,children:"Save"})]})]})]})}}]),n}(r.a.Component),A=function(){function e(){Object(o.a)(this,e),this.items=[],this._map=new Map,this.filterText="",this.filterTimer=null,this.num=0,this.max=1e3}return Object(i.a)(e,[{key:"showList",value:function(){var e=this;return this.filterText?this.items.filter((function(t){return t.request.url.includes(e.filterText)})):this.items}},{key:"add",value:function(e){if(e.no=++this.num,this.items.push(e),this._map.set(e.id,e),this.items.length>this.max){var t=this.items.shift();this._map.delete(t.id)}}},{key:"get",value:function(e){return this._map.get(e)}},{key:"changeFilter",value:function(e){this.filterText=e}},{key:"changeFilterLazy",value:function(e,t){var n=this;this.filterTimer&&(clearTimeout(this.filterTimer),this.filterTimer=null),this.filterTimer=setTimeout((function(){n.filterText=e,t()}),300)}},{key:"clear",value:function(){this.items=[],this._map=new Map}}]),e}(),H=function(e){Object(l.a)(n,e);var t=Object(d.a)(n);function n(e){var s;return Object(o.a)(this,n),(s=t.call(this,e)).flowMgr=new A,s.state={flows:s.flowMgr.showList(),flow:null,flowTab:"Headers"},s.ws=null,s}return Object(i.a)(n,[{key:"componentDidMount",value:function(){this.initWs()}},{key:"componentWillUnmount",value:function(){this.ws&&this.ws.close()}},{key:"initWs",value:function(){var e,t=this;this.ws||(e=new URL(document.URL).host,this.ws=new WebSocket("ws://".concat(e,"/echo")),this.ws.binaryType="arraybuffer",this.ws.onopen=function(){console.log("OPEN")},this.ws.onclose=function(){console.log("CLOSE")},this.ws.onmessage=function(e){var n=function(e){if(e.byteLength<39)return null;var t=new Int8Array(e.slice(0,39));if(1!==t[0])return null;var n=t[1];if(!k.includes(n))return null;var s=(new TextDecoder).decode(e.slice(2,38)),r=1===t[38],a={type:T[n],id:s,waitIntercept:r};if(39===e.byteLength)return a;if(n===S.requestBody||n===S.responseBody)return a.content=e.slice(39),a;var c=(new TextDecoder).decode(e.slice(39));try{c=JSON.parse(c)}catch(o){return null}return a.content=c,a}(e.data);if(n){if("request"===n.type){var s={id:n.id,request:n.content,waitIntercept:n.waitIntercept};t.flowMgr.add(s),t.setState({flows:t.flowMgr.showList()})}else if("requestBody"===n.type){var r=t.flowMgr.get(n.id);if(!r)return;r.waitIntercept=n.waitIntercept,r.request.body=n.content,t.setState({flows:t.state.flows})}else if("response"===n.type){var a=t.flowMgr.get(n.id);if(!a)return;a.waitIntercept=n.waitIntercept,a.response=n.content,t.setState({flows:t.state.flows})}else if("responseBody"===n.type){var c=t.flowMgr.get(n.id);if(!c||!c.response)return;c.waitIntercept=n.waitIntercept,c.response.body=n.content,t.setState({flows:t.state.flows})}}else console.error("parse error:",e.data)},this.ws.onerror=function(e){console.log("ERROR:",e)})}},{key:"renderFlow",value:function(){var e=this,t=this.state,n=t.flow,s=t.flowTab;if(!n)return null;var r=n.request,a=n.response||{};return Object(w.jsxs)("div",{className:"flow-detail",children:[Object(w.jsxs)("div",{className:"header-tabs",children:[Object(w.jsx)("span",{onClick:function(){e.setState({flow:null})},children:"x"}),Object(w.jsx)("span",{className:"Headers"===s?"selected":null,onClick:function(){e.setState({flowTab:"Headers"})},children:"Headers"}),Object(w.jsx)("span",{className:"Preview"===s?"selected":null,onClick:function(){e.setState({flowTab:"Preview"})},children:"Preview"}),Object(w.jsx)("span",{className:"Response"===s?"selected":null,onClick:function(){e.setState({flowTab:"Response"})},children:"Response"}),Object(w.jsx)(F,{flow:n,onChangeRequest:function(t){n.request.method=t.method,n.request.url=t.url,n.request.header=t.header,E(n.request)&&(n.request.body=t.body),e.setState({flows:e.state.flows})},onChangeResponse:function(t){n.response.statusCode=t.statusCode,n.response.header=t.header,E(n.response)&&(n.response.body=t.body),e.setState({flows:e.state.flows})},onMessage:function(t){e.ws.send(t),n.waitIntercept=!1,e.setState({flows:e.state.flows})}})]}),Object(w.jsxs)("div",{style:{padding:"20px"},children:["Headers"!==s?null:Object(w.jsxs)("div",{children:[Object(w.jsxs)("div",{className:"header-block",children:[Object(w.jsx)("p",{children:"General"}),Object(w.jsxs)("div",{className:"header-block-content",children:[Object(w.jsxs)("p",{children:["Request URL: ",r.url]}),Object(w.jsxs)("p",{children:["Request Method: ",r.method]}),Object(w.jsxs)("p",{children:["Status Code: ","".concat(a.statusCode||"(pending)")]})]})]}),a.header?Object(w.jsxs)("div",{className:"header-block",children:[Object(w.jsx)("p",{children:"Response Headers"}),Object(w.jsx)("div",{className:"header-block-content",children:Object.keys(a.header).map((function(e){return Object(w.jsxs)("p",{children:[e,": ",a.header[e].join(" ")]},e)}))})]}):null,Object(w.jsxs)("div",{className:"header-block",children:[Object(w.jsx)("p",{children:"Request Headers"}),Object(w.jsx)("div",{className:"header-block-content",children:r.header?Object.keys(r.header).map((function(e){return Object(w.jsxs)("p",{children:[e,": ",r.header[e].join(" ")]},e)})):null})]}),r.body&&r.body.byteLength?Object(w.jsxs)("div",{className:"header-block",children:[Object(w.jsx)("p",{children:"Request Body"}),Object(w.jsx)("div",{className:"header-block-content",children:Object(w.jsx)("p",{children:E(r)?(new TextDecoder).decode(r.body):"Not text"})})]}):null]}),"Response"!==s?null:a.body&&a.body.byteLength?E(a)?Object(w.jsx)("div",{children:(new TextDecoder).decode(a.body)}):Object(w.jsx)("div",{children:"Not text response"}):Object(w.jsx)("div",{children:"No response"})]})]})}},{key:"render",value:function(){var e=this,t=this.state.flows;return Object(w.jsxs)("div",{className:"main-table-wrap",children:[Object(w.jsxs)("div",{className:"top-control",children:[Object(w.jsx)("div",{children:Object(w.jsx)(j.a,{size:"sm",onClick:function(){e.flowMgr.clear(),e.setState({flows:e.flowMgr.showList(),flow:null})},children:"Clear"})}),Object(w.jsx)("div",{children:Object(w.jsx)(u.a.Control,{size:"sm",placeholder:"Filter",onChange:function(t){var n=t.target.value;e.flowMgr.changeFilterLazy(n,(function(){e.setState({flows:e.flowMgr.showList()})}))}})}),Object(w.jsx)(x,{onSave:function(t){var n=function(e,t){if(e!==M)throw new Error("invalid message type");var n=(new TextEncoder).encode(JSON.stringify(t)),s=new Uint8Array(2+n.byteLength);return s[0]=1,s[1]=e,s.set(n,2),s}(M,t);e.ws.send(n)}})]}),Object(w.jsxs)(h.a,{striped:!0,bordered:!0,size:"sm",children:[Object(w.jsx)("thead",{children:Object(w.jsxs)("tr",{children:[Object(w.jsx)("th",{children:"No"}),Object(w.jsx)("th",{children:"Host"}),Object(w.jsx)("th",{children:"Path"}),Object(w.jsx)("th",{children:"Method"}),Object(w.jsx)("th",{children:"Status"}),Object(w.jsx)("th",{children:"Size"})]})}),Object(w.jsx)("tbody",{children:t.map((function(t){var n=t.request.url,s=new URL(n),r=s.host;r.length>35&&(r=r.slice(0,35)+"...");var a=s.pathname+s.search;a.length>65&&(a=a.slice(0,65)+"...");var c=t.request,o=t.response||{},i=[];return e.state.flow&&e.state.flow.id===t.id&&i.push("tr-selected"),t.waitIntercept&&i.push("tr-wait-intercept"),Object(w.jsxs)("tr",{className:i.length?i.join(" "):null,onClick:function(){e.setState({flow:t})},children:[Object(w.jsx)("td",{children:t.no}),Object(w.jsx)("td",{children:r}),Object(w.jsx)("td",{children:a}),Object(w.jsx)("td",{children:c.method}),Object(w.jsx)("td",{children:o.statusCode||"(pending)"}),Object(w.jsx)("td",{children:I(o)})]},t.id)}))})]}),this.renderFlow()]})}}]),n}(r.a.Component),U=function(e){e&&e instanceof Function&&n.e(3).then(n.bind(null,55)).then((function(t){var n=t.getCLS,s=t.getFID,r=t.getFCP,a=t.getLCP,c=t.getTTFB;n(e),s(e),r(e),a(e),c(e)}))};c.a.render(Object(w.jsx)(r.a.StrictMode,{children:Object(w.jsx)(H,{})}),document.getElementById("root")),U()}},[[53,1,2]]]); //# sourceMappingURL=main.6b681f56.chunk.js.map