whistle.interceptors 0.0.4 → 0.0.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.
package/.console.log ADDED
@@ -0,0 +1,24 @@
1
+ ssss [
2
+ { id: 'tiance', name: '天策', config: { conditions: [Array] } },
3
+ { id: 'cdn', name: 'cdn', config: { conditions: [Array] } }
4
+ ] object
5
+ ssss [
6
+ { id: 'tiance', name: '天策', config: { conditions: [Array] } },
7
+ { id: 'cdn', name: 'cdn', config: { conditions: [Array] } }
8
+ ] object
9
+ ssss [
10
+ { id: 'tiance', name: '天策', config: { conditions: [Array] } },
11
+ { id: 'cdn', name: 'cdn', config: { conditions: [Array] } }
12
+ ] object
13
+ ssss [
14
+ { id: 'tiance', name: '天策', config: { conditions: [Array] } },
15
+ { id: 'cdn', name: 'cdn', config: { conditions: [Array] } }
16
+ ] object
17
+ ssss [
18
+ { id: 'tiance', name: '天策', config: { conditions: [Array] } },
19
+ { id: 'cdn', name: 'cdn', config: { conditions: [Array] } }
20
+ ] object
21
+ ssss [
22
+ { id: 'tiance', name: '天策', config: { conditions: [Array] } },
23
+ { id: 'cdn', name: 'cdn', config: { conditions: [Array] } }
24
+ ] object
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.0.5](https://github.com/lyx-jay/whistle.interceptors/compare/v0.0.4...v0.0.5) (2025-07-13)
6
+
7
+
8
+ ### Features
9
+
10
+ * 1.单个条件支持添加多个键值对 ([12f67cf](https://github.com/lyx-jay/whistle.interceptors/commit/12f67cf99c9d7ad7c023c1a95eba8608c0e16330))
11
+
5
12
  ### 0.0.4 (2025-05-23)
6
13
 
7
14
 
package/dist/server.js CHANGED
@@ -1 +1 @@
1
- var d=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var O=(o,t)=>{for(var e in t)d(o,e,{get:t[e],enumerable:!0})},f=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of T(t))!y.call(o,n)&&n!==e&&d(o,n,{get:()=>t[n],enumerable:!(r=P(t,n))||r.enumerable});return o};var S=o=>f(d({},"__esModule",{value:!0}),o);var h=(o,t,e)=>new Promise((r,n)=>{var c=s=>{try{l(e.next(s))}catch(a){n(a)}},i=s=>{try{l(e.throw(s))}catch(a){n(a)}},l=s=>s.done?r(s.value):Promise.resolve(s.value).then(c,i);l((e=e.apply(o,t)).next())});var w={};O(w,{default:()=>v});module.exports=S(w);var g="whistle.interceptors",p={NETWORK:"network",MOCK:"mock"};function A(o){let t={};return(o.startsWith("?")?o.substring(1):o).split("&").forEach(r=>{let[n,c]=r.split("=");n&&c&&(t[decodeURIComponent(n)]=decodeURIComponent(c))}),t}function W(o){return new Promise(t=>{o.getReqSession(e=>{t(JSON.parse(e.req.body))})})}function C({conditions:o,payload:t,res:e,req:r,options:n,extra:c}){if(!o.every(l=>{let{key:s,value:a,enabled:u}=l;return u&&t[s]&&t[s]===a}))return!0;e.setHeader("whistle-plugin","whistle.interceptors"),e.setHeader("Content-Type","application/json; charset=UTF-8"),e.setHeader("Access-Control-Allow-Origin",c.origin),e.setHeader("Access-Control-Allow-Credentials","true"),e.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization, X-Requested-With"),e.setHeader("Access-Control-Allow-Methods","POST,GET,OPTIONS,PUT,DELETE,HEAD"),e.end(o[0].response)}function m({conditions:o,payload:t,res:e,req:r,options:n,extra:c}){let i=o.find(({key:l,value:s,enabled:a})=>a&&t[l]===s);if(console.log("matchCondition",i),!i)return!0;if(i.proxyMode===p.NETWORK)return r.getSession(l=>{console.log("\u8FD4\u56DE\u5185\u5BB9",l.res.body),n.localStorage.setProperty(`${g}_${i.ruleId}_${i.key}_${i.value}`,l.res.body)}),!0;e.setHeader("whistle-plugin","whistle.interceptors"),e.setHeader("Content-Type","application/json; charset=UTF-8"),e.setHeader("Access-Control-Allow-Origin",c.origin),e.setHeader("Access-Control-Allow-Credentials","true"),e.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization, X-Requested-With"),e.setHeader("Access-Control-Allow-Methods","POST,GET,OPTIONS,PUT,DELETE,HEAD"),e.end(i.response)}function E({matchType:o,conditions:t,payload:e,res:r,req:n,options:c}){({and:C,or:m})[o]({conditions:t,payload:e,res:r,req:n,options:c,extra:{origin:n.headers.origin}})&&n.passThrough()}var v=(o,t)=>{o.on("request",(e,r)=>h(null,null,function*(){try{let n=e.originalReq.ruleValue,i=(JSON.parse(t.storage.getProperty(g))||[]).filter(R=>R.id===n)[0],{matchType:l,method:s,conditions:a}=i.config;if(e.method!==s){e.passThrough();return}let u;s==="POST"&&(u=yield W(e)),s==="GET"&&(u=A(t.parseUrl(e.fullUrl).query)),E({matchType:l,conditions:a,res:r,req:e,options:t,payload:u})}catch(n){e.passThrough()}})),o.on("upgrade",(e,r)=>{e.passThrough()}),o.on("connect",(e,r)=>{e.passThrough()})};
1
+ var p=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var O=(t,o)=>{for(var e in o)p(t,e,{get:o[e],enumerable:!0})},A=(t,o,e,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of f(o))!T.call(t,n)&&n!==e&&p(t,n,{get:()=>o[n],enumerable:!(l=P(o,n))||l.enumerable});return t};var m=t=>A(p({},"__esModule",{value:!0}),t);var y=(t,o,e)=>new Promise((l,n)=>{var a=s=>{try{r(e.next(s))}catch(i){n(i)}},c=s=>{try{r(e.throw(s))}catch(i){n(i)}},r=s=>s.done?l(s.value):Promise.resolve(s.value).then(a,c);r((e=e.apply(t,o)).next())});var w={};O(w,{default:()=>H});module.exports=m(w);var h="whistle.interceptors",R={NETWORK:"network",MOCK:"mock"};function S(t){let o={};return(t.startsWith("?")?t.substring(1):t).split("&").forEach(l=>{let[n,a]=l.split("=");n&&a&&(o[decodeURIComponent(n)]=decodeURIComponent(a))}),o}function W(t){return new Promise(o=>{t.getReqSession(e=>{o(JSON.parse(e.req.body))})})}function C({conditions:t,payload:o,res:e,req:l,options:n,extra:a}){let c=!0,r=null,s=-1;for(let i=0;i<t.length;i++){let d=t[i];if(!d.enabled)continue;if(!d.pairs.every(g=>g.key&&g.value&&o[g.key]===g.value)){c=!1;break}r===null&&(r=d,s=i)}if(!c)return!0;if((r==null?void 0:r.proxyMode)===R.NETWORK)return l.getSession(i=>{let d=`${r.ruleId}_${s}`;n.localStorage.setProperty(`${h}_${d}`,i.res.body)}),!0;e.setHeader("whistle-plugin","whistle.interceptors"),e.setHeader("Content-Type","application/json; charset=UTF-8"),e.setHeader("Access-Control-Allow-Origin",a.origin),e.setHeader("Access-Control-Allow-Credentials","true"),e.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization, X-Requested-With"),e.setHeader("Access-Control-Allow-Methods","POST,GET,OPTIONS,PUT,DELETE,HEAD"),e.end((r==null?void 0:r.response)||t[0].response)}function E({conditions:t,payload:o,res:e,req:l,options:n,extra:a}){let c=null,r=-1;for(let s=0;s<t.length;s++){let i=t[s];if(!i.enabled)continue;if(i.pairs.every(u=>u.key&&u.value&&o[u.key]===u.value)){c=i,r=s;break}}if(!c)return!0;if(c.proxyMode===R.NETWORK)return l.getSession(s=>{let i=`${c.ruleId}_${r}`;n.localStorage.setProperty(`${h}_${i}`,s.res.body)}),!0;e.setHeader("whistle-plugin","whistle.interceptors"),e.setHeader("Content-Type","application/json; charset=UTF-8"),e.setHeader("Access-Control-Allow-Origin",a.origin),e.setHeader("Access-Control-Allow-Credentials","true"),e.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization, X-Requested-With"),e.setHeader("Access-Control-Allow-Methods","POST,GET,OPTIONS,PUT,DELETE,HEAD"),e.end(c.response)}function v({matchType:t,conditions:o,payload:e,res:l,req:n,options:a}){({and:C,or:E})[t]({conditions:o,payload:e,res:l,req:n,options:a,extra:{origin:n.headers.origin}})&&n.passThrough()}var H=(t,o)=>{t.on("request",(e,l)=>y(null,null,function*(){try{let n=e.originalReq.ruleValue,c=(JSON.parse(o.storage.getProperty(h))||[]).filter(d=>d.id===n)[0];if(!c){e.passThrough();return}let{conditions:r}=c.config,s;e.method==="POST"||e.method==="PUT"||e.method==="PATCH"?s=yield W(e):s=S(o.parseUrl(e.fullUrl).query),v({matchType:"or",conditions:r,res:l,req:e,options:o,payload:s})}catch(n){e.passThrough()}}))};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whistle.interceptors",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "flexible interception requests",
5
5
  "author": {
6
6
  "name": "lvyuanxin",