mockforme 2.0.0 → 2.1.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/README.md CHANGED
@@ -22,7 +22,7 @@ yarn add mockforme
22
22
 
23
23
  * Import the package in your code
24
24
  ```
25
- import mockforme from 'mockforme';
25
+ import { mockforme } from 'mockforme';
26
26
  ```
27
27
  * Initialize the SDK using Access Token (Generate access token [here](https://dashboard.mockforme.com/user/token))
28
28
  ```
@@ -1 +1 @@
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,(function(){return(()=>{"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{switch(o[0]){case"application/json":return JSON.parse(t);default:return 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 u=window.location,d=u.protocol;if(u.host,u.port,!e)throw"mockforme token cannot be null";const p=(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,u=p(a,r.method);return u&&(o=`${s}${u.url}${l}`,n[0]=o,r.headers={[c]:e},u&&u._ri_&&(r.headers._ri_=u._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 u=p(i,o);return u&&(l[1]=`${s}${u.url}${a}`),this.onreadystatechange=function(){1==this.readyState&&(this.setRequestHeader(c,e),u&&u._ri_&&this.setRequestHeader("_ri_",u._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})()}));
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})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mockforme",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "mockforme client integration kit. Intercept APIs & get mock responses. Integrate mockforme SDK with your codebase in seconds",
5
5
  "main": "dist/mockforme.min.js",
6
6
  "typings": "dist/mockforme.d.ts",