mockforme 2.1.0 → 3.0.0-alpha.1

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/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html><head><meta charset="utf-8"><title>mockforme - The best way to mock your APIs</title><meta name="viewport" content="width=device-width,initial-scale=1"><script defer="defer" src="mockforme.min.js"></script></head><body></body></html>
1
+ <!doctype html><html><head><meta charset="utf-8"><title>mockforme - The best way to mock your APIs</title><meta name="viewport" content="width=device-width,initial-scale=1"><script defer="defer" src="mockforme.client.esm.js"></script></head><body></body></html>
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var t={d:(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{mockforme:()=>l});const o=t=>{try{return t?t.toLowerCase():t}catch(t){return console.log(t),null}},r=()=>"undefined"==typeof window,n=function(t,e,o){const n=r();var i;function a(){if(4==i.readyState)if(i.status.toString().match(/^20[0-9]$/)){var t=function(){var t=i.getResponseHeader("Content-Type"),e=i.responseText;if(t){var o=t.split(";");try{return"application/json"===o[0]?JSON.parse(e):e}catch(t){throw"Unable to convert response header"}}}();e.call(this,t,i)}else o.call(this,i.responseText,i)}function s(t,e){var o=[];for(var r in t)if(t.hasOwnProperty(r)){var n=e?e+"["+r+"]":r,i=t[r];o.push("object"==typeof i?s(i,n):encodeURIComponent(n)+"="+encodeURIComponent(i))}return o.join("&")}return n||(window.XMLHttpRequest?i=new XMLHttpRequest:window.ActiveXObject&&(i=new ActiveXObject("Microsoft.XMLHTTP"))),{request:function(){if(!n){if(window.XMLHttpRequest)i.onload=a;else{if(!window.ActiveXObject)throw"unable to process ajax";i.onreadystatechange=a}var e=s(t.params);if("get"==t.method.toLowerCase()&&"object"==typeof t.params){if(-1==t.url.indexOf("?"))t.url+="?";else{var o=t.url.split("?");o[1]&&o[1].split("=")[1]&&(t.url+="&")}t.url+=e}t.hasOwnProperty("async")||(t.async=!0),i.open(t.method,t.url,t.async),t.headers&&function(t){for(let e in t)i.setRequestHeader(e,t[e])}(t.headers),i.send(e)}}}},i=(t,e)=>{const o=t.split("/"),r=e.split("/");if(o.length!==r.length)return!1;for(let t=0;t<o.length;t++){const e=o[t];if(e!==r[t]&&":any"!==e)return!1}return!0},a=t=>{if(r())return;const e="https://dashboard.mockforme.com",a=`${e}/mockforme`,s=`${e}/gateway/_mfm_`,c="mockforme";let l=[];const d=window.location,p=d.protocol;if(d.host,d.port,!t)throw"mockforme token cannot be null";const u=(t,e="get")=>{let r=null;if(!Array.isArray(l))return r;for(let n=0;n<l.length;n++){const a=l[n];if(o(a.apiMethod)===o(e)&&(a.apiEndpoint===t||i(a.apiEndpoint,t))){r={url:t,method:a.apiMethod},a._ri_&&(r._ri_=a._ri_);break}}return r},h=()=>{(()=>{const e=window.fetch;window.fetch=function(o,r={}){r.method||(r.method="get");let n=arguments;o&&(o.startsWith("//")?o=`${window.location.protocol}${o}`:o.startsWith("/")&&(o=`${window.location.origin}${o}`));const i=new URL(o),s=i&&i.pathname,l=i&&i.search,d=u(s,r.method);return d&&(o=`${a}${d.url}${l}`,n[0]=o,r.headers={[c]:t},d&&d._ri_&&(r.headers._ri_=d._ri_)),e.call(this,o,r)}})(),(()=>{let e=window.XMLHttpRequest.prototype.open;window.XMLHttpRequest.prototype.open=function(o,r,n,i,s){try{r&&(r.startsWith("//")?r=`${window.location.protocol}${r}`:r.startsWith("/")?r=`${window.location.origin}${r}`:r.indexOf("://")>-1||(r=`${p}//${r}`));const n=new URL(r),i=n&&n.pathname,s=n&&n.search;let l=arguments;const d=u(i,o);return d&&(l[1]=`${a}${d.url}${s}`),this.onreadystatechange=function(){1==this.readyState&&(this.setRequestHeader(c,t),d&&d._ri_&&this.setRequestHeader("_ri_",d._ri_))},e.apply(this,l)}catch(t){return console.log("Error in mock api, could be invalid url",t),e.apply(this,arguments)}}})()};return{run:t=>{var e;h(),e=e=>{t&&t(e)},n({method:"get",url:s,async:!1},(t=>{var o;t&&(o=t,l=l.concat(o)),e(t)}),(()=>{console.log("Error in loading mocked apis")})).request()}}},s=r();s||(window.mockforme=a);let c=a;s&&(c=t=>({run:()=>{}}));const l=c;module.exports=e})();
@@ -0,0 +1 @@
1
+ var t={d:(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{_:()=>l});const o=t=>{try{return t?t.toLowerCase():t}catch(t){return console.log(t),null}},r=()=>"undefined"==typeof window,n=function(t,e,o){const n=r();var i;function a(){if(4==i.readyState)if(i.status.toString().match(/^20[0-9]$/)){var t=function(){var t=i.getResponseHeader("Content-Type"),e=i.responseText;if(t){var o=t.split(";");try{return"application/json"===o[0]?JSON.parse(e):e}catch(t){throw"Unable to convert response header"}}}();e.call(this,t,i)}else o.call(this,i.responseText,i)}function s(t,e){var o=[];for(var r in t)if(t.hasOwnProperty(r)){var n=e?e+"["+r+"]":r,i=t[r];o.push("object"==typeof i?s(i,n):encodeURIComponent(n)+"="+encodeURIComponent(i))}return o.join("&")}return n||(window.XMLHttpRequest?i=new XMLHttpRequest:window.ActiveXObject&&(i=new ActiveXObject("Microsoft.XMLHTTP"))),{request:function(){if(!n){if(window.XMLHttpRequest)i.onload=a;else{if(!window.ActiveXObject)throw"unable to process ajax";i.onreadystatechange=a}var e=s(t.params);if("get"==t.method.toLowerCase()&&"object"==typeof t.params){if(-1==t.url.indexOf("?"))t.url+="?";else{var o=t.url.split("?");o[1]&&o[1].split("=")[1]&&(t.url+="&")}t.url+=e}t.hasOwnProperty("async")||(t.async=!0),i.open(t.method,t.url,t.async),t.headers&&function(t){for(let e in t)i.setRequestHeader(e,t[e])}(t.headers),i.send(e)}}}},i=(t,e)=>{const o=t.split("/"),r=e.split("/");if(o.length!==r.length)return!1;for(let t=0;t<o.length;t++){const e=o[t];if(e!==r[t]&&":any"!==e)return!1}return!0},a=t=>{if(r())return;const e="https://dashboard.mockforme.com",a=`${e}/mockforme`,s=`${e}/gateway/_mfm_`,c="mockforme";let l=[];const p=window.location,d=p.protocol;if(p.host,p.port,!t)throw"mockforme token cannot be null";const u=(t,e="get")=>{let r=null;if(!Array.isArray(l))return r;for(let n=0;n<l.length;n++){const a=l[n];if(o(a.apiMethod)===o(e)&&(a.apiEndpoint===t||i(a.apiEndpoint,t))){r={url:t,method:a.apiMethod},a._ri_&&(r._ri_=a._ri_);break}}return r},h=()=>{(()=>{const e=window.fetch;window.fetch=function(o,r={}){r.method||(r.method="get");let n=arguments;o&&(o.startsWith("//")?o=`${window.location.protocol}${o}`:o.startsWith("/")&&(o=`${window.location.origin}${o}`));const i=new URL(o),s=i&&i.pathname,l=i&&i.search,p=u(s,r.method);return p&&(o=`${a}${p.url}${l}`,n[0]=o,r.headers={[c]:t},p&&p._ri_&&(r.headers._ri_=p._ri_)),e.call(this,o,r)}})(),(()=>{let e=window.XMLHttpRequest.prototype.open;window.XMLHttpRequest.prototype.open=function(o,r,n,i,s){try{r&&(r.startsWith("//")?r=`${window.location.protocol}${r}`:r.startsWith("/")?r=`${window.location.origin}${r}`:r.indexOf("://")>-1||(r=`${d}//${r}`));const n=new URL(r),i=n&&n.pathname,s=n&&n.search;let l=arguments;const p=u(i,o);return p&&(l[1]=`${a}${p.url}${s}`),this.onreadystatechange=function(){1==this.readyState&&(this.setRequestHeader(c,t),p&&p._ri_&&this.setRequestHeader("_ri_",p._ri_))},e.apply(this,l)}catch(t){return console.log("Error in mock api, could be invalid url",t),e.apply(this,arguments)}}})()};return{run:t=>{var e;h(),e=e=>{t&&t(e)},n({method:"get",url:s,async:!1},(t=>{var o;t&&(o=t,l=l.concat(o)),e(t)}),(()=>{console.log("Error in loading mocked apis")})).request()}}},s=r();s||(window.mockforme=a);let c=a;s&&(c=t=>({run:()=>{}}));const l=c;var p=e._;export{p as mockforme};
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{mockforme:()=>p});const o=require("http");var n=e.n(o);const r=require("https");var i=e.n(r);const s=require("child_process");class a{constructor(e){this.token=e,this.apiMappings=[],this.isReady=!1,this.originalHttpRequest=n().request,this.originalHttpGet=n().get,this.originalHttpsRequest=i().request,this.originalHttpsGet=i().get,this.originalFetch=globalThis.fetch,this.fetchApiMappings(),this.setupInterceptor()}fetchApiMappings(){try{const e=`curl -s -H "mockforme: ${this.token}" "https://dashboard.mockforme.com/gateway/_mfm_"`,t=(0,s.execSync)(e,{encoding:"utf8"});this.apiMappings=JSON.parse(t),this.isReady=!0,console.log("Mockforme mappings loaded:",this.apiMappings)}catch(e){console.error("Failed to fetch mappings:",e.message)}}setupInterceptor(){const e=this;n().request=function(...t){return e.handleIntercept(e.originalHttpRequest,t)},i().request=function(...t){return e.handleIntercept(e.originalHttpsRequest,t)},n().get=function(...t){return e.handleIntercept(e.originalHttpGet,t)},i().get=function(...t){return e.handleIntercept(e.originalHttpsGet,t)},globalThis.fetch=async function(t,o={}){if(!e.isReady)return console.warn("⚠️ Interceptor not ready, sending fetch request normally."),e.originalFetch(t,o);let n=t;"string"==typeof t?n=new URL(t,"http://localhost"):t instanceof Request&&(n=new URL(t.url));const r=e.interceptFetch(n,o);return e.originalFetch(r.url,r.init)},console.log("🚀 Mockforme interceptor is now active for all HTTP requests.")}handleIntercept(e,t){let o=t[0];if("string"==typeof o&&(o=new URL(o)),!this.isReady)return console.warn("⚠️ Interceptor not ready, sending request normally."),e.apply(null,[o,...t.slice(1)]);const n=this.interceptRequest(o);return e.apply(null,[n,...t.slice(1)])}interceptRequest(e){const t=this.apiMappings.find((t=>t.apiEndpoint===e.path&&t.apiMethod.toLowerCase()===e.method.toLowerCase()));return t?(console.log(`🔄 Redirecting: ${e.method.toUpperCase()} ${e.path} → /mockforme${t.apiEndpoint}`),{...e,hostname:"dashboard.mockforme.com",path:`/mockforme${t.apiEndpoint}`,headers:{...e.headers,mockforme:this.token}}):e}interceptFetch(e,t){const o=(t.method||"GET").toUpperCase(),n=this.apiMappings.find((t=>t.apiEndpoint===e.pathname&&t.apiMethod.toLowerCase()===o.toLowerCase()));return n?(console.log(`🔄 Fetch Redirecting: ${o} ${e.pathname} → /mockforme${n.apiEndpoint}`),{url:`https://dashboard.mockforme.com/mockforme${n.apiEndpoint}`,init:{...t,headers:{...t.headers,mockforme:this.token}}}):{url:e.href,init:t}}run(){console.log("🔄 Mockforme is already running.")}}function p(e){return new a(e)}module.exports=t})();
@@ -0,0 +1 @@
1
+ import{createRequire as e}from"node:module";var t={n:e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o},d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},o={};t.d(o,{_:()=>c});const n=e(import.meta.url)("http");var r=t.n(n);const i=e(import.meta.url)("https");var s=t.n(i);const a=e(import.meta.url)("child_process");class p{constructor(e){this.token=e,this.apiMappings=[],this.isReady=!1,this.originalHttpRequest=r().request,this.originalHttpGet=r().get,this.originalHttpsRequest=s().request,this.originalHttpsGet=s().get,this.originalFetch=globalThis.fetch,this.fetchApiMappings(),this.setupInterceptor()}fetchApiMappings(){try{const e=`curl -s -H "mockforme: ${this.token}" "https://dashboard.mockforme.com/gateway/_mfm_"`,t=(0,a.execSync)(e,{encoding:"utf8"});this.apiMappings=JSON.parse(t),this.isReady=!0,console.log("Mockforme mappings loaded:",this.apiMappings)}catch(e){console.error("Failed to fetch mappings:",e.message)}}setupInterceptor(){const e=this;r().request=function(...t){return e.handleIntercept(e.originalHttpRequest,t)},s().request=function(...t){return e.handleIntercept(e.originalHttpsRequest,t)},r().get=function(...t){return e.handleIntercept(e.originalHttpGet,t)},s().get=function(...t){return e.handleIntercept(e.originalHttpsGet,t)},globalThis.fetch=async function(t,o={}){if(!e.isReady)return console.warn("⚠️ Interceptor not ready, sending fetch request normally."),e.originalFetch(t,o);let n=t;"string"==typeof t?n=new URL(t,"http://localhost"):t instanceof Request&&(n=new URL(t.url));const r=e.interceptFetch(n,o);return e.originalFetch(r.url,r.init)},console.log("🚀 Mockforme interceptor is now active for all HTTP requests.")}handleIntercept(e,t){let o=t[0];if("string"==typeof o&&(o=new URL(o)),!this.isReady)return console.warn("⚠️ Interceptor not ready, sending request normally."),e.apply(null,[o,...t.slice(1)]);const n=this.interceptRequest(o);return e.apply(null,[n,...t.slice(1)])}interceptRequest(e){const t=this.apiMappings.find((t=>t.apiEndpoint===e.path&&t.apiMethod.toLowerCase()===e.method.toLowerCase()));return t?(console.log(`🔄 Redirecting: ${e.method.toUpperCase()} ${e.path} → /mockforme${t.apiEndpoint}`),{...e,hostname:"dashboard.mockforme.com",path:`/mockforme${t.apiEndpoint}`,headers:{...e.headers,mockforme:this.token}}):e}interceptFetch(e,t){const o=(t.method||"GET").toUpperCase(),n=this.apiMappings.find((t=>t.apiEndpoint===e.pathname&&t.apiMethod.toLowerCase()===o.toLowerCase()));return n?(console.log(`🔄 Fetch Redirecting: ${o} ${e.pathname} → /mockforme${n.apiEndpoint}`),{url:`https://dashboard.mockforme.com/mockforme${n.apiEndpoint}`,init:{...t,headers:{...t.headers,mockforme:this.token}}}):{url:e.href,init:t}}run(){console.log("🔄 Mockforme is already running.")}}function c(e){return new p(e)}var l=o._;export{l as mockforme};
package/package.json CHANGED
@@ -1,9 +1,20 @@
1
1
  {
2
2
  "name": "mockforme",
3
- "version": "2.1.0",
3
+ "version": "3.0.0-alpha.1",
4
4
  "description": "mockforme client integration kit. Intercept APIs & get mock responses. Integrate mockforme SDK with your codebase in seconds",
5
- "main": "dist/mockforme.min.js",
6
- "typings": "dist/mockforme.d.ts",
5
+ "main": "dist/mockforme.client.cjs.js",
6
+ "module": "dist/mockforme.client.esm.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/mockforme.client.esm.js",
10
+ "require": "./dist/mockforme.client.cjs.js"
11
+ },
12
+ "./server": {
13
+ "import": "./dist/mockforme.server.esm.js",
14
+ "require": "./dist/mockforme.server.cjs.js"
15
+ }
16
+ },
17
+ "types": "dist/mockforme.d.ts",
7
18
  "files": [
8
19
  "dist/*"
9
20
  ],
@@ -21,11 +32,13 @@
21
32
  "mock for me"
22
33
  ],
23
34
  "scripts": {
24
- "build": "webpack"
35
+
25
36
  },
26
37
  "author": "team mockforme",
27
38
  "license": "ISC",
28
39
  "homepage": "https://www.mockforme.com",
29
40
  "dependencies": {},
30
- "devDependencies": {}
41
+ "devDependencies": {
42
+
43
+ }
31
44
  }
@@ -1 +0,0 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var o=t();for(var r in o)("object"==typeof exports?exports:e)[r]=o[r]}}(this,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{mockforme:()=>l});const o=e=>{try{return e?e.toLowerCase():e}catch(e){return console.log(e),null}},r=()=>"undefined"==typeof window,n=function(e,t,o){const n=r();var i;function s(){if(4==i.readyState)if(i.status.toString().match(/^20[0-9]$/)){var e=function(){var e=i.getResponseHeader("Content-Type"),t=i.responseText;if(e){var o=e.split(";");try{return"application/json"===o[0]?JSON.parse(t):t}catch(e){throw"Unable to convert response header"}}}();t.call(this,e,i)}else o.call(this,i.responseText,i)}function a(e,t){var o=[];for(var r in e)if(e.hasOwnProperty(r)){var n=t?t+"["+r+"]":r,i=e[r];o.push("object"==typeof i?a(i,n):encodeURIComponent(n)+"="+encodeURIComponent(i))}return o.join("&")}return n||(window.XMLHttpRequest?i=new XMLHttpRequest:window.ActiveXObject&&(i=new ActiveXObject("Microsoft.XMLHTTP"))),{request:function(){if(!n){if(window.XMLHttpRequest)i.onload=s;else{if(!window.ActiveXObject)throw"unable to process ajax";i.onreadystatechange=s}var t=a(e.params);if("get"==e.method.toLowerCase()&&"object"==typeof e.params){if(-1==e.url.indexOf("?"))e.url+="?";else{var o=e.url.split("?");o[1]&&o[1].split("=")[1]&&(e.url+="&")}e.url+=t}e.hasOwnProperty("async")||(e.async=!0),i.open(e.method,e.url,e.async),e.headers&&function(e){for(let t in e)i.setRequestHeader(t,e[t])}(e.headers),i.send(t)}}}},i=(e,t)=>{const o=e.split("/"),r=t.split("/");if(o.length!==r.length)return!1;for(let e=0;e<o.length;e++){const t=o[e];if(t!==r[e]&&":any"!==t)return!1}return!0},s=e=>{if(r())return;const t="https://dashboard.mockforme.com",s=`${t}/mockforme`,a=`${t}/gateway/_mfm_`,c="mockforme";let l=[];const p=window.location,d=p.protocol;if(p.host,p.port,!e)throw"mockforme token cannot be null";const u=(e,t="get")=>{let r=null;if(!Array.isArray(l))return r;for(let n=0;n<l.length;n++){const s=l[n];if(o(s.apiMethod)===o(t)&&(s.apiEndpoint===e||i(s.apiEndpoint,e))){r={url:e,method:s.apiMethod},s._ri_&&(r._ri_=s._ri_);break}}return r},f=()=>{(()=>{const t=window.fetch;window.fetch=function(o,r={}){r.method||(r.method="get");let n=arguments;o&&(o.startsWith("//")?o=`${window.location.protocol}${o}`:o.startsWith("/")&&(o=`${window.location.origin}${o}`));const i=new URL(o),a=i&&i.pathname,l=i&&i.search,p=u(a,r.method);return p&&(o=`${s}${p.url}${l}`,n[0]=o,r.headers={[c]:e},p&&p._ri_&&(r.headers._ri_=p._ri_)),t.call(this,o,r)}})(),(()=>{let t=window.XMLHttpRequest.prototype.open;window.XMLHttpRequest.prototype.open=function(o,r,n,i,a){try{r&&(r.startsWith("//")?r=`${window.location.protocol}${r}`:r.startsWith("/")?r=`${window.location.origin}${r}`:r.indexOf("://")>-1||(r=`${d}//${r}`));const n=new URL(r),i=n&&n.pathname,a=n&&n.search;let l=arguments;const p=u(i,o);return p&&(l[1]=`${s}${p.url}${a}`),this.onreadystatechange=function(){1==this.readyState&&(this.setRequestHeader(c,e),p&&p._ri_&&this.setRequestHeader("_ri_",p._ri_))},t.apply(this,l)}catch(e){return console.log("Error in mock api, could be invalid url",e),t.apply(this,arguments)}}})()};return{run:e=>{var t;f(),t=t=>{e&&e(t)},n({method:"get",url:a,async:!1},(e=>{var o;e&&(o=e,l=l.concat(o)),t(e)}),(()=>{console.log("Error in loading mocked apis")})).request()}}},a=r();a||(window.mockforme=s);let c=s;a&&(c=e=>({run:()=>{console.log("node mockforme(t).run()")}}));const l=c;return t})()));