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/mock-sw.js CHANGED
@@ -1 +1 @@
1
- const u=e=>{try{return new RegExp(e),!0}catch{return!1}};function d(e,s,n){return n.find(t=>{const o=t.method.toLowerCase()===e.toLowerCase();if(t.urlRegex&&u(t.url)){const a=new RegExp(t.url);return o&&a.test(s)}const l=t.url===s||s.includes(t.url);return o&&l})}function f(e,s,n){e.forEach(t=>t.postMessage({type:"EXECUTED",alias:s.alias,request:n}))}const h=(e,s,n)=>{const o=![204,205,304].includes(s),l=o?JSON.stringify(e):null;return new Response(l,{status:s,headers:o?n||{"Content-Type":"application/json"}:n||{}})};let c=[];const y=async e=>{const{method:s}=e.request,n=e.request.url,t=d(s,n,c);t&&(console.log("[TWD] Mock hit:",t.alias,s,n),e.respondWith((async()=>{let o=null;const l=e.request.headers.get("content-type")||"application/json";if(l.includes("application/json"))try{o=await e.request.clone().json()}catch{}else if(l.includes("form"))try{const a=await e.request.clone().formData();o={},a.forEach((r,i)=>{o[i]=r})}catch{}else if(l.includes("text"))try{o=await e.request.clone().text()}catch{}else if(l.includes("octet-stream"))try{o=await e.request.clone().arrayBuffer()}catch{}else if(l.includes("image"))try{o=await e.request.clone().blob()}catch{}else try{o=await e.request.clone().text()}catch{}return self.clients.matchAll().then(a=>{f(a,t,o)}),h(t.response,t.status??200,t.responseHeaders)})()))},p=e=>{const{type:s,rule:n}=e.data||{};s==="ADD_RULE"&&(c=c.filter(t=>t.alias!==n.alias),c.push(n),console.log("[TWD] Rule added:",n)),s==="CLEAR_RULES"&&(c=[],console.log("[TWD] All rules cleared"))};console.log("[TWD] Mock Service Worker loaded - version 0.7.1");self.addEventListener("fetch",y);self.addEventListener("message",p);
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
@@ -52,7 +52,7 @@ interface TWDAPI {
52
52
  *
53
53
  * ```
54
54
  */
55
- visit: (url: string) => void;
55
+ visit: (url: string) => Promise<void>;
56
56
  /**
57
57
  * Mock a network request.
58
58
  *
@@ -0,0 +1,2 @@
1
+ declare const MockRequestIcon: () => import("react/jsx-runtime").JSX.Element;
2
+ export default MockRequestIcon;
@@ -0,0 +1 @@
1
+ export declare const MockRulesButton: () => import("react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twd-js",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Test While Developing (TWD) - in-browser testing",
5
5
  "license": "MIT",
6
6
  "author": "BRIKEV",