mockforme 3.0.0-alpha.1 → 3.0.0-alpha.2

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
@@ -20,23 +20,44 @@ yarn add mockforme
20
20
 
21
21
  ### How to use? ###
22
22
 
23
- * Import the package in your code
24
- ```
25
- import { mockforme } from 'mockforme';
26
- ```
23
+ ### CLIENT SIDE INTEGRATION
24
+ * Import the package in your code for client side
25
+ ```
26
+ import { mockforme } from 'mockforme';
27
+ ```
27
28
  * Initialize the SDK using Access Token (Generate access token [here](https://dashboard.mockforme.com/user/token))
28
- ```
29
- mockforme('<ACCESS_TOKEN>').run();
30
- ```
29
+ ```
30
+ mockforme('<ACCESS_TOKEN>').run();
31
+ ```
31
32
 
32
33
  * You can also access mockforme object in your browser from window object:
33
- ```
34
- window.mockforme
35
- ```
36
- And initialize it directly from window:
37
- ```
38
- window.mockforme('<ACCESS_TOKEN>').run();
39
- ```
34
+ ```
35
+ window.mockforme
36
+ ```
37
+ And initialize it directly from window:
38
+ ```
39
+ window.mockforme('<ACCESS_TOKEN>').run();
40
+ ```
41
+
42
+ * You can also directly use mockforme through script file using jsdelivr CDN.
43
+ ```
44
+ <script src="https://cdn.jsdelivr.net/npm/mockforme@3.0.0-alpha.2/dist/mockforme.client.umd.js"></script>
45
+
46
+ <script>
47
+ window.mockforme
48
+ window.mockforme('<ACCESS_TOKEN>').run();
49
+ </script>
50
+ ```
51
+
52
+ ### SERVER SIDE INTEGRATION
53
+ * Import the package in your code for server side
54
+ ```
55
+ import { mockforme } from 'mockforme/server';
56
+ ```
57
+ * Initialize the SDK using Access Token (Generate access token [here](https://dashboard.mockforme.com/user/token))
58
+ ```
59
+ mockforme('<ACCESS_TOKEN>').run();
60
+ ```
40
61
 
41
62
  ## Example
42
63
  [https://codesandbox.io/p/sandbox/wizardly-gagarin-smlf7z](https://codesandbox.io/p/sandbox/wizardly-gagarin-smlf7z)
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mockforme=e():t.mockforme=e()}(this,(()=>(()=>{"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)},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 s(){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 a(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?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 e=a(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},s=t=>{if(r())return;const e="https://dashboard.mockforme.com",s=`${e}/mockforme`,a=`${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 s=l[n];if(o(s.apiMethod)===o(e)&&(s.apiEndpoint===t||i(s.apiEndpoint,t))){r={url:t,method:s.apiMethod},s._ri_&&(r._ri_=s._ri_);break}}return r},f=()=>{(()=>{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),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]: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,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,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;f(),e=e=>{t&&t(e)},n({method:"get",url:a,async:!1},(t=>{var o;t&&(o=t,l=l.concat(o)),e(t)}),(()=>{console.log("Error in loading mocked apis")})).request()}}},a=r();a||(window.mockforme=s);let c=s;a&&(c=t=>({run:()=>{}}));const l=c;return e.mockforme})()));
package/package.json CHANGED
@@ -1,20 +1,22 @@
1
1
  {
2
2
  "name": "mockforme",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-alpha.2",
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.client.cjs.js",
6
6
  "module": "dist/mockforme.client.esm.js",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./dist/mockforme.client.esm.js",
10
- "require": "./dist/mockforme.client.cjs.js"
10
+ "require": "./dist/mockforme.client.cjs.js",
11
+ "types": "./dist/mockforme.d.ts"
11
12
  },
12
13
  "./server": {
13
14
  "import": "./dist/mockforme.server.esm.js",
14
- "require": "./dist/mockforme.server.cjs.js"
15
+ "require": "./dist/mockforme.server.cjs.js",
16
+ "types": "./dist/mockforme.d.ts"
15
17
  }
16
18
  },
17
- "types": "dist/mockforme.d.ts",
19
+ "types": "./dist/mockforme.d.ts",
18
20
  "files": [
19
21
  "dist/*"
20
22
  ],
@@ -32,7 +34,7 @@
32
34
  "mock for me"
33
35
  ],
34
36
  "scripts": {
35
-
37
+
36
38
  },
37
39
  "author": "team mockforme",
38
40
  "license": "ISC",