@mock-proxy/mock-proxy-apifox-script
Advanced tools
Comparing version 1.2.3 to 1.3.0
@@ -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 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}; | ||
var he=Object.create;var z=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var xe=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var L=(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 i of ce(r))!ye.call(e,i)&&i!==t&&z(e,i,{get:()=>r[i],enumerable:!(n=ve(r,i))||n.enumerable});return e};var ge=(e,r,t)=>(t=e!=null?he(xe(e)):{},Ae(r||!e||!e.__esModule?z(t,"default",{value:e,enumerable:!0}):t,e));var W=L((Ge,j)=>{typeof j=="object"&&typeof j.exports=="object"&&(j.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 x=u.global;if(!x){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:x,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(),x=c.result,l=c.length;this.index+=l,this.reject=!1,n++;var s=c.action.apply(this,x);if(this.reject)this.index=x.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(u.length)this.reject=!0;else break}};function i(){for(var u=[],d=0,c=this.state,x=this.index,l=this.input,s=0,A=t.length;s<A;s++){var f=t[s],g=f.start,p=g.length;if(!p||g.indexOf(c)>=0||c%2&&p===1&&!g[0]){var a=f.pattern;a.lastIndex=x;var h=a.exec(l);if(h&&h.index===x){var y=u.push({result:h,action:f.action,length:h[0].length});for(f.global&&(d=y);--y>d;){var v=y-1;if(u[y].length>u[v].length){var C=u[y];u[y]=u[v],u[v]=C}}}}}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,x,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,x=f%1024+56320,d.push(c,x)),(l+1==s||d.length>u)&&(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=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,x,l){return i!==void 0?$(i):u!==void 0?$(u):d!==void 0?$(d):c!==void 0?Ee(c):l!==void 0?$(l):Re[x]})};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,y=p.length,v,C;h<y;)v=p.charCodeAt(h++),v>=55296&&v<=56319&&h<y?(C=p.charCodeAt(h++),(C&64512)==56320?a.push(((v&1023)<<10)+(C&1023)+65536):(a.push(v),h--)):a.push(v);return a}function n(p){for(var a=p.length,h=-1,y,v="";++h<a;)y=p[h],y>65535&&(y-=65536,v+=r(y>>>10&1023|55296),y=56320|y&1023),v+=r(y);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,y=-1,v,C="";++y<h;)v=a[y],C+=d(v);return C}function x(){if(f>=A)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,y,v;if(f>A)throw Error("Invalid byte index");if(f==A)return!1;if(p=s[f]&255,f++,(p&128)==0)return p;if((p&224)==192){if(a=x(),v=(p&31)<<6|a,v>=128)return v;throw Error("Invalid continuation byte")}if((p&240)==224){if(a=x(),h=x(),v=(p&15)<<12|a<<6|h,v>=2048)return i(v),v;throw Error("Invalid continuation byte")}if((p&248)==240&&(a=x(),h=x(),y=x(),v=(p&7)<<18|a<<12|h<<6|y,v>=65536&&v<=1114111))return v;throw Error("Invalid UTF-8 detected")}var s,A,f;function g(p){s=t(p),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 q=="undefined"?q.utf8={}:q)});var ue=L((He,B)=>{"use strict";var be=W(),we=k(),Ze=ee(),re=6,Ce=7,te=11,Fe=12,Oe=13,Le=14,_e=-1,Te=-2,Xe=-3,Ue=-4,Ie=-5,Pe=[[/\s*:\s*/,_e],[/\s*,\s*/,Te],[/\s*{\s*/,Xe],[/\s*}\s*/,Oe],[/\s*\[\s*/,Ue],[/\s*\]\s*/,Fe],[/\s*\.\s*/,Ie]];function ne(e){return e=e.replace(/\\\//,"/"),we(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:Ce,value:parseInt(i),row:n,col:t})),Pe.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=je;function je(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,F=2,Q=3,N=4,V=5,qe=6,oe=7,R=8,S=9,O=10,Ne=11,I=12,P=13,Ve=14,m=15,U=-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!=I&&n.push({type:I,value:"]",row:-1,col:-1}),n[0].type==G&&n.last(0).type!=P&&n.push({type:P,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(),U))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),F)){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(),U))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(),U)){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(),F)?(e.peek().value.push(r.value),!0):(e.push({type:F,value:[r.value]}),!0);case F: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(),F))return e.peek().value.push(r.value[0]),!0;break;case N:if(o(e.peek(),R)||o(e.peek(),m)||o(e.peek(),F)){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 I:if(o(e.peek(),F)&&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:I}),!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:I,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),F)){for(e.pop(),e.push({type:I}),""+JSON.stringify(e);b(e););return!0}break;case P: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),U)){let t=e.pop();for(e.push({type:m,value:t.value}),""+t.value;b(e););return e.push({type:P}),!0}if(o(e.peek(),U)){for(e.push({type:m,value:null});b(e););return e.push({type:P}),!0}if(o(e.peek(),E))return e.pop(),e.push({type:P}),!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(),U)){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=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 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 w="https://app.apifox.com",rr=async(e,r)=>{let{projectConfig:t}=e;if(!(t!=null&&t.mockPrefixUrl))throw new Error("project\u4E2D\u5FC5\u987B\u914D\u7F6EmockPrefixUrl");let{data:n}=await r.fetchJSON(`${w}/api/v1/project-members`,{headers:X(t,r.teamConfig)}),i=await r.fetchJSON(`${w}/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,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:`${w}/project/${t==null?void 0:t.id}/apis/api-${l==null?void 0:l.id}`}},x=(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(p=>c(p.api));d.push(...g),u.push({id:l.key,name:s?`${s}__${l.name}`:l.name,apis:g})}f.forEach(g=>{x(g,l.name)})};return i.data.forEach(l=>{x(l)}),{groups:[{id:"all",name:"\u5168\u90E8\u63A5\u53E3",apis:d},...u]}},tr=async(e,r)=>{var s,A,f,g,p,a;let{projectConfig:t,overviewApiResponse:n}=e;if(!(t!=null&&t.mockPrefixUrl))throw new Error("project\u4E2D\u5FC5\u987B\u914D\u7F6EmockPrefixUrl");let i=await r.fetchJSON(`${w}/api/v1/api-details/${n.id}`,{headers:X(t,r.teamConfig)}),d=(await r.fetchJSON(`${w}/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=(A=(s=i==null?void 0:i.data)==null?void 0:s.responseExamples)==null?void 0:A[0])==null?void 0:f.data;c=c?Y.default.parse(c):"";let x=((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:x,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:`${w}/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(`${w}/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(`${w}/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(`${w}/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.3", | ||
"version": "1.3.0", | ||
"description": "mock proxy apifox脚本", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -116,2 +116,5 @@ import { | ||
const { projectConfig } = params; | ||
if(!projectConfig?.mockPrefixUrl) throw new Error('project中必须配置mockPrefixUrl'); | ||
const { data: members } = | ||
@@ -209,2 +212,4 @@ await context.fetchJSON<ApifoxQueryMembersOriginalResponse>( | ||
if(!projectConfig?.mockPrefixUrl) throw new Error('project中必须配置mockPrefixUrl'); | ||
const apiDetail = | ||
@@ -211,0 +216,0 @@ await context.fetchJSON<ApifoxQueryApiDetailOriginalResponse>( |
Sorry, the diff of this file is not supported yet
112503
739