@mock-proxy/mock-proxy-apifox-script
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -1,5 +0,5 @@ | ||
var he=Object.create;var z=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,xe=Object.prototype.hasOwnProperty;var C=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var Ae=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let u of ce(r))!xe.call(e,u)&&u!==t&&z(e,u,{get:()=>r[u],enumerable:!(n=ve(r,u))||n.enumerable});return e};var ge=(e,r,t)=>(t=e!=null?he(ye(e)):{},Ae(r||!e||!e.__esModule?z(t,"default",{value:e,enumerable:!0}):t,e));var W=C((Ge,$)=>{typeof $=="object"&&typeof $.exports=="object"&&($.exports=M);M.defunct=function(e){throw new Error("Unexpected character at index "+(this.index-1)+": "+e)};function M(e){typeof e!="function"&&(e=M.defunct);var r=[],t=[],n=0;this.state=0,this.index=0,this.input="",this.addRule=function(i,d,c){var y=i.global;if(!y){var l="g";i.multiline&&(l+="m"),i.ignoreCase&&(l+="i"),i=new RegExp(i.source,l)}return Object.prototype.toString.call(c)!=="[object Array]"&&(c=[0]),t.push({pattern:i,global:y,action:d,start:c}),this},this.setInput=function(i){return n=0,this.state=0,this.index=0,r.length=0,this.input=i,this},this.lex=function(){if(r.length)return r.shift();for(this.reject=!0;this.index<=this.input.length;){for(var i=u.call(this).splice(n),d=this.index;i.length&&this.reject;){var c=i.shift(),y=c.result,l=c.length;this.index+=l,this.reject=!1,n++;var s=c.action.apply(this,y);if(this.reject)this.index=y.index;else if(typeof s!="undefined")switch(Object.prototype.toString.call(s)){case"[object Array]":r=s.slice(1),s=s[0];default:return l&&(n=0),s}}var A=this.input;if(d<A.length)if(this.reject){n=0;var s=e.call(this,A.charAt(this.index++));if(typeof s!="undefined")return Object.prototype.toString.call(s)==="[object Array]"?(r=s.slice(1),s[0]):s}else this.index!==d&&(n=0),this.reject=!0;else if(i.length)this.reject=!0;else break}};function u(){for(var i=[],d=0,c=this.state,y=this.index,l=this.input,s=0,A=t.length;s<A;s++){var f=t[s],g=f.start,o=g.length;if(!o||g.indexOf(c)>=0||c%2&&o===1&&!g[0]){var a=f.pattern;a.lastIndex=y;var h=a.exec(l);if(h&&h.index===y){var x=i.push({result:h,action:f.action,length:h[0].length});for(f.global&&(d=x);--x>d;){var v=x-1;if(i[x].length>i[v].length){var O=i[x];i[x]=i[v],i[v]=O}}}}}return i}}});var Z=C(()=>{String.fromCodePoint||function(){var e=function(){try{var u={},i=Object.defineProperty,d=i(u,u,u)&&i}catch(c){}return d}(),r=String.fromCharCode,t=Math.floor,n=function(u){var i=16384,d=[],c,y,l=-1,s=arguments.length;if(!s)return"";for(var A="";++l<s;){var f=Number(arguments[l]);if(!isFinite(f)||f<0||f>1114111||t(f)!=f)throw RangeError("Invalid code point: "+f);f<=65535?d.push(f):(f-=65536,c=(f>>10)+55296,y=f%1024+56320,d.push(c,y)),(l+1==s||d.length>i)&&(A+=r.apply(null,d),d.length=0)}return A};e?e(String,"fromCodePoint",{value:n,configurable:!0,writable:!0}):String.fromCodePoint=n}()});var k=C((P,H)=>{"use strict";Object.defineProperty(P,"__esModule",{value:!0});P.default=void 0;Z();var Re=/\\(u\{([0-9A-Fa-f]+)\}|u([0-9A-Fa-f]{4})|x([0-9A-Fa-f]{2})|([1-7][0-7]{0,2}|[0-7]{2,3})|(['"tbrnfv0\\]))|\\U([0-9A-Fa-f]{8})/g,me={0:"\0",b:"\b",f:"\f",n:` | ||
`,r:"\r",t:" ",v:"\v","'":"'",'"':'"',"\\":"\\"},q=function(r){return String.fromCodePoint(parseInt(r,16))},Ee=function(r){return String.fromCodePoint(parseInt(r,8))},Se=function(r){return r.replace(Re,function(t,n,u,i,d,c,y,l){return u!==void 0?q(u):i!==void 0?q(i):d!==void 0?q(d):c!==void 0?Ee(c):l!==void 0?q(l):me[y]})};P.default=Se;H.exports=P.default});var ee=C(j=>{(function(e){var r=String.fromCharCode;function t(o){for(var a=[],h=0,x=o.length,v,O;h<x;)v=o.charCodeAt(h++),v>=55296&&v<=56319&&h<x?(O=o.charCodeAt(h++),(O&64512)==56320?a.push(((v&1023)<<10)+(O&1023)+65536):(a.push(v),h--)):a.push(v);return a}function n(o){for(var a=o.length,h=-1,x,v="";++h<a;)x=o[h],x>65535&&(x-=65536,v+=r(x>>>10&1023|55296),x=56320|x&1023),v+=r(x);return v}function u(o){if(o>=55296&&o<=57343)throw Error("Lone surrogate U+"+o.toString(16).toUpperCase()+" is not a scalar value")}function i(o,a){return r(o>>a&63|128)}function d(o){if((o&4294967168)==0)return r(o);var a="";return(o&4294965248)==0?a=r(o>>6&31|192):(o&4294901760)==0?(u(o),a=r(o>>12&15|224),a+=i(o,6)):(o&4292870144)==0&&(a=r(o>>18&7|240),a+=i(o,12),a+=i(o,6)),a+=r(o&63|128),a}function c(o){for(var a=t(o),h=a.length,x=-1,v,O="";++x<h;)v=a[x],O+=d(v);return O}function y(){if(f>=A)throw Error("Invalid byte index");var o=s[f]&255;if(f++,(o&192)==128)return o&63;throw Error("Invalid continuation byte")}function l(){var o,a,h,x,v;if(f>A)throw Error("Invalid byte index");if(f==A)return!1;if(o=s[f]&255,f++,(o&128)==0)return o;if((o&224)==192){if(a=y(),v=(o&31)<<6|a,v>=128)return v;throw Error("Invalid continuation byte")}if((o&240)==224){if(a=y(),h=y(),v=(o&15)<<12|a<<6|h,v>=2048)return u(v),v;throw Error("Invalid continuation byte")}if((o&248)==240&&(a=y(),h=y(),x=y(),v=(o&7)<<18|a<<12|h<<6|x,v>=65536&&v<=1114111))return v;throw Error("Invalid UTF-8 detected")}var s,A,f;function g(o){s=t(o),A=s.length,f=0;for(var a=[],h;(h=l())!==!1;)a.push(h);return n(a)}e.version="3.0.0",e.encode=c,e.decode=g})(typeof j=="undefined"?j.utf8={}:j)});var ie=C((He,B)=>{"use strict";var be=W(),Fe=k(),Ze=ee(),re=6,Oe=7,te=11,we=12,Le=13,Ce=14,_e=-1,Xe=-2,Te=-3,Ie=-4,Ue=-5,De=[[/\s*:\s*/,_e],[/\s*,\s*/,Xe],[/\s*{\s*/,Te],[/\s*}\s*/,Le],[/\s*\[\s*/,Ie],[/\s*\]\s*/,we],[/\s*\.\s*/,Ue]];function ne(e){return e=e.replace(/\\\//,"/"),Fe(e)}function Pe(e){let r=new be,t=0,n=0;return r.addRule(/"((?:\\.|[^"])*?)($|")/,(u,i)=>(t+=u.length,{type:te,value:ne(i),row:n,col:t,single:!1})),r.addRule(/'((?:\\.|[^'])*?)($|'|(",?[ \t]*\n))/,(u,i)=>(t+=u.length,{type:te,value:ne(i),row:n,col:t,single:!0})),r.addRule(/[\-0-9]*\.[0-9]*([eE][\+\-]?)?[0-9]*(?:\s*)/,u=>(t+=u.length,{type:re,value:parseFloat(u),row:n,col:t})),r.addRule(/\-?[0-9]+([eE][\+\-]?)[0-9]*(?:\s*)/,u=>(t+=u.length,{type:re,value:parseFloat(u),row:n,col:t})),r.addRule(/\-?[0-9]+(?:\s*)/,u=>(t+=u.length,{type:Oe,value:parseInt(u),row:n,col:t})),De.forEach(u=>{r.addRule(u[0],i=>(t+=i.length,{type:u[1],value:i,row:n,col:t}))}),r.addRule(/\s/,u=>{u==` | ||
`?(t=0,n++):t+=u.length}),r.addRule(/\S[ \t]*/,u=>(t+=u.length,{type:Ce,value:u,row:n,col:t})),r.setInput(e),r}B.exports.lexString=ue;function ue(e,r){let t=Pe(e),n="";for(;n=t.lex();)r(n)}B.exports.getAllTokens=$e;function $e(e){let r=[];return ue(e,function(n){r.push(n)}),r}});var ae=C((ke,le)=>{"use strict";var qe=ie(),K=0,_=1,w=2,Q=3,N=4,V=5,je=6,pe=7,m=8,S=9,L=10,Ne=11,U=12,D=13,Ve=14,R=15,I=-1,E=-2,G=-3,X=-4;function oe(e){e.peek==null&&Object.defineProperty(e,"peek",{enumerable:!1,value:function(){return this[this.length-1]}}),e.last==null&&Object.defineProperty(e,"last",{enumerable:!1,value:function(r){return this[this.length-(1+r)]}})}function p(e,r){return e&&e.hasOwnProperty("type")&&e.type==r}le.exports.parse=Je;function Je(e,r){let t=[],n=[];oe(t),oe(n);let u=function(i){n.push(i)};qe.lexString(e,u),n[0].type==X&&n.last(0).type!=U&&n.push({type:U,value:"]",row:-1,col:-1}),n[0].type==G&&n.last(0).type!=D&&n.push({type:D,value:"}",row:-1,col:-1});for(let i=0;i<n.length;i++)for(""+n[i].type,t.push(n[i]);b(t););return t.length==1&&t[0].type==_&&(t=[{type:L,value:t[0].value}]),J(t[0],r)}function b(e){let r=e.pop();switch(r.type){case m:if(r.value.trim()=="true")return e.push({type:Q,value:"true"}),!0;if(r.value.trim()=="false")return e.push({type:Q,value:"false"}),!0;if(r.value.trim()=="null")return e.push({type:R,value:null}),!0;break;case Ve:return p(e.peek(),m)?(e.peek().value+=r.value,!0):(e.push({type:m,value:r.value}),!0);case pe:return p(r,pe)&&p(e.peek(),m)?(e.peek().value+=r.value,!0):(r.type=R,e.push(r),!0);case Ne:return r.type=R,r.value=r.value,e.push(r),!0;case Q:return r.type=R,r.value=="true"?r.value=!0:r.value=!1,e.push(r),!0;case je:return r.type=R,e.push(r),!0;case R:if(p(e.peek(),E))return r.type=V,e.pop(),e.push(r),!0;if(p(e.peek(),I))return r.type=N,e.pop(),e.push(r),!0;if(p(e.peek(),m)&&p(e.last(1),R)){let t=e.pop();return e.peek().value+='"'+t.value+'"',e.peek().value+=r.value,!0}if(p(e.peek(),m)&&p(e.last(1),w)){let t=e.pop(),n=e.peek().value.pop();return n+='"'+t.value+'"',n+=r.value,e.peek().value.push(n),!0}if(p(e.peek(),m)&&p(e.last(1),_)){let t=e.pop(),n=e.peek().value.pop(),u=r.single?"'":'"';return n.value+=u+t.value+u,n.value+=r.value,e.peek().value.push(n),!0}if(p(e.peek(),m)){let t=e.pop().value;return r.value=t+r.value,e.push(r),!0}break;case S:if(p(r,S)&&p(e.peek(),E))return r.type=V,e.pop(),e.push(r),!0;if(p(e.peek(),I))return r.type=N,e.pop(),e.push(r),!0;break;case L:if(p(e.peek(),E)){let t={type:V,value:r};return e.pop(),e.push(t),!0}if(p(e.peek(),I)){let t={type:N,value:r};return e.pop(),e.push(t),!0}if(p(e.peek(),m)){let t=e.pop();return e.push({type:K,key:t.value.trim(),value:r}),!0}break;case V:return p(e.peek(),w)?(e.peek().value.push(r.value),!0):(e.push({type:w,value:[r.value]}),!0);case w:if(p(e.peek(),R))return r.value.unshift(e.peek().value),e.pop(),e.push(r),!0;if(p(e.peek(),S))return r.value.unshift(e.peek().value),e.pop(),e.push(r),!0;if(p(e.peek(),L))return r.value.unshift(e.peek()),e.pop(),e.push(r),!0;if(p(e.peek(),m)&&(e.last(1),E)){let t=e.pop();for(e.push({type:R,value:t.value}),""+t.value;b(e););return e.push(r),!0}if(p(e.peek(),w))return e.peek().value.push(r.value[0]),!0;break;case N:if(p(e.peek(),m)||p(e.peek(),R)||p(e.peek(),w)){let t=e.pop();return e.push({type:K,key:t.value,value:r.value}),!0}throw new Error("Got a :value that can't be handled at line "+r.row+":"+r.col);case K:return p(e.last(0),E)&&p(e.last(1),_)?(e.last(1).value.push(r),e.pop(),!0):(e.push({type:_,value:[r]}),!0);case _:if(p(e.peek(),_))return r.value.forEach(function(t){e.peek().value.push(t)}),!0;break;case U:if(p(e.peek(),w)&&p(e.last(1),X)){let t=e.pop();return e.pop(),e.push({type:S,value:t.value}),!0}if(p(e.peek(),S)&&p(e.last(1),X)){let t=e.pop();return e.pop(),e.push({type:S,value:[t.value]}),!0}if(p(e.peek(),X))return e.pop(),e.push({type:S,value:[]}),!0;if(p(e.peek(),R)&&p(e.last(1),X)){let t=e.pop().value;return e.pop(),e.push({type:S,value:[t]}),!0}if(p(e.peek(),L)&&p(e.last(1),X)){let t=e.pop();return e.pop(),e.push({type:S,value:[t]}),!0}if(p(e.peek(),m)&&p(e.last(1),E)){let t=e.pop();for(e.push({type:R,value:t.value}),""+t.value;b(e););return e.push({type:U}),!0}if(p(e.peek(),E)&&(p(e.last(1),m)||p(e.last(1),L)||p(e.last(1),R))){for(e.pop(),e.push({type:U,value:"]"}),""+JSON.stringify(e);b(e););return!0}if(p(e.peek(),m)&&p(e.last(1),X)){let t=e.pop();return e.pop(),e.push({type:S,value:[t.value]}),!0}if(p(e.peek(),E)&&p(e.last(1),w)){for(e.pop(),e.push({type:U}),""+JSON.stringify(e);b(e););return!0}break;case D:if(p(e.peek(),_)&&p(e.last(1),G)){let t=e.pop();return e.pop(),e.push({type:L,value:t.value}),!0}if(p(e.peek(),G))return e.pop(),e.push({type:L,value:null}),!0;if(p(e.peek(),m)&&p(e.last(1),I)){let t=e.pop();for(e.push({type:R,value:t.value}),""+t.value;b(e););return e.push({type:D}),!0}if(p(e.peek(),I)){for(e.push({type:R,value:null});b(e););return e.push({type:D}),!0}if(p(e.peek(),E))return e.pop(),e.push({type:D}),!0;throw new Error("Found } that I can't handle at line "+r.row+":"+r.col);case E:if(p(e.peek(),E))return!0;if(p(e.peek(),m)){let t=e.pop();for(e.push({type:R,value:t.value});b(e););return e.push(r),!0}if(p(e.peek(),I)){for(e.push({type:R,value:null});b(e););return e.push(r),!0}}return e.push(r),!1}function J(e,r){if(["boolean","number","string"].indexOf(typeof e)!=-1)return e;if(e===null)return null;if(Array.isArray(e)){let n=[];for(;e.length>0;)n.unshift(J(e.pop()));return n}if(p(e,L)){let n={};return e.value===null?{}:(e.value.forEach(function(u){let i=u.key,d=J(u.value);r&&i in n?n[i]={value:n[i],next:d}:n[i]=d}),n)}return p(e,S)?J(e.value):e.value}});var fe=C((er,se)=>{"use strict";var Me=ae();se.exports.parse=Be;function Be(e,r){let t=!0,n=!1;r&&("fallback"in r&&r[t]===!1&&(t=!1),n="duplicateKeys"in r&&r.duplicateKeys===!0);try{return Me.parse(e,n)}catch(u){if(t===!1)throw u;try{let i=JSON.parse(e);return console.warn("dirty-json got valid JSON that failed with the custom parser. We're returning the valid JSON, but please file a bug report here: https://github.com/RyanMarcus/dirty-json/issues -- the JSON that caused the failure was: "+e),i}catch(i){throw u}}}});var Y=ge(fe());function Ke(e,r){if(!Array.isArray(e)||typeof r!="function")throw new Error("Invalid arguments. Expected an array and a function.");let t=[],n=[];for(let u of e)r(u)?t.push(u):n.push(u);return[t,n]}function de(e){return Object.keys(e).map(r=>typeof e[r]=="object"&&e[r]!==null?encodeURIComponent(r)+"="+encodeURIComponent(JSON.stringify(e[r])):encodeURIComponent(r)+"="+encodeURIComponent(e[r])).join("&")}function T(e,r){return{"X-Project-Id":`${e.id}`,Authorization:r==null?void 0:r.accessToken,"X-Client-Version":e==null?void 0:e.clientVersion}}var F="https://app.apifox.com",rr=async(e,r)=>{let{projectConfig:t}=e,{data:n}=await r.fetchJSON(`${F}/api/v1/project-members`,{headers:T(t,r.teamConfig)}),u=await r.fetchJSON(`${F}/api/v1/api-tree-list`,{headers:T(t,r.teamConfig)}),i=[],d=[],c=l=>{var f;let s=((f=t.requestMap)==null?void 0:f[l.path])||l.path,A=(n||[]).find(g=>g.user.id===l.responsibleId);return{id:l.id,name:l.name,method:l.method.toUpperCase(),path:l.path,realPath:s,creator:`${(A==null?void 0:A.nickname)||"-"}`,mockUrl:`${t==null?void 0:t.mockPrefixUrl}${l.path}`,sourceUrl:`${F}/project/${t==null?void 0:t.id}/apis/api-${l==null?void 0:l.id}`}},y=(l,s="")=>{if(l.type!=="apiDetailFolder"||!l.children||l.children.length===0)return;let[A,f]=Ke(l.children||[],g=>g.type==="apiDetail");if(A.length>0){let g=A.map(o=>c(o.api));d.push(...g),i.push({id:l.key,name:s?`${s}__${l.name}`:l.name,apis:g})}f.forEach(g=>{y(g,l.name)})};return u.data.forEach(l=>{y(l)}),{groups:[{id:"all",name:"\u5168\u90E8\u63A5\u53E3",apis:d},...i]}},tr=async(e,r)=>{var s,A,f,g,o,a;let{projectConfig:t,overviewApiResponse:n}=e,u=await r.fetchJSON(`${F}/api/v1/api-details/${n.id}`,{headers:T(t,r.teamConfig)}),d=(await r.fetchJSON(`${F}/api/v1/api-mocks`,{headers:T(t,r.teamConfig)})).data.filter(h=>h.apiDetailId===n.id).map(h=>({id:h.id,name:h.name,mockUrl:`${t==null?void 0:t.mockPrefixUrl}${n.path}`,mockData:Y.default.parse(h.response.bodyData),realSceneId:h.id})),c=(f=(A=(s=u==null?void 0:u.data)==null?void 0:s.responseExamples)==null?void 0:A[0])==null?void 0:f.data;c=c?Y.default.parse(c):"";let y=((g=t.requestMap)==null?void 0:g[n.path])||n.path;return{id:n.id,name:n.name,method:n.method,path:n.path,realPath:y,desc:(o=u==null?void 0:u.data)==null?void 0:o.description,creator:`${n.creator}`,mockUrl:`${t==null?void 0:t.mockPrefixUrl}${n.path}`,sourceUrl:`${F}/project/${t==null?void 0:t.id}/apis/api-${n==null?void 0:n.id}`,mockData:c||((a=d[0])==null?void 0:a.mockData)||{},scenes:d}},nr=(e,r)=>{let{projectConfig:t,apiResponse:n,addScenePayload:u}=e,i={response:{code:200,delay:0,headers:[],bodyType:"json",bodyData:JSON.stringify(u.mockData)},name:u.name,apiDetailId:n.id,conditions:[],ipCondition:{}};return r.fetchJSON(`${F}/api/v1/api-mocks`,{method:"POST",body:de(i),headers:{...T(t,r.teamConfig),"Content-Type":"application/x-www-form-urlencoded"}}).then(d=>({id:d.data.id}))},ur=(e,r)=>{let{projectConfig:t,apiResponse:n,sceneResponse:u}=e,i={response:{code:200,delay:0,headers:[],bodyType:"json",bodyData:JSON.stringify(u.mockData)},name:u.name,apiDetailId:n.id,id:u.id,conditions:[],ipCondition:{}};return r.fetchJSON(`${F}/api/v1/api-mocks/${u.realSceneId}`,{method:"PUT",body:de(i),headers:{...T(t,r.teamConfig),"Content-Type":"application/x-www-form-urlencoded"}})},ir=(e,r)=>{let{projectConfig:t,sceneResponse:n}=e;return r.fetchJSON(`${F}/api/v1/api-mocks/${n.realSceneId}`,{method:"DELETE",headers:T(t,r.teamConfig)})};export{nr as addApiScene,ir as deleteApiScene,tr as getApi,rr as getProject,ur as updateApiScene}; | ||
var he=Object.create;var z=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,xe=Object.prototype.hasOwnProperty;var L=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var ge=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of ce(r))!xe.call(e,i)&&i!==t&&z(e,i,{get:()=>r[i],enumerable:!(n=ve(r,i))||n.enumerable});return e};var Ae=(e,r,t)=>(t=e!=null?he(ye(e)):{},ge(r||!e||!e.__esModule?z(t,"default",{value:e,enumerable:!0}):t,e));var W=L((Ge,P)=>{typeof P=="object"&&typeof P.exports=="object"&&(P.exports=M);M.defunct=function(e){throw new Error("Unexpected character at index "+(this.index-1)+": "+e)};function M(e){typeof e!="function"&&(e=M.defunct);var r=[],t=[],n=0;this.state=0,this.index=0,this.input="",this.addRule=function(u,d,c){var y=u.global;if(!y){var l="g";u.multiline&&(l+="m"),u.ignoreCase&&(l+="i"),u=new RegExp(u.source,l)}return Object.prototype.toString.call(c)!=="[object Array]"&&(c=[0]),t.push({pattern:u,global:y,action:d,start:c}),this},this.setInput=function(u){return n=0,this.state=0,this.index=0,r.length=0,this.input=u,this},this.lex=function(){if(r.length)return r.shift();for(this.reject=!0;this.index<=this.input.length;){for(var u=i.call(this).splice(n),d=this.index;u.length&&this.reject;){var c=u.shift(),y=c.result,l=c.length;this.index+=l,this.reject=!1,n++;var s=c.action.apply(this,y);if(this.reject)this.index=y.index;else if(typeof s!="undefined")switch(Object.prototype.toString.call(s)){case"[object Array]":r=s.slice(1),s=s[0];default:return l&&(n=0),s}}var g=this.input;if(d<g.length)if(this.reject){n=0;var s=e.call(this,g.charAt(this.index++));if(typeof s!="undefined")return Object.prototype.toString.call(s)==="[object Array]"?(r=s.slice(1),s[0]):s}else this.index!==d&&(n=0),this.reject=!0;else if(u.length)this.reject=!0;else break}};function i(){for(var u=[],d=0,c=this.state,y=this.index,l=this.input,s=0,g=t.length;s<g;s++){var f=t[s],A=f.start,p=A.length;if(!p||A.indexOf(c)>=0||c%2&&p===1&&!A[0]){var a=f.pattern;a.lastIndex=y;var h=a.exec(l);if(h&&h.index===y){var x=u.push({result:h,action:f.action,length:h[0].length});for(f.global&&(d=x);--x>d;){var v=x-1;if(u[x].length>u[v].length){var F=u[x];u[x]=u[v],u[v]=F}}}}}return u}}});var Z=L(()=>{String.fromCodePoint||function(){var e=function(){try{var i={},u=Object.defineProperty,d=u(i,i,i)&&u}catch(c){}return d}(),r=String.fromCharCode,t=Math.floor,n=function(i){var u=16384,d=[],c,y,l=-1,s=arguments.length;if(!s)return"";for(var g="";++l<s;){var f=Number(arguments[l]);if(!isFinite(f)||f<0||f>1114111||t(f)!=f)throw RangeError("Invalid code point: "+f);f<=65535?d.push(f):(f-=65536,c=(f>>10)+55296,y=f%1024+56320,d.push(c,y)),(l+1==s||d.length>u)&&(g+=r.apply(null,d),d.length=0)}return g};e?e(String,"fromCodePoint",{value:n,configurable:!0,writable:!0}):String.fromCodePoint=n}()});var k=L((D,H)=>{"use strict";Object.defineProperty(D,"__esModule",{value:!0});D.default=void 0;Z();var me=/\\(u\{([0-9A-Fa-f]+)\}|u([0-9A-Fa-f]{4})|x([0-9A-Fa-f]{2})|([1-7][0-7]{0,2}|[0-7]{2,3})|(['"tbrnfv0\\]))|\\U([0-9A-Fa-f]{8})/g,Re={0:"\0",b:"\b",f:"\f",n:` | ||
`,r:"\r",t:" ",v:"\v","'":"'",'"':'"',"\\":"\\"},$=function(r){return String.fromCodePoint(parseInt(r,16))},Ee=function(r){return String.fromCodePoint(parseInt(r,8))},Se=function(r){return r.replace(me,function(t,n,i,u,d,c,y,l){return i!==void 0?$(i):u!==void 0?$(u):d!==void 0?$(d):c!==void 0?Ee(c):l!==void 0?$(l):Re[y]})};D.default=Se;H.exports=D.default});var ee=L(q=>{(function(e){var r=String.fromCharCode;function t(p){for(var a=[],h=0,x=p.length,v,F;h<x;)v=p.charCodeAt(h++),v>=55296&&v<=56319&&h<x?(F=p.charCodeAt(h++),(F&64512)==56320?a.push(((v&1023)<<10)+(F&1023)+65536):(a.push(v),h--)):a.push(v);return a}function n(p){for(var a=p.length,h=-1,x,v="";++h<a;)x=p[h],x>65535&&(x-=65536,v+=r(x>>>10&1023|55296),x=56320|x&1023),v+=r(x);return v}function i(p){if(p>=55296&&p<=57343)throw Error("Lone surrogate U+"+p.toString(16).toUpperCase()+" is not a scalar value")}function u(p,a){return r(p>>a&63|128)}function d(p){if((p&4294967168)==0)return r(p);var a="";return(p&4294965248)==0?a=r(p>>6&31|192):(p&4294901760)==0?(i(p),a=r(p>>12&15|224),a+=u(p,6)):(p&4292870144)==0&&(a=r(p>>18&7|240),a+=u(p,12),a+=u(p,6)),a+=r(p&63|128),a}function c(p){for(var a=t(p),h=a.length,x=-1,v,F="";++x<h;)v=a[x],F+=d(v);return F}function y(){if(f>=g)throw Error("Invalid byte index");var p=s[f]&255;if(f++,(p&192)==128)return p&63;throw Error("Invalid continuation byte")}function l(){var p,a,h,x,v;if(f>g)throw Error("Invalid byte index");if(f==g)return!1;if(p=s[f]&255,f++,(p&128)==0)return p;if((p&224)==192){if(a=y(),v=(p&31)<<6|a,v>=128)return v;throw Error("Invalid continuation byte")}if((p&240)==224){if(a=y(),h=y(),v=(p&15)<<12|a<<6|h,v>=2048)return i(v),v;throw Error("Invalid continuation byte")}if((p&248)==240&&(a=y(),h=y(),x=y(),v=(p&7)<<18|a<<12|h<<6|x,v>=65536&&v<=1114111))return v;throw Error("Invalid UTF-8 detected")}var s,g,f;function A(p){s=t(p),g=s.length,f=0;for(var a=[],h;(h=l())!==!1;)a.push(h);return n(a)}e.version="3.0.0",e.encode=c,e.decode=A})(typeof q=="undefined"?q.utf8={}:q)});var ue=L((He,B)=>{"use strict";var be=W(),Ce=k(),Ze=ee(),re=6,Fe=7,te=11,we=12,Oe=13,Le=14,_e=-1,Te=-2,Xe=-3,Ie=-4,Ue=-5,je=[[/\s*:\s*/,_e],[/\s*,\s*/,Te],[/\s*{\s*/,Xe],[/\s*}\s*/,Oe],[/\s*\[\s*/,Ie],[/\s*\]\s*/,we],[/\s*\.\s*/,Ue]];function ne(e){return e=e.replace(/\\\//,"/"),Ce(e)}function De(e){let r=new be,t=0,n=0;return r.addRule(/"((?:\\.|[^"])*?)($|")/,(i,u)=>(t+=i.length,{type:te,value:ne(u),row:n,col:t,single:!1})),r.addRule(/'((?:\\.|[^'])*?)($|'|(",?[ \t]*\n))/,(i,u)=>(t+=i.length,{type:te,value:ne(u),row:n,col:t,single:!0})),r.addRule(/[\-0-9]*\.[0-9]*([eE][\+\-]?)?[0-9]*(?:\s*)/,i=>(t+=i.length,{type:re,value:parseFloat(i),row:n,col:t})),r.addRule(/\-?[0-9]+([eE][\+\-]?)[0-9]*(?:\s*)/,i=>(t+=i.length,{type:re,value:parseFloat(i),row:n,col:t})),r.addRule(/\-?[0-9]+(?:\s*)/,i=>(t+=i.length,{type:Fe,value:parseInt(i),row:n,col:t})),je.forEach(i=>{r.addRule(i[0],u=>(t+=u.length,{type:i[1],value:u,row:n,col:t}))}),r.addRule(/\s/,i=>{i==` | ||
`?(t=0,n++):t+=i.length}),r.addRule(/\S[ \t]*/,i=>(t+=i.length,{type:Le,value:i,row:n,col:t})),r.setInput(e),r}B.exports.lexString=ie;function ie(e,r){let t=De(e),n="";for(;n=t.lex();)r(n)}B.exports.getAllTokens=Pe;function Pe(e){let r=[];return ie(e,function(n){r.push(n)}),r}});var ae=L((ke,le)=>{"use strict";var $e=ue(),K=0,_=1,w=2,Q=3,N=4,V=5,qe=6,oe=7,R=8,S=9,O=10,Ne=11,U=12,j=13,Ve=14,m=15,I=-1,E=-2,G=-3,T=-4;function pe(e){e.peek==null&&Object.defineProperty(e,"peek",{enumerable:!1,value:function(){return this[this.length-1]}}),e.last==null&&Object.defineProperty(e,"last",{enumerable:!1,value:function(r){return this[this.length-(1+r)]}})}function o(e,r){return e&&e.hasOwnProperty("type")&&e.type==r}le.exports.parse=Je;function Je(e,r){let t=[],n=[];pe(t),pe(n);let i=function(u){n.push(u)};$e.lexString(e,i),n[0].type==T&&n.last(0).type!=U&&n.push({type:U,value:"]",row:-1,col:-1}),n[0].type==G&&n.last(0).type!=j&&n.push({type:j,value:"}",row:-1,col:-1});for(let u=0;u<n.length;u++)for(""+n[u].type,t.push(n[u]);b(t););return t.length==1&&t[0].type==_&&(t=[{type:O,value:t[0].value}]),J(t[0],r)}function b(e){let r=e.pop();switch(r.type){case R:if(r.value.trim()=="true")return e.push({type:Q,value:"true"}),!0;if(r.value.trim()=="false")return e.push({type:Q,value:"false"}),!0;if(r.value.trim()=="null")return e.push({type:m,value:null}),!0;break;case Ve:return o(e.peek(),R)?(e.peek().value+=r.value,!0):(e.push({type:R,value:r.value}),!0);case oe:return o(r,oe)&&o(e.peek(),R)?(e.peek().value+=r.value,!0):(r.type=m,e.push(r),!0);case Ne:return r.type=m,r.value=r.value,e.push(r),!0;case Q:return r.type=m,r.value=="true"?r.value=!0:r.value=!1,e.push(r),!0;case qe:return r.type=m,e.push(r),!0;case m:if(o(e.peek(),E))return r.type=V,e.pop(),e.push(r),!0;if(o(e.peek(),I))return r.type=N,e.pop(),e.push(r),!0;if(o(e.peek(),R)&&o(e.last(1),m)){let t=e.pop();return e.peek().value+='"'+t.value+'"',e.peek().value+=r.value,!0}if(o(e.peek(),R)&&o(e.last(1),w)){let t=e.pop(),n=e.peek().value.pop();return n+='"'+t.value+'"',n+=r.value,e.peek().value.push(n),!0}if(o(e.peek(),R)&&o(e.last(1),_)){let t=e.pop(),n=e.peek().value.pop(),i=r.single?"'":'"';return n.value+=i+t.value+i,n.value+=r.value,e.peek().value.push(n),!0}if(o(e.peek(),R)){let t=e.pop().value;return r.value=t+r.value,e.push(r),!0}break;case S:if(o(r,S)&&o(e.peek(),E))return r.type=V,e.pop(),e.push(r),!0;if(o(e.peek(),I))return r.type=N,e.pop(),e.push(r),!0;break;case O:if(o(e.peek(),E)){let t={type:V,value:r};return e.pop(),e.push(t),!0}if(o(e.peek(),I)){let t={type:N,value:r};return e.pop(),e.push(t),!0}if(o(e.peek(),R)){let t=e.pop();return e.push({type:K,key:t.value.trim(),value:r}),!0}break;case V:return o(e.peek(),w)?(e.peek().value.push(r.value),!0):(e.push({type:w,value:[r.value]}),!0);case w:if(o(e.peek(),m))return r.value.unshift(e.peek().value),e.pop(),e.push(r),!0;if(o(e.peek(),S))return r.value.unshift(e.peek().value),e.pop(),e.push(r),!0;if(o(e.peek(),O))return r.value.unshift(e.peek()),e.pop(),e.push(r),!0;if(o(e.peek(),R)&&(e.last(1),E)){let t=e.pop();for(e.push({type:m,value:t.value}),""+t.value;b(e););return e.push(r),!0}if(o(e.peek(),w))return e.peek().value.push(r.value[0]),!0;break;case N:if(o(e.peek(),R)||o(e.peek(),m)||o(e.peek(),w)){let t=e.pop();return e.push({type:K,key:t.value,value:r.value}),!0}throw new Error("Got a :value that can't be handled at line "+r.row+":"+r.col);case K:return o(e.last(0),E)&&o(e.last(1),_)?(e.last(1).value.push(r),e.pop(),!0):(e.push({type:_,value:[r]}),!0);case _:if(o(e.peek(),_))return r.value.forEach(function(t){e.peek().value.push(t)}),!0;break;case U:if(o(e.peek(),w)&&o(e.last(1),T)){let t=e.pop();return e.pop(),e.push({type:S,value:t.value}),!0}if(o(e.peek(),S)&&o(e.last(1),T)){let t=e.pop();return e.pop(),e.push({type:S,value:[t.value]}),!0}if(o(e.peek(),T))return e.pop(),e.push({type:S,value:[]}),!0;if(o(e.peek(),m)&&o(e.last(1),T)){let t=e.pop().value;return e.pop(),e.push({type:S,value:[t]}),!0}if(o(e.peek(),O)&&o(e.last(1),T)){let t=e.pop();return e.pop(),e.push({type:S,value:[t]}),!0}if(o(e.peek(),R)&&o(e.last(1),E)){let t=e.pop();for(e.push({type:m,value:t.value}),""+t.value;b(e););return e.push({type:U}),!0}if(o(e.peek(),E)&&(o(e.last(1),R)||o(e.last(1),O)||o(e.last(1),m))){for(e.pop(),e.push({type:U,value:"]"}),""+JSON.stringify(e);b(e););return!0}if(o(e.peek(),R)&&o(e.last(1),T)){let t=e.pop();return e.pop(),e.push({type:S,value:[t.value]}),!0}if(o(e.peek(),E)&&o(e.last(1),w)){for(e.pop(),e.push({type:U}),""+JSON.stringify(e);b(e););return!0}break;case j:if(o(e.peek(),_)&&o(e.last(1),G)){let t=e.pop();return e.pop(),e.push({type:O,value:t.value}),!0}if(o(e.peek(),G))return e.pop(),e.push({type:O,value:null}),!0;if(o(e.peek(),R)&&o(e.last(1),I)){let t=e.pop();for(e.push({type:m,value:t.value}),""+t.value;b(e););return e.push({type:j}),!0}if(o(e.peek(),I)){for(e.push({type:m,value:null});b(e););return e.push({type:j}),!0}if(o(e.peek(),E))return e.pop(),e.push({type:j}),!0;throw new Error("Found } that I can't handle at line "+r.row+":"+r.col);case E:if(o(e.peek(),E))return!0;if(o(e.peek(),R)){let t=e.pop();for(e.push({type:m,value:t.value});b(e););return e.push(r),!0}if(o(e.peek(),I)){for(e.push({type:m,value:null});b(e););return e.push(r),!0}}return e.push(r),!1}function J(e,r){if(["boolean","number","string"].indexOf(typeof e)!=-1)return e;if(e===null)return null;if(Array.isArray(e)){let n=[];for(;e.length>0;)n.unshift(J(e.pop()));return n}if(o(e,O)){let n={};return e.value===null?{}:(e.value.forEach(function(i){let u=i.key,d=J(i.value);r&&u in n?n[u]={value:n[u],next:d}:n[u]=d}),n)}return o(e,S)?J(e.value):e.value}});var fe=L((er,se)=>{"use strict";var Me=ae();se.exports.parse=Be;function Be(e,r){let t=!0,n=!1;r&&("fallback"in r&&r[t]===!1&&(t=!1),n="duplicateKeys"in r&&r.duplicateKeys===!0);try{return Me.parse(e,n)}catch(i){if(t===!1)throw i;try{let u=JSON.parse(e);return console.warn("dirty-json got valid JSON that failed with the custom parser. We're returning the valid JSON, but please file a bug report here: https://github.com/RyanMarcus/dirty-json/issues -- the JSON that caused the failure was: "+e),u}catch(u){throw i}}}});var Y=Ae(fe());function Ke(e,r){if(!Array.isArray(e)||typeof r!="function")throw new Error("Invalid arguments. Expected an array and a function.");let t=[],n=[];for(let i of e)r(i)?t.push(i):n.push(i);return[t,n]}function de(e){return Object.keys(e).map(r=>typeof e[r]=="object"&&e[r]!==null?encodeURIComponent(r)+"="+encodeURIComponent(JSON.stringify(e[r])):encodeURIComponent(r)+"="+encodeURIComponent(e[r])).join("&")}function X(e,r){if(!r.accessToken)throw new Error("teamConfig\u4E2D\u5FC5\u914D\u7F6EaccessToken");if(!r.clientVersion)throw new Error("teamConfig\u4E2D\u5FC5\u914D\u7F6EclientVersion");return{"X-Project-Id":`${e.id}`,Authorization:r.accessToken,"X-Client-Version":r.clientVersion}}var C="https://app.apifox.com",rr=async(e,r)=>{let{projectConfig:t}=e,{data:n}=await r.fetchJSON(`${C}/api/v1/project-members`,{headers:X(t,r.teamConfig)}),i=await r.fetchJSON(`${C}/api/v1/api-tree-list`,{headers:X(t,r.teamConfig)}),u=[],d=[],c=l=>{var f;let s=((f=t.requestMap)==null?void 0:f[l.path])||l.path,g=(n||[]).find(A=>A.user.id===l.responsibleId);return{id:l.id,name:l.name,method:l.method.toUpperCase(),path:l.path,realPath:s,creator:`${(g==null?void 0:g.nickname)||"-"}`,mockUrl:`${t==null?void 0:t.mockPrefixUrl}${l.path}`,sourceUrl:`${C}/project/${t==null?void 0:t.id}/apis/api-${l==null?void 0:l.id}`}},y=(l,s="")=>{if(l.type!=="apiDetailFolder"||!l.children||l.children.length===0)return;let[g,f]=Ke(l.children||[],A=>A.type==="apiDetail");if(g.length>0){let A=g.map(p=>c(p.api));d.push(...A),u.push({id:l.key,name:s?`${s}__${l.name}`:l.name,apis:A})}f.forEach(A=>{y(A,l.name)})};return i.data.forEach(l=>{y(l)}),{groups:[{id:"all",name:"\u5168\u90E8\u63A5\u53E3",apis:d},...u]}},tr=async(e,r)=>{var s,g,f,A,p,a;let{projectConfig:t,overviewApiResponse:n}=e,i=await r.fetchJSON(`${C}/api/v1/api-details/${n.id}`,{headers:X(t,r.teamConfig)}),d=(await r.fetchJSON(`${C}/api/v1/api-mocks`,{headers:X(t,r.teamConfig)})).data.filter(h=>h.apiDetailId===n.id).map(h=>({id:h.id,name:h.name,mockUrl:`${t==null?void 0:t.mockPrefixUrl}${n.path}`,mockData:Y.default.parse(h.response.bodyData),realSceneId:h.id})),c=(f=(g=(s=i==null?void 0:i.data)==null?void 0:s.responseExamples)==null?void 0:g[0])==null?void 0:f.data;c=c?Y.default.parse(c):"";let y=((A=t.requestMap)==null?void 0:A[n.path])||n.path;return{id:n.id,name:n.name,method:n.method,path:n.path,realPath:y,desc:(p=i==null?void 0:i.data)==null?void 0:p.description,creator:`${n.creator}`,mockUrl:`${t==null?void 0:t.mockPrefixUrl}${n.path}`,sourceUrl:`${C}/project/${t==null?void 0:t.id}/apis/api-${n==null?void 0:n.id}`,mockData:c||((a=d[0])==null?void 0:a.mockData)||{},scenes:d}},nr=(e,r)=>{let{projectConfig:t,apiResponse:n,addScenePayload:i}=e,u={response:{code:200,delay:0,headers:[],bodyType:"json",bodyData:JSON.stringify(i.mockData)},name:i.name,apiDetailId:n.id,conditions:[],ipCondition:{}};return r.fetchJSON(`${C}/api/v1/api-mocks`,{method:"POST",body:de(u),headers:{...X(t,r.teamConfig),"Content-Type":"application/x-www-form-urlencoded"}}).then(d=>({id:d.data.id}))},ir=(e,r)=>{let{projectConfig:t,apiResponse:n,sceneResponse:i}=e,u={response:{code:200,delay:0,headers:[],bodyType:"json",bodyData:JSON.stringify(i.mockData)},name:i.name,apiDetailId:n.id,id:i.id,conditions:[],ipCondition:{}};return r.fetchJSON(`${C}/api/v1/api-mocks/${i.realSceneId}`,{method:"PUT",body:de(u),headers:{...X(t,r.teamConfig),"Content-Type":"application/x-www-form-urlencoded"}})},ur=(e,r)=>{let{projectConfig:t,sceneResponse:n}=e;return r.fetchJSON(`${C}/api/v1/api-mocks/${n.realSceneId}`,{method:"DELETE",headers:X(t,r.teamConfig)})};export{nr as addApiScene,ur as deleteApiScene,tr as getApi,rr as getProject,ir as updateApiScene}; | ||
/*! http://mths.be/fromcodepoint v0.2.1 by @mathias */ | ||
/*! https://mths.be/utf8js v3.0.0 by @mathias */ |
{ | ||
"name": "@mock-proxy/mock-proxy-apifox-script", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "mock proxy apifox脚本", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -63,7 +63,15 @@ import { | ||
function makeRequestHeaders(projectConfig: ApifoxProjectConfig, teamConfig: TeamConfig) { | ||
function makeRequestHeaders(projectConfig: ApifoxProjectConfig, teamConfig: ApifoxTeamConfig) { | ||
if(!teamConfig.accessToken) { | ||
throw new Error('teamConfig中必配置accessToken'); | ||
} | ||
if(!teamConfig.clientVersion) { | ||
throw new Error('teamConfig中必配置clientVersion'); | ||
} | ||
return { | ||
"X-Project-Id": `${projectConfig.id}`, | ||
Authorization: teamConfig?.accessToken!, | ||
"X-Client-Version": projectConfig?.clientVersion!, | ||
Authorization: teamConfig.accessToken, | ||
"X-Client-Version": teamConfig.clientVersion, | ||
}; | ||
@@ -83,6 +91,12 @@ } | ||
interface ApifoxTeamConfig extends TeamConfig { | ||
// 请求的Authorization Header字段 | ||
accessToken: string; | ||
// apifox的客户端版本 | ||
clientVersion: string; | ||
} | ||
interface ApifoxProjectConfig extends ProjectConfig { | ||
requestMap?: RequestMap; | ||
mockPrefixUrl?: string; | ||
clientVersion?: string; | ||
} | ||
@@ -108,3 +122,3 @@ | ||
{ | ||
headers: makeRequestHeaders(projectConfig, context.teamConfig), | ||
headers: makeRequestHeaders(projectConfig, context.teamConfig as ApifoxTeamConfig), | ||
} | ||
@@ -116,3 +130,3 @@ ); | ||
{ | ||
headers: makeRequestHeaders(projectConfig, context.teamConfig), | ||
headers: makeRequestHeaders(projectConfig, context.teamConfig as ApifoxTeamConfig), | ||
} | ||
@@ -202,3 +216,3 @@ ); | ||
{ | ||
headers: makeRequestHeaders(projectConfig, context.teamConfig), | ||
headers: makeRequestHeaders(projectConfig, context.teamConfig as ApifoxTeamConfig), | ||
} | ||
@@ -210,3 +224,3 @@ ); | ||
{ | ||
headers: makeRequestHeaders(projectConfig, context.teamConfig), | ||
headers: makeRequestHeaders(projectConfig, context.teamConfig as ApifoxTeamConfig), | ||
} | ||
@@ -307,3 +321,3 @@ ); | ||
headers: { | ||
...makeRequestHeaders(projectConfig, context.teamConfig), | ||
...makeRequestHeaders(projectConfig, context.teamConfig as ApifoxTeamConfig), | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
@@ -351,3 +365,3 @@ }, | ||
headers: { | ||
...makeRequestHeaders(projectConfig, context.teamConfig), | ||
...makeRequestHeaders(projectConfig, context.teamConfig as ApifoxTeamConfig), | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
@@ -373,5 +387,5 @@ }, | ||
method: "DELETE", | ||
headers: makeRequestHeaders(projectConfig, context.teamConfig), | ||
headers: makeRequestHeaders(projectConfig, context.teamConfig as ApifoxTeamConfig), | ||
} | ||
); | ||
}; |
Sorry, the diff of this file is not supported yet
111755
736