twd-js 0.7.1 → 0.8.0
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/dist/constants/version.d.ts +1 -0
- package/dist/index.cjs.js +39 -39
- package/dist/index.es.js +2315 -2268
- package/dist/mock-sw.js +1 -1
- package/dist/twd.d.ts +1 -1
- package/dist/ui/Icons/MockRequestIcon.d.ts +2 -0
- package/dist/ui/MockRulesButton.d.ts +1 -0
- package/package.json +1 -1
package/dist/mock-sw.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const d=e=>{try{return new RegExp(e),!0}catch{return!1}},r=e=>{const s=e.split("?")[0];return/\.([a-zA-Z0-9]+)$/.test(s)};function f(e,s,o){return o.find(t=>{const n=t.method.toLowerCase()===e.toLowerCase();if(t.urlRegex&&d(t.url)){const i=new RegExp(t.url);return n&&i.test(s)}if(r(t.url))return n&&s.includes(t.url);const a=t.url===s||s.includes(t.url);return n&&a&&!r(s)})}function h(e,s,o){e.forEach(t=>t.postMessage({type:"EXECUTED",alias:s.alias,request:o}))}const y=(e,s,o)=>{const n=![204,205,304].includes(s),l=n?JSON.stringify(e):null;return new Response(l,{status:s,headers:n?o||{"Content-Type":"application/json"}:o||{}})},p="0.8.0";let c=[];const g=async e=>{const{method:s}=e.request,o=e.request.url,t=f(s,o,c);t&&(console.log("[TWD] Mock hit:",t.alias,s,o),e.respondWith((async()=>{let n=null;const l=e.request.headers.get("content-type")||"application/json";if(l.includes("application/json"))try{n=await e.request.clone().json()}catch{}else if(l.includes("form"))try{const a=await e.request.clone().formData();n={},a.forEach((i,u)=>{n[u]=i})}catch{}else if(l.includes("text"))try{n=await e.request.clone().text()}catch{}else if(l.includes("octet-stream"))try{n=await e.request.clone().arrayBuffer()}catch{}else if(l.includes("image"))try{n=await e.request.clone().blob()}catch{}else try{n=await e.request.clone().text()}catch{}return self.clients.matchAll().then(a=>{h(a,t,n)}),y(t.response,t.status??200,t.responseHeaders)})()))},E=e=>{const{type:s,rule:o}=e.data||{};s==="ADD_RULE"&&(c=c.filter(t=>t.alias!==o.alias),c.push(o),console.log("[TWD] Rule added:",o)),s==="CLEAR_RULES"&&(c=[],console.log("[TWD] All rules cleared"))};self.addEventListener("install",()=>{self.skipWaiting()});self.addEventListener("activate",e=>{e.waitUntil(self.clients.claim())});console.log(`[TWD] Mock Service Worker loaded - version ${p}`);self.addEventListener("fetch",g);self.addEventListener("message",E);
|
package/dist/twd.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MockRulesButton: () => import("react/jsx-runtime").JSX.Element;
|