New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mockyeah/fetch

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mockyeah/fetch - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

dist/main.js

@@ -1,1 +0,1 @@

module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=23)}([function(e,t){e.exports=require("@babel/runtime/regenerator")},function(e,t){e.exports=require("lodash/isPlainObject")},function(e,t){e.exports=require("assert")},function(e,t){e.exports=require("@babel/runtime/helpers/asyncToGenerator")},function(e,t){e.exports=require("debug")},function(e,t){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,t){e.exports=require("@babel/runtime/helpers/slicedToArray")},function(e,t){e.exports=require("qs")},function(e,t){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,t){e.exports=require("url")},function(e,t){e.exports=require("match-deep")},function(e,t){e.exports=require("lodash/isEmpty")},function(e,t){e.exports=require("lodash/isEqual")},function(e,t){e.exports=require("@babel/runtime/helpers/classCallCheck")},function(e,t){e.exports=require("@babel/runtime/helpers/createClass")},function(e,t){e.exports=require("lodash/flatten")},function(e,t){e.exports=require("cookie")},function(e,t){e.exports=require("lodash/isRegExp")},function(e,t){e.exports=require("lodash/mapValues")},function(e,t){e.exports=require("path-to-regexp")},function(e,t){e.exports=require("mime")},function(e,t){e.exports=require("@babel/runtime/helpers/typeof")},function(e,t){e.exports=require("lodash/fromPairs")},function(e,t,r){"use strict";r.r(t);var n=r(0),o=r.n(n),a=r(8),i=r.n(a),c=r(6),s=r.n(c),u=r(3),l=r.n(u),f=r(13),p=r.n(f),h=r(14),d=r.n(h),v=r(5),m=r.n(v),y=r(9),k=r(7),x=r.n(k),b=r(1),g=r.n(b),w=r(15),O=r.n(w),P=r(16),q=r.n(P),_=r(4),S=r.n(_),j=r(10),E=r.n(j),W=r(19),T=r.n(W),R=r(11),$=r.n(R),D=r(17),C=r.n(D),H=r(18),M=r.n(H);function I(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function L(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?I(Object(r),!0).forEach((function(t){m()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):I(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var F=/^(\/?https?.{3}[^/:?]+):/,N=/^(\/?https?).{3}/,U=/^(\/?https?.{3}[^/:?]+)~/,A=/^(\/?https?).{3}/,K=function(e){return e.replace(A,"$1://").replace(U,"$1:")},J=function(e){return e.replace(F,"$1~").replace(N,"$1~~~")},B=/^\//,V=/^(https?)%3A%2F%2F/,X=function(e){return/^\/+https?[:~][/~]{2}/.test(e)?K(function(e){return e.replace(B,"")}(e).replace(V,(function(e,t){return"".concat(t,"://")}))):e},Y=function(e,t){if("function"==typeof e)return e;var r,n=g()(e)?L({},e):e;(r=g()(e)?L({},e):{url:e}).query=$()(r.query)?void 0:r.query,r.headers=$()(r.headers)?void 0:Object.entries(r.headers).reduce((function(e,t){var r=s()(t,2),n=r[0],o=r[1];return e[n.toLowerCase()]=o,e}),{}),r.method&&"all"!==r.method&&"ALL"!==r.method&&"*"!==r.method?"string"==typeof r.method&&(r.method=r.method.toLowerCase()):delete r.method;var o=L({},r.$meta||{});if(r.path&&(r.url=r.path,delete r.path),"*"===r.url&&delete r.url,"string"==typeof r.url){r.url=X(r.url);var a=function(e){var t;return/^https?:/.test(e)?(t=Object(y.parse)(e),e="".concat(t.protocol||"http:","//").concat(t.hostname).concat(t.port&&!["80","443"].includes(t.port)?":".concat(t.port):"").concat(t.pathname)):(t=Object(y.parse)("http://example.com".concat(e.startsWith("/")?e:"/".concat(e))),e=t.pathname||""),{url:e,query:t.query?x.a.parse(t.query):void 0}}(r.url);r.url=a.url.replace(/\/+$/,"")||"/",r.query=g()(r.query)?L({},a.query,{},r.query):r.query||a.query}$()(r.query)&&delete r.query,$()(r.cookies)&&delete r.cookies;var i=L({},r);r.url||(i.url="*"),o.original=n,o.originalNormal=i,o.originalSerialized=function e(t){return M()(t,(function(t){return C()(t)?{$regex:{source:t.source,flags:t.flags}}:g()(t)?M()(t,(function(t){return e(t)})):t}))}(i);var c=r.url;if("string"==typeof r.url){if(!t){var u=[],l=T()(J(r.url),u);r.url=function(e){return l.test(J(e)||J("/".concat(e)))},o.regex=l,o.matchKeys=u,o.fn=r.url.toString(),r.url.toStringForMatchDeep=function(){return'"'.concat(null==c?void 0:c.toString(),'"')}}}else if(C()(r.url)){if(!t){var f=r.url;r.url=function(e){return f.test(K(e))||f.test(K("/".concat(e)))},o.regex=f,o.fn=r.url.toString(),r.url.toStringForMatchDeep=function(){return null==c?void 0:c.toString()}}}else if("function"==typeof r.url){var p=r.url;r.url=function(e){return p(e)||p("/".concat(e))}}return L({},r,{$meta:o})},z=r(12),G=r.n(z),Q=function(e,t){var r=e.$meta?e.$meta.originalNormal:void 0,n=t.$meta?t.$meta.originalNormal:void 0;return g()(r)&&g()(n)?!(!r||!n)&&(r.url===n.url&&r.path===n.path&&r.method===n.method&&G()(r.query,n.query)&&G()(r.body,n.body)&&G()(r.headers,n.headers)&&G()(r.cookies,n.cookies)):r===n},Z=r(20),ee=r.n(Z);function te(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function re(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?te(Object(r),!0).forEach((function(t){m()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):te(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var ne=function(e,t,r){return"function"==typeof e?e(t,r):e},oe=function(){var e=l()(o.a.mark((function e(t,r,n,a){var i,c,s,u,l,f,p,h,d,v,m,y,k,x,b,g;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=n.responseHeaders,c=n.fixtureResolver,s=n.fileResolver,u=t[1]||{},l=u.name,e.t1=u.status,!e.t1){e.next=8;break}return e.next=7,ne(u.status,r,a);case 7:e.t1=e.sent;case 8:if(e.t0=e.t1,e.t0){e.next=11;break}e.t0=200;case 11:if(f=e.t0,e.t2=u.type,!e.t2){e.next=17;break}return e.next=16,ne(u.type,r,a);case 16:e.t2=e.sent;case 17:if(h=e.t2,!u.fixture){e.next=35;break}if(c){e.next=21;break}throw new Error("Using `fixture` in mock response options requires a `fixtureResolver`.");case 21:return e.next=23,ne(u.fixture,r,a);case 23:if(m=e.sent,h=h||m,!m){e.next=31;break}return e.next=28,c(m);case 28:e.t3=e.sent,e.next=32;break;case 31:e.t3=void 0;case 32:p=e.t3,e.next=79;break;case 35:if(!u.filePath){e.next=52;break}if(s){e.next=38;break}throw new Error("Using `filePath` in mock response options requires a `fileResolver`.");case 38:return e.next=40,ne(u.filePath,r,a);case 40:if(y=e.sent,h=h||y,!y){e.next=48;break}return e.next=45,s(y);case 45:e.t4=e.sent,e.next=49;break;case 48:e.t4=void 0;case 49:p=e.t4,e.next=79;break;case 52:if(!u.json){e.next=60;break}return e.next=55,ne(u.json,r,a);case 55:v=e.sent,p=JSON.stringify(v),d="application/json; charset=UTF-8",e.next=79;break;case 60:if(!u.text){e.next=67;break}return e.next=63,ne(u.text,r,a);case 63:p=e.sent,d="text/plain; charset=UTF-8",e.next=79;break;case 67:if(!u.html){e.next=74;break}return e.next=70,ne(u.html,r,a);case 70:p=e.sent,d="text/html; charset=UTF-8",e.next=79;break;case 74:if(!u.raw){e.next=79;break}return e.next=77,ne(u.raw,r,a);case 77:p=e.sent,d=void 0;case 79:if(p=p||"",d=h?ee.a.getType(h)||h:d,!(k=u.latency||n.latency)){e.next=88;break}return e.next=85,ne(k,r,a);case 85:return x=e.sent,e.next=88,new Promise((function(e){return setTimeout(e,x)}));case 88:if(!u.headers){e.next=97;break}return e.t6=re,e.t7={},e.next=93,ne(u.headers,r,a);case 93:e.t8=e.sent,e.t5=(0,e.t6)(e.t7,e.t8),e.next=98;break;case 97:e.t5={};case 98:return b=e.t5,i&&(b["x-mockyeah-mocked"]="true",l&&(b["x-mockyeah-name"]=l),m&&(b["x-mockyeah-fixture"]=m),y&&(b["x-mockyeah-filePath"]=y),x&&(b["x-mockyeah-latency"]=x.toString())),d&&(b["content-type"]=d),g=new Response(p,{status:f,headers:b}),e.abrupt("return",{response:g,body:p,headers:b,json:v});case 104:case"end":return e.stop()}}),e)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),ae=r(21),ie=r.n(ae),ce=r(2),se=r.n(ce),ue=function(e){return e&&(e instanceof Promise||!(!e.then||!e.catch))},le=function(e,t,r){var n=E()(e,t,{skipKeys:["$meta"]}),o=n.result,a=n.message;se()(o,"".concat(r,": ").concat(a))},fe=function(){function e(t){p()(this,e);var r=t.$meta&&t.$meta.originalNormal?t.$meta.originalNormal:t;this.prefix="[".concat(r.method||"all","] ").concat(r.path||r.url," --"),this.called=0,this.assertions=[],this.handlers=[],this.verifier=this.verifier.bind(this),this.run=this.run.bind(this),this.verify=this.verify.bind(this)}return d()(e,[{key:"request",value:function(e){var t=this;this.called+=1,this.handlers.forEach((function(r){t.assertions.push(r.bind(t,e))}))}},{key:"api",value:function(e){var t=this;if("function"==typeof e){var r=e;this.handlers.push((function(e){try{var n=r(e);if(void 0!==n&&!n)throw new Error("function returned false")}catch(e){var o="".concat(t.prefix," Expect function did not match").concat(e&&e.message?": ".concat(e.message):"");se()(!1,o)}}))}else if("object"===ie()(e)){var n=Y(e);this.handlers.push((function(e){var t=E()(e,n,{skipKeys:["$meta"]}),r=t.result,o=t.message;se()(r,"Expect object did not match: ".concat(o))}))}return this}},{key:"atLeast",value:function(e){var t=this;return this.assertions.push((function(){se()(t.called>=e,"".concat(t.prefix," Expected route to be called at least ").concat(e," times, but it was called ").concat(t.called," times"))})),this}},{key:"atMost",value:function(e){var t=this;return this.assertions.push((function(){se()(t.called<=e,"".concat(t.prefix," Expected route to be called at most ").concat(e," times, but it was called ").concat(t.called," times"))})),this}},{key:"never",value:function(){var e=this;return this.assertions.push((function(){se()(0===e.called,"".concat(e.prefix," Expected route to be called never, but it was called ").concat(e.called," times"))})),this}},{key:"once",value:function(){var e=this;return this.assertions.push((function(){se()(1===e.called,"".concat(e.prefix," Expected route to be called once, but it was called ").concat(e.called," times"))})),this}},{key:"twice",value:function(){var e=this;return this.assertions.push((function(){se()(2===e.called,"".concat(e.prefix," Expected route to be called twice, but it was called ").concat(e.called," times"))})),this}},{key:"thrice",value:function(){var e=this;return this.assertions.push((function(){se()(3===e.called,"".concat(e.prefix," Expected route to be called thrice, but it was called ").concat(e.called," times"))})),this}},{key:"exactly",value:function(e){var t=this;return this.assertions.push((function(){se()(t.called===e,"".concat(t.prefix," Expected route to be called ").concat(e," times, but it was called ").concat(t.called," times"))})),this}},{key:"path",value:function(e){var t="".concat(this.prefix," Path did not match expected");return this.handlers.push((function(r){var n=r.path;le(n,e,t)})),this}},{key:"url",value:function(e){return this.path(e)}},{key:"header",value:function(e,t){var r="".concat(this.prefix,' Header "').concat(e,'" did not match expected');return this.handlers.push((function(n){le(n.headers&&(n.headers[e]||n.headers[e.toLowerCase()]),t,r)})),this}},{key:"params",value:function(e){var t="".concat(this.prefix," Params did not match expected");return this.handlers.push((function(r){le(r.query||{},e||{},t)})),this}},{key:"query",value:function(e){return this.params(e)}},{key:"body",value:function(e){var t="".concat(this.prefix," Body did not match expected");return this.handlers.push((function(r){le(r.body,e,t)})),this}},{key:"verifier",value:function(e){var t=this;return function(r){r?e(r):t.verify(e)}}},{key:"run",value:function(e){return ue(e)?this.runPromise=e:this.runPromise=new Promise((function(t,r){setTimeout((function(){var n=e((function(e){e?r(e):t()}));ue(n)&&n.then(t).catch(r)}))})),this}},{key:"verify",value:function(e){var t=this,r=function(t){if(!e)throw t;e(t)},n=function(){try{t.assertions.forEach((function(e){return e()})),e&&e()}catch(e){r(e)}};if(this.runPromise)return this.runPromise.then(n).catch(r);n()}}]),e}(),pe=function(){var e=l()(o.a.mark((function e(t){return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(204!==t.status){e.next=3;break}return e.abrupt("return","");case 3:return e.abrupt("return",t.text()||"");case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),he=function(e,t){var r=e&&e.get("Content-Type"),n=null==r?void 0:r.includes("application/json"),o=null==r?void 0:r.includes("application/x-www-form-urlencoded");if(t){if(n)return JSON.parse(t);if(o)return x.a.parse(t)}return t},de=r(22),ve=r.n(de),me=function(e){if(!e)return{};if(e.entries){var t=e.entries();return ve()(i()(t).map((function(e){return[e[0].toLowerCase(),e[1]]})))}if(e.forEach){var r={};return e.forEach((function(e,t){r[t]=e})),r}return{}},ye=function(e){var t=e.url,r=e.scope;"undefined"!=typeof navigator&&navigator.serviceWorker.register(t,{scope:r}).then((function(e){console.log("@mockyeah/fetch service worker registration succeeded.")})).catch((function(e){console.log("@mockyeah/fetch service worker registration failed.",e)}))},ke=function(e){var t;if("undefined"!=typeof navigator&&(null===(t=navigator.serviceWorker)||void 0===t?void 0:t.controller))try{navigator.serviceWorker.controller.postMessage(e)}catch(e){console.error(e)}},xe=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))},be=["json","text","html","raw","filePath","fixture","status","type","latency","headers"];function ge(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function we(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ge(Object(r),!0).forEach((function(t){m()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ge(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var Oe=S()("mockyeah:fetch:mock"),Pe=S()("mockyeah:fetch:hit"),qe=S()("mockyeah:fetch:miss"),_e=S()("mockyeah:fetch:miss:each"),Se=S()("mockyeah:fetch:error"),je=S()("mockyeah:fetch:admin"),Ee=S()("mockyeah:fetch:admin:error"),We=0,Te={},Re={},$e=function(e,t){return we({},g()(e)?e:{url:e},{method:t})},De=function(e){var t=e.name,r=void 0===t?"default":t,n=e.noProxy,o=void 0!==n&&n,a=e.prependServerURL,i=void 0!==a&&a,c=e.modifyRequest,s=e.noPolyfill,u=void 0!==s&&s,l=e.noWebSocket,f=void 0!==l&&l,p=e.host,h=void 0===p?"localhost":p,d=e.port,v=void 0===d?4001:d,m=e.portHttps,y=e.adminHost,k=void 0===y?h:y,x=e.adminPort,b=void 0===x?4777:x,g=e.suiteHeader,w=void 0===g?"x-mockyeah-suite":g,O=e.suiteCookie,P=void 0===O?"mockyeahSuite":O,q=e.latency,_=e.ignorePrefix,S=void 0===_?"http".concat(m?"s":"","://").concat(h,":").concat(m||v,"/"):_,j=e.aliases,E=void 0===j?[]:j,W=e.responseHeaders,T=void 0===W||W,R=e.fetch,$=void 0===R?global.fetch:R,D=e.fileResolver,C=e.fixtureResolver,H=e.mockSuiteResolver,M=e.devTools,I=void 0!==M&&M,L=e.devToolsTimeout,F=void 0===L?2e3:L,N=e.devToolsInterval,U=void 0===N?100:N,A=e.serviceWorker,K=e.serviceWorkerRegister,J=void 0===K?A:K,B=e.serviceWorkerURL,V=void 0===B?"/__mockyeahServiceWorker.js":B,X=e.serviceWorkerScope;return{name:r,noProxy:o,prependServerURL:i,modifyRequest:c,noPolyfill:u,noWebSocket:f,host:h,port:v,portHttps:m,adminHost:k,adminPort:b,suiteHeader:w,suiteCookie:P,latency:q,ignorePrefix:S,aliases:E,responseHeaders:T,fetch:$,fileResolver:D,fixtureResolver:C,mockSuiteResolver:H,devTools:I,devToolsTimeout:F,devToolsInterval:U,serviceWorker:A,serviceWorkerRegister:J,serviceWorkerURL:V,serviceWorkerScope:void 0===X?"/":X}},Ce=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Re;p()(this,e);var r=De(t),n=r.name,o=r.noPolyfill,a=r.aliases,i=r.fetch,c=r.serviceWorker,s=r.serviceWorkerRegister,u=r.serviceWorkerURL,l=r.serviceWorkerScope;this.__private={recording:!1,bootOptions:r,logPrefix:"[".concat(n,"]"),mocks:[],devToolsFound:!1,skipDevToolsCheck:!1};var f=this.__private.logPrefix;if(!i){var h="".concat(f," @mockyeah/fetch requires a fetch implementation");throw Se(h),new Error(h)}var d={};(a||[]).forEach((function(e){e.forEach((function(t){d[t]=e}))})),this.__private.aliasReplacements=d,o||(global.fetch=this.fetch.bind(this));var v={all:this.all.bind(this),get:this.get.bind(this),post:this.post.bind(this),put:this.put.bind(this),delete:this.delete.bind(this),options:this.options.bind(this),patch:this.patch.bind(this)};this.methods=v,c&&"undefined"!=typeof window&&(s&&ye({url:u,scope:l}),navigator.serviceWorker.addEventListener("message",(function(e){if(e.data&&"mockyeahServiceWorkerDataRequest"===e.data.type){var t=(e.data.payload||{}).requestId;if(!t)return;if(Te[t]){var r={type:"mockyeahServiceWorkerDataResponse",payload:{requestId:t,response:Te[t].response}};ke(r)}}})))}var t,r,n;return d()(e,[{key:"fetch",value:(n=l()(o.a.mark((function e(t,r){var n,a,c,u,l,f,p,h,d,v,k,b,w,P,_,S,j,W,T,R,$,D,C,H,M,I,L,F,N,U,A,K,J,B,V,X,z,G,Q,Z,ee,te,re,ne,ae,ie,ce,se,ue,le,fe,pe,de,ve,ye,ke,xe,ge,Oe,je,Ee,Re,$e,De,Ce,He,Me,Ie=this,Le=arguments;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=Le.length>2&&void 0!==Le[2]?Le[2]:{},c=this.__private,u=c.logPrefix,l=c.mocks,f=c.bootOptions,p=c.aliasReplacements,h=c.skipDevToolsCheck,d=f.noWebSocket,v=f.ignorePrefix,k=f.modifyRequest,b=f.noProxy,w=f.prependServerURL,P=f.suiteCookie,_=f.suiteHeader,S=f.port,j=f.portHttps,W=f.host,T=f.mockSuiteResolver,R=f.fetch,$=f.devTools,D=f.devToolsTimeout,C=f.devToolsInterval,H=f.serviceWorker,M=a.dynamicMocks,I=a.dynamicMockSuite,L=a.noProxy,F=void 0===L?b:L,d){e.next=12;break}return e.prev=5,e.next=8,this.connectWebSocket();case 8:e.next=12;break;case 10:e.prev=10,e.t0=e.catch(5);case 12:if(!$||"undefined"==typeof window||h){e.next=18;break}return e.next=15,new Promise((function(e){var t=0,r=setInterval((function(){t+=1,window.__MOCKYEAH_DEVTOOLS_EXTENSION__?(Ie.__private.devToolsFound=!0,clearInterval(r),e()):t>D/C&&(Ie.__private.skipDevToolsCheck=!0,clearInterval(r),e())}),C)}));case 15:if(!this.__private.devToolsFound){e.next=18;break}return e.next=18,new Promise((function(e){var t=0,r=setInterval((function(){var n;t+=1,((null===(n=window.__MOCKYEAH_DEVTOOLS_EXTENSION__)||void 0===n?void 0:n.loadedMocks)||t>D/C)&&(clearInterval(r),e())}),C)}));case 18:if(N="string"==typeof t?t:t.url,U=r||{},A=(M||[]).map((function(e){return e&&Ie.makeMock(e[0],e[1],{keepExisting:!0}).mock})).filter(Boolean),K=Object(y.parse)(N),J=U.headers?U.headers instanceof Headers?U.headers:new Headers(U.headers):void 0,!U.body||"string"==typeof U.body){e.next=26;break}return Se("".concat(u," @mockyeah/fetch does not yet support non-string request bodies, falling back to normal fetch")),e.abrupt("return",this.fallbackFetch(N,r,{noProxy:F}));case 26:if(B=J&&he(J,U.body),V=K.query?x.a.parse(K.query):void 0,X=U.method?U.method.toLowerCase():"get",!U.headers||g()(U.headers)){e.next=32;break}return Se("".concat(u," @mockyeah/fetch does not yet support non-object request headers, falling back to normal fetch")),e.abrupt("return",this.fallbackFetch(N,r,{noProxy:F}));case 32:z=U.headers;try{(Q=z&&(z.cookie||z.Cookie))?G=q.a.parse(Q):"undefined"!=typeof window&&(G=q.a.parse(window.document.cookie))}catch(e){Se("".concat(u," @mockyeah/fetch couldn't parse cookies: ").concat(e.message))}if(Z=G&&G[P],!(ee=I||Z)||!T){e.next=43;break}return te=ee.split(",").map((function(e){return e.trim()})),re=te.map(T),e.next=41,Promise.all(re);case 41:e.sent.forEach((function(e,t){var r=te[t];(e.default||e).forEach((function(e){var t,n=s()(e,2),o=n[0],a=n[1];Z?(t=g()(o)?we({},o):{url:o}).cookies=we({},t.cookies,{mockSuite:function(e){return!!e&&e.split(",").map((function(e){return e.trim()})).includes(r)}}):t=o,A.push(Ie.makeMock(t,a,{name:r,keepExisting:!0}).mock)}))}));case 43:if(ne={url:N.replace(v,""),query:V,headers:z,body:B,method:X,cookies:G},ae=null!==(n=null==k?void 0:k(ne))&&void 0!==n?n:[ne],ie=(Array.isArray(ae)?ae:[ae]).map((function(e){return Y(e,!0)})),O()(ie.map((function(e){return[e].concat(i()(g()(e)?O()(p&&Object.entries(p).map((function(t){var r=s()(t,2),n=r[0],o=r[1],a=e.url;return"string"==typeof a&&a.replace(/^\//,"").startsWith(n)?o.map((function(t){return we({},e,{url:a.replace(n,t)})})):[]}))):[]))}))).filter(Boolean).find((function(e){return[].concat(i()(A),i()(l)).find((function(t){if(!t)return!1;var r=s()(t,2),n=r[0],o=r[1],a=E()(e,n,{skipKeys:["$meta"]});return a.result?(ce=t,!0):(_e("".concat(u," @mockyeah/fetch missed mock ").concat(o.name?'"'.concat(o.name,'" '):"","for"),N,a.message,{request:ne,match:n}),!1)}))})),se="".concat(K.protocol?"".concat(K.protocol,"//"):"").concat(K.host||"").concat(K.pathname||"/"),ue={url:se,path:se,query:V,method:X,headers:z,body:B,cookies:G},!ce){e.next=76;break}if(ce[0]&&ce[0].$meta&&ce[0].$meta.expectation&&ce[0].$meta.expectation.request(ue),!(fe=ce[1])||!be.some((function(e){return"function"==typeof fe[e]&&fe[e].length>1}))){e.next=64;break}return e.next=56,this.fallbackFetch(N,U);case 56:return pe=e.sent,e.t1=he,e.t2=pe.headers,e.next=61,pe.text();case 61:e.t3=e.sent,de=(0,e.t1)(e.t2,e.t3),le={status:pe.status,body:de,headers:me(pe.headers)};case 64:return e.next=66,oe(ce,ue,f,le);case 66:ve=e.sent,ye=ve.response,ke=ve.json,xe=ve.body,ge=ve.headers;try{ye.url=N}catch(e){}return H&&(Oe={status:ye.status,body:xe,headers:ge},Te[je=We+=1]={response:Oe},R(N,we({},U,{headers:we({},U.headers,{"x-mockyeah-service-worker-request":je})}))),Ee=ce,(Re=s()(Ee,2))[0],$e=Re[1],Pe("".concat(u," @mockyeah/fetch matched mock ").concat($e.name?'"'.concat($e.name,'" '):"","for"),N,{request:ue,mock:ce,response:ye,body:xe,json:ke,headers:ge}),e.abrupt("return",ye);case 76:return qe("".concat(u," @mockyeah/fetch missed all mocks for"),N,{request:ue}),De="http".concat(j?"s":"","://").concat(W,":").concat(j||S),Ce=U,w&&De&&(N="".concat(De,"/").concat(N.replace("://","~~~")),"undefined"!=typeof document&&(Me=document.cookie.match("\\b".concat(P,"=([^;]+)\\b")),He=Me&&Me[1]),Ce=we({},U,{headers:we({},U.headers,{},He&&m()({},_,He))})),e.abrupt("return",this.fallbackFetch(N,Ce,{noProxy:F}));case 81:case"end":return e.stop()}}),e,this,[[5,10]])}))),function(e,t){return n.apply(this,arguments)})},{key:"fallbackFetch",value:(r=l()(o.a.mark((function e(t,r){var n,a,i,c,s,u,l,f,p,h,d,v,m,y,k,x,b,g,w,O,P=arguments;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=P.length>2&&void 0!==P[2]?P[2]:{},a=n.noProxy,i=this.__private.bootOptions,c=i.responseHeaders,s=i.fetch,u="string"==typeof t?t:t.url,!a&&u.startsWith("http")){e.next=8;break}return l={},c&&(l["x-mockyeah-missed"]="true"),e.abrupt("return",new Response("",{status:404,headers:l}));case 8:return f=(new Date).getTime(),e.next=11,s(t,r);case 11:return p=e.sent,e.next=14,pe(p);case 14:return h=e.sent,d=this.__private,v=d.ws,d.recording&&(m=p.status,y=me(p.headers),v&&(k={type:"recordPush",payload:{reqUrl:u,req:{method:r&&r.method,body:r&&r.body},startTime:f,body:h,headers:y,status:m}},v.send(JSON.stringify(k)))),c&&(b=(x=p).status,g=x.statusText,w=x.headers,(O=w&&new Headers(w))&&(O.set("x-mockyeah-proxied","true"),O.set("x-mockyeah-missed","true")),p=new Response(h,{headers:O,status:b,statusText:g})),e.abrupt("return",p);case 19:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"expect",value:function(e){return this.all("*").expect(e)}},{key:"all",value:function(e,t){return this.mock(e,t)}},{key:"get",value:function(e,t){return this.mock($e(e,"get"),t)}},{key:"post",value:function(e,t){return this.mock($e(e,"post"),t)}},{key:"put",value:function(e,t){return this.mock($e(e,"put"),t)}},{key:"delete",value:function(e,t){return this.mock($e(e,"delete"),t)}},{key:"options",value:function(e,t){return this.mock($e(e,"options"),t)}},{key:"patch",value:function(e,t){return this.mock($e(e,"patch"),t)}},{key:"reset",value:function(){this.__private.mocks=[]}},{key:"makeMock",value:function(e,t){var r,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=n.keepExisting,a=n.name,i=Y(e),c=this.__private.mocks,s=[];if(!o){var u,l=c.findIndex((function(e){return Q(i,e[0])}));if(l>=0)r=null!==(u=r)&&void 0!==u?u:l,s.push(c[l]),c.splice(l,1)}var f="string"==typeof t?{name:a,text:t}:we({name:a},t);return f=f||{status:200},i.$meta&&(i.$meta.expectation=new fe(i),i.$meta.id=xe()),{mock:[i,f],removed:s,removedIndex:r}}},{key:"mock",value:function(e,t){var r,n=this.makeMock(e,t),o=n.mock,a=n.removed,i=n.removedIndex,c=null===(r=o[0].$meta)||void 0===r?void 0:r.id,s=this.__private,u=s.mocks,l=s.logPrefix;Oe("".concat(l," mocked"),e,t),null!=i?u.splice(i,0,o):u.push(o);var f=o[0].$meta&&o[0].$meta.expectation,p=a.map((function(e){var t,r;return null===(t=e[0])||void 0===t||null===(r=t.$meta)||void 0===r?void 0:r.id})),h=f.api.bind(f);return{id:c,removedIds:p,expect:function(e){return h(e)}}}},{key:"unmock",value:function(e){var t=this.__private,r=t.mocks,n=t.logPrefix,o=r.findIndex((function(t){var r;return(null===(r=t[0].$meta)||void 0===r?void 0:r.id)===e}));return-1===o?(Oe("".concat(n," didn't find id to unmock"),e),!1):(r.splice(o,1),Oe("".concat(n," unmocked"),e),!0)}},{key:"connectWebSocket",value:(t=l()(o.a.mark((function e(){var t,r,n,a,i=this;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("undefined"!=typeof WebSocket){e.next=2;break}return e.abrupt("return");case 2:if(!this.__private.ws){e.next=4;break}return e.abrupt("return");case 4:t=this.__private.bootOptions,r=t.adminPort,n=t.adminHost,a="ws://".concat(n,":").concat(r),je("WebSocket trying to connect to '".concat(a,"'.")),e.prev=7,this.__private.ws=new WebSocket(a),e.next=16;break;case 11:throw e.prev=11,e.t0=e.catch(7),Ee("WebSocket couldn't connect to '".concat(a,"':"),e.t0),delete this.__private.ws,e.t0;case 16:return e.next=18,new Promise((function(e,t){var r=i.__private.ws;r&&(r.onopen=function(){je("WebSocket opened"),r.send(JSON.stringify({type:"opened"})),e()},r.onerror=function(e){Ee("WebSocket errored",e),t(e)},r.onclose=function(){Ee("WebSocket closed"),i.__private.recording=!1,delete i.__private.ws,t(new Error("WebSocket closed"))},r.onmessage=function(e){var t;je("WebSocket message",e);try{t=JSON.parse(e.data)}catch(t){return void Ee("Couldn't parse WebSocket message data '".concat(e.data,"':"),t)}t&&(je("WebSocket action",t),"record"===t.type?i.__private.recording=!0:"recordStop"===t.type&&(i.__private.recording=!1))})}));case 18:case"end":return e.stop()}}),e,this,[[7,11]])}))),function(){return t.apply(this,arguments)})}]),e}();t.default=Ce}]).default;
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=23)}([function(e,t){e.exports=require("@babel/runtime/regenerator")},function(e,t){e.exports=require("lodash/isPlainObject")},function(e,t){e.exports=require("assert")},function(e,t){e.exports=require("@babel/runtime/helpers/asyncToGenerator")},function(e,t){e.exports=require("debug")},function(e,t){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,t){e.exports=require("@babel/runtime/helpers/slicedToArray")},function(e,t){e.exports=require("qs")},function(e,t){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,t){e.exports=require("url")},function(e,t){e.exports=require("match-deep")},function(e,t){e.exports=require("lodash/isEmpty")},function(e,t){e.exports=require("lodash/isEqual")},function(e,t){e.exports=require("@babel/runtime/helpers/classCallCheck")},function(e,t){e.exports=require("@babel/runtime/helpers/createClass")},function(e,t){e.exports=require("lodash/flatten")},function(e,t){e.exports=require("cookie")},function(e,t){e.exports=require("lodash/isRegExp")},function(e,t){e.exports=require("lodash/mapValues")},function(e,t){e.exports=require("path-to-regexp")},function(e,t){e.exports=require("mime")},function(e,t){e.exports=require("@babel/runtime/helpers/typeof")},function(e,t){e.exports=require("lodash/fromPairs")},function(e,t,r){"use strict";r.r(t);var n=r(0),o=r.n(n),a=r(8),i=r.n(a),c=r(6),s=r.n(c),u=r(3),l=r.n(u),f=r(13),p=r.n(f),h=r(14),d=r.n(h),v=r(5),m=r.n(v),y=r(9),k=r(7),x=r.n(k),b=r(1),g=r.n(b),w=r(15),O=r.n(w),P=r(16),q=r.n(P),_=r(4),S=r.n(_),j=r(10),E=r.n(j),W=r(19),T=r.n(W),R=r(11),$=r.n(R),D=r(17),C=r.n(D),H=r(18),M=r.n(H);function I(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function L(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?I(Object(r),!0).forEach((function(t){m()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):I(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var N=/^(\/?https?.{3}[^/:?]+):/,F=/^(\/?https?).{3}/,U=/^(\/?https?.{3}[^/:?]+)~/,A=/^(\/?https?).{3}/,J=function(e){return e.replace(A,"$1://").replace(U,"$1:")},K=function(e){return e.replace(N,"$1~").replace(F,"$1~~~")},B=/^\//,V=/^(https?)%3A%2F%2F/,X=function(e){return/^\/+https?[:~][/~]{2}/.test(e)?J(function(e){return e.replace(B,"")}(e).replace(V,(function(e,t){return"".concat(t,"://")}))):e},Y=function(e,t){if("function"==typeof e)return e;var r,n=g()(e)?L({},e):e;(r=g()(e)?L({},e):{url:e}).query=$()(r.query)?void 0:r.query,r.headers=$()(r.headers)?void 0:Object.entries(r.headers).reduce((function(e,t){var r=s()(t,2),n=r[0],o=r[1];return e[n.toLowerCase()]=o,e}),{}),r.method&&"all"!==r.method&&"ALL"!==r.method&&"*"!==r.method?"string"==typeof r.method&&(r.method=r.method.toLowerCase()):delete r.method;var o=L({},r.$meta||{});if(r.path&&(r.url=r.path,delete r.path),"*"===r.url&&delete r.url,"string"==typeof r.url){r.url=X(r.url);var a=function(e){var t;return/^https?:/.test(e)?(t=Object(y.parse)(e),e="".concat(t.protocol||"http:","//").concat(t.hostname).concat(t.port&&!["80","443"].includes(t.port)?":".concat(t.port):"").concat(t.pathname)):(t=Object(y.parse)("http://example.com".concat(e.startsWith("/")?e:"/".concat(e))),e=t.pathname||""),{url:e,query:t.query?x.a.parse(t.query):void 0}}(r.url);r.url=a.url.replace(/\/+$/,"")||"/",r.query=g()(r.query)?L({},a.query,{},r.query):r.query||a.query}$()(r.query)&&delete r.query,$()(r.cookies)&&delete r.cookies;var i=L({},r);r.url||(i.url="*"),o.original=n,o.originalNormal=i,o.originalSerialized=function e(t){return M()(t,(function(t){return C()(t)?{$regex:{source:t.source,flags:t.flags}}:g()(t)?M()(t,(function(t){return e(t)})):t}))}(i);var c=r.url;if("string"==typeof r.url){if(!t){var u=[],l=T()(K(r.url),u);r.url=function(e){return l.test(K(e)||K("/".concat(e)))},o.regex=l,o.matchKeys=u,o.fn=r.url.toString(),r.url.toStringForMatchDeep=function(){return'"'.concat(null==c?void 0:c.toString(),'"')}}}else if(C()(r.url)){if(!t){var f=r.url;r.url=function(e){return f.test(J(e))||f.test(J("/".concat(e)))},o.regex=f,o.fn=r.url.toString(),r.url.toStringForMatchDeep=function(){return null==c?void 0:c.toString()}}}else if("function"==typeof r.url){var p=r.url;r.url=function(e){return p(e)||p("/".concat(e))}}return L({},r,{$meta:o})},z=r(12),G=r.n(z),Q=function(e,t){var r=e.$meta?e.$meta.originalNormal:void 0,n=t.$meta?t.$meta.originalNormal:void 0;return g()(r)&&g()(n)?!(!r||!n)&&(r.url===n.url&&r.path===n.path&&r.method===n.method&&G()(r.query,n.query)&&G()(r.body,n.body)&&G()(r.headers,n.headers)&&G()(r.cookies,n.cookies)):r===n},Z=r(20),ee=r.n(Z);function te(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function re(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?te(Object(r),!0).forEach((function(t){m()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):te(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var ne=function(e,t,r){return"function"==typeof e?e(t,r):e},oe=function(){var e=l()(o.a.mark((function e(t,r,n,a){var i,c,s,u,l,f,p,h,d,v,m,y,k,x,b,g;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=n.responseHeaders,c=n.fixtureResolver,s=n.fileResolver,u=t[1]||{},l=u.name,e.t1=u.status,!e.t1){e.next=8;break}return e.next=7,ne(u.status,r,a);case 7:e.t1=e.sent;case 8:if(e.t0=e.t1,e.t0){e.next=11;break}e.t0=200;case 11:if(f=e.t0,e.t2=u.type,!e.t2){e.next=17;break}return e.next=16,ne(u.type,r,a);case 16:e.t2=e.sent;case 17:if(h=e.t2,!u.fixture){e.next=36;break}if(c){e.next=21;break}throw new Error("Using `fixture` in mock response options requires a `fixtureResolver`.");case 21:return e.next=23,ne(u.fixture,r,a);case 23:if(m=e.sent,h=h||m,!m){e.next=31;break}return e.next=28,c(m);case 28:e.t3=e.sent,e.next=32;break;case 31:e.t3=void 0;case 32:if(p=e.t3,h.includes("json"))try{v=JSON.parse(p)}catch(e){}e.next=81;break;case 36:if(!u.filePath){e.next=54;break}if(s){e.next=39;break}throw new Error("Using `filePath` in mock response options requires a `fileResolver`.");case 39:return e.next=41,ne(u.filePath,r,a);case 41:if(y=e.sent,h=h||y,!y){e.next=49;break}return e.next=46,s(y);case 46:e.t4=e.sent,e.next=50;break;case 49:e.t4=void 0;case 50:if(p=e.t4,h.includes("json"))try{v=JSON.parse(p)}catch(e){}e.next=81;break;case 54:if(!u.json){e.next=62;break}return e.next=57,ne(u.json,r,a);case 57:v=e.sent,p=JSON.stringify(v),d="application/json; charset=UTF-8",e.next=81;break;case 62:if(!u.text){e.next=69;break}return e.next=65,ne(u.text,r,a);case 65:p=e.sent,d="text/plain; charset=UTF-8",e.next=81;break;case 69:if(!u.html){e.next=76;break}return e.next=72,ne(u.html,r,a);case 72:p=e.sent,d="text/html; charset=UTF-8",e.next=81;break;case 76:if(!u.raw){e.next=81;break}return e.next=79,ne(u.raw,r,a);case 79:p=e.sent,d=void 0;case 81:if(p=p||"",d=h?ee.a.getType(h)||h:d,!(k=u.latency||n.latency)){e.next=90;break}return e.next=87,ne(k,r,a);case 87:return x=e.sent,e.next=90,new Promise((function(e){return setTimeout(e,x)}));case 90:if(!u.headers){e.next=99;break}return e.t6=re,e.t7={},e.next=95,ne(u.headers,r,a);case 95:e.t8=e.sent,e.t5=(0,e.t6)(e.t7,e.t8),e.next=100;break;case 99:e.t5={};case 100:return b=e.t5,i&&(b["x-mockyeah-mocked"]="true",l&&(b["x-mockyeah-name"]=l),m&&(b["x-mockyeah-fixture"]=m),y&&(b["x-mockyeah-filePath"]=y),x&&(b["x-mockyeah-latency"]=x.toString())),d&&(b["content-type"]=d),g=new Response(p,{status:f,headers:b}),e.abrupt("return",{response:g,body:p,headers:b,json:v});case 106:case"end":return e.stop()}}),e)})));return function(t,r,n,o){return e.apply(this,arguments)}}(),ae=r(21),ie=r.n(ae),ce=r(2),se=r.n(ce),ue=function(e){return e&&(e instanceof Promise||!(!e.then||!e.catch))},le=function(e,t,r){var n=E()(e,t,{skipKeys:["$meta"]}),o=n.result,a=n.message;se()(o,"".concat(r,": ").concat(a))},fe=function(){function e(t){p()(this,e);var r=t.$meta&&t.$meta.originalNormal?t.$meta.originalNormal:t;this.prefix="[".concat(r.method||"all","] ").concat(r.path||r.url," --"),this.called=0,this.assertions=[],this.handlers=[],this.verifier=this.verifier.bind(this),this.run=this.run.bind(this),this.verify=this.verify.bind(this)}return d()(e,[{key:"request",value:function(e){var t=this;this.called+=1,this.handlers.forEach((function(r){t.assertions.push(r.bind(t,e))}))}},{key:"api",value:function(e){var t=this;if("function"==typeof e){var r=e;this.handlers.push((function(e){try{var n=r(e);if(void 0!==n&&!n)throw new Error("function returned false")}catch(e){var o="".concat(t.prefix," Expect function did not match").concat(e&&e.message?": ".concat(e.message):"");se()(!1,o)}}))}else if("object"===ie()(e)){var n=Y(e);this.handlers.push((function(e){var t=E()(e,n,{skipKeys:["$meta"]}),r=t.result,o=t.message;se()(r,"Expect object did not match: ".concat(o))}))}return this}},{key:"atLeast",value:function(e){var t=this;return this.assertions.push((function(){se()(t.called>=e,"".concat(t.prefix," Expected route to be called at least ").concat(e," times, but it was called ").concat(t.called," times"))})),this}},{key:"atMost",value:function(e){var t=this;return this.assertions.push((function(){se()(t.called<=e,"".concat(t.prefix," Expected route to be called at most ").concat(e," times, but it was called ").concat(t.called," times"))})),this}},{key:"never",value:function(){var e=this;return this.assertions.push((function(){se()(0===e.called,"".concat(e.prefix," Expected route to be called never, but it was called ").concat(e.called," times"))})),this}},{key:"once",value:function(){var e=this;return this.assertions.push((function(){se()(1===e.called,"".concat(e.prefix," Expected route to be called once, but it was called ").concat(e.called," times"))})),this}},{key:"twice",value:function(){var e=this;return this.assertions.push((function(){se()(2===e.called,"".concat(e.prefix," Expected route to be called twice, but it was called ").concat(e.called," times"))})),this}},{key:"thrice",value:function(){var e=this;return this.assertions.push((function(){se()(3===e.called,"".concat(e.prefix," Expected route to be called thrice, but it was called ").concat(e.called," times"))})),this}},{key:"exactly",value:function(e){var t=this;return this.assertions.push((function(){se()(t.called===e,"".concat(t.prefix," Expected route to be called ").concat(e," times, but it was called ").concat(t.called," times"))})),this}},{key:"path",value:function(e){var t="".concat(this.prefix," Path did not match expected");return this.handlers.push((function(r){var n=r.path;le(n,e,t)})),this}},{key:"url",value:function(e){return this.path(e)}},{key:"header",value:function(e,t){var r="".concat(this.prefix,' Header "').concat(e,'" did not match expected');return this.handlers.push((function(n){le(n.headers&&(n.headers[e]||n.headers[e.toLowerCase()]),t,r)})),this}},{key:"params",value:function(e){var t="".concat(this.prefix," Params did not match expected");return this.handlers.push((function(r){le(r.query||{},e||{},t)})),this}},{key:"query",value:function(e){return this.params(e)}},{key:"body",value:function(e){var t="".concat(this.prefix," Body did not match expected");return this.handlers.push((function(r){le(r.body,e,t)})),this}},{key:"verifier",value:function(e){var t=this;return function(r){r?e(r):t.verify(e)}}},{key:"run",value:function(e){return ue(e)?this.runPromise=e:this.runPromise=new Promise((function(t,r){setTimeout((function(){var n=e((function(e){e?r(e):t()}));ue(n)&&n.then(t).catch(r)}))})),this}},{key:"verify",value:function(e){var t=this,r=function(t){if(!e)throw t;e(t)},n=function(){try{t.assertions.forEach((function(e){return e()})),e&&e()}catch(e){r(e)}};if(this.runPromise)return this.runPromise.then(n).catch(r);n()}}]),e}(),pe=function(){var e=l()(o.a.mark((function e(t){return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(204!==t.status){e.next=3;break}return e.abrupt("return","");case 3:return e.abrupt("return",t.text()||"");case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),he=function(e,t){var r=e&&e.get("Content-Type"),n=null==r?void 0:r.includes("application/json"),o=null==r?void 0:r.includes("application/x-www-form-urlencoded");if(t){if(n)return JSON.parse(t);if(o)return x.a.parse(t)}return t},de=r(22),ve=r.n(de),me=function(e){if(!e)return{};if(e.entries){var t=e.entries();return ve()(i()(t).map((function(e){return[e[0].toLowerCase(),e[1]]})))}if(e.forEach){var r={};return e.forEach((function(e,t){r[t]=e})),r}return{}},ye=function(e){var t=e.url,r=e.scope;"undefined"!=typeof navigator&&navigator.serviceWorker.register(t,{scope:r}).then((function(e){console.log("@mockyeah/fetch service worker registration succeeded.")})).catch((function(e){console.log("@mockyeah/fetch service worker registration failed.",e)}))},ke=function(e){var t;if("undefined"!=typeof navigator&&(null===(t=navigator.serviceWorker)||void 0===t?void 0:t.controller))try{navigator.serviceWorker.controller.postMessage(e)}catch(e){console.error(e)}},xe=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))},be=["json","text","html","raw","filePath","fixture","status","type","latency","headers"];function ge(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function we(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ge(Object(r),!0).forEach((function(t){m()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ge(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var Oe=S()("mockyeah:fetch:mock"),Pe=S()("mockyeah:fetch:hit"),qe=S()("mockyeah:fetch:miss"),_e=S()("mockyeah:fetch:miss:each"),Se=S()("mockyeah:fetch:error"),je=S()("mockyeah:fetch:admin"),Ee=S()("mockyeah:fetch:admin:error"),We=0,Te={},Re={},$e=function(e,t){return we({},g()(e)?e:{url:e},{method:t})},De=function(e){var t=e.name,r=void 0===t?"default":t,n=e.noProxy,o=void 0!==n&&n,a=e.prependServerURL,i=void 0!==a&&a,c=e.modifyRequest,s=e.noPolyfill,u=void 0!==s&&s,l=e.noWebSocket,f=void 0!==l&&l,p=e.host,h=void 0===p?"localhost":p,d=e.port,v=void 0===d?4001:d,m=e.portHttps,y=e.adminHost,k=void 0===y?h:y,x=e.adminPort,b=void 0===x?4777:x,g=e.suiteHeader,w=void 0===g?"x-mockyeah-suite":g,O=e.suiteCookie,P=void 0===O?"mockyeahSuite":O,q=e.latency,_=e.ignorePrefix,S=void 0===_?"http".concat(m?"s":"","://").concat(h,":").concat(m||v,"/"):_,j=e.aliases,E=void 0===j?[]:j,W=e.responseHeaders,T=void 0===W||W,R=e.fetch,$=void 0===R?global.fetch:R,D=e.fileResolver,C=e.fixtureResolver,H=e.mockSuiteResolver,M=e.devTools,I=void 0!==M&&M,L=e.devToolsTimeout,N=void 0===L?2e3:L,F=e.devToolsInterval,U=void 0===F?100:F,A=e.serviceWorker,J=e.serviceWorkerRegister,K=void 0===J?A:J,B=e.serviceWorkerURL,V=void 0===B?"/__mockyeahServiceWorker.js":B,X=e.serviceWorkerScope;return{name:r,noProxy:o,prependServerURL:i,modifyRequest:c,noPolyfill:u,noWebSocket:f,host:h,port:v,portHttps:m,adminHost:k,adminPort:b,suiteHeader:w,suiteCookie:P,latency:q,ignorePrefix:S,aliases:E,responseHeaders:T,fetch:$,fileResolver:D,fixtureResolver:C,mockSuiteResolver:H,devTools:I,devToolsTimeout:N,devToolsInterval:U,serviceWorker:A,serviceWorkerRegister:K,serviceWorkerURL:V,serviceWorkerScope:void 0===X?"/":X}},Ce=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Re;p()(this,e);var r=De(t),n=r.name,o=r.noPolyfill,a=r.aliases,i=r.fetch,c=r.serviceWorker,s=r.serviceWorkerRegister,u=r.serviceWorkerURL,l=r.serviceWorkerScope;this.__private={recording:!1,bootOptions:r,logPrefix:"[".concat(n,"]"),mocks:[],devToolsFound:!1,skipDevToolsCheck:!1};var f=this.__private.logPrefix;if(!i){var h="".concat(f," @mockyeah/fetch requires a fetch implementation");throw Se(h),new Error(h)}var d={};(a||[]).forEach((function(e){e.forEach((function(t){d[t]=e}))})),this.__private.aliasReplacements=d,o||(global.fetch=this.fetch.bind(this));var v={all:this.all.bind(this),get:this.get.bind(this),post:this.post.bind(this),put:this.put.bind(this),delete:this.delete.bind(this),options:this.options.bind(this),patch:this.patch.bind(this)};this.methods=v,c&&"undefined"!=typeof window&&(s&&ye({url:u,scope:l}),navigator.serviceWorker.addEventListener("message",(function(e){if(e.data&&"mockyeahServiceWorkerDataRequest"===e.data.type){var t=(e.data.payload||{}).requestId;if(!t)return;if(Te[t]){var r={type:"mockyeahServiceWorkerDataResponse",payload:{requestId:t,response:Te[t].response}};ke(r)}}})))}var t,r,n;return d()(e,[{key:"fetch",value:(n=l()(o.a.mark((function e(t,r){var n,a,c,u,l,f,p,h,d,v,k,b,w,P,_,S,j,W,T,R,$,D,C,H,M,I,L,N,F,U,A,J,K,B,V,X,z,G,Q,Z,ee,te,re,ne,ae,ie,ce,se,ue,le,fe,pe,de,ve,ye,ke,xe,ge,Oe,je,Ee,Re,$e,De,Ce,He,Me,Ie=this,Le=arguments;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=Le.length>2&&void 0!==Le[2]?Le[2]:{},c=this.__private,u=c.logPrefix,l=c.mocks,f=c.bootOptions,p=c.aliasReplacements,h=c.skipDevToolsCheck,d=f.noWebSocket,v=f.ignorePrefix,k=f.modifyRequest,b=f.noProxy,w=f.prependServerURL,P=f.suiteCookie,_=f.suiteHeader,S=f.port,j=f.portHttps,W=f.host,T=f.mockSuiteResolver,R=f.fetch,$=f.devTools,D=f.devToolsTimeout,C=f.devToolsInterval,H=f.serviceWorker,M=a.dynamicMocks,I=a.dynamicMockSuite,L=a.noProxy,N=void 0===L?b:L,d){e.next=12;break}return e.prev=5,e.next=8,this.connectWebSocket();case 8:e.next=12;break;case 10:e.prev=10,e.t0=e.catch(5);case 12:if(!$||"undefined"==typeof window||h){e.next=18;break}return e.next=15,new Promise((function(e){var t=0,r=setInterval((function(){t+=1,window.__MOCKYEAH_DEVTOOLS_EXTENSION__?(Ie.__private.devToolsFound=!0,clearInterval(r),e()):t>D/C&&(Ie.__private.skipDevToolsCheck=!0,clearInterval(r),e())}),C)}));case 15:if(!this.__private.devToolsFound){e.next=18;break}return e.next=18,new Promise((function(e){var t=0,r=setInterval((function(){var n;t+=1,((null===(n=window.__MOCKYEAH_DEVTOOLS_EXTENSION__)||void 0===n?void 0:n.loadedMocks)||t>D/C)&&(clearInterval(r),e())}),C)}));case 18:if(F="string"==typeof t?t:t.url,U=r||{},A=(M||[]).map((function(e){return e&&Ie.makeMock(e[0],e[1],{keepExisting:!0}).mock})).filter(Boolean),J=Object(y.parse)(F),K=U.headers?U.headers instanceof Headers?U.headers:new Headers(U.headers):void 0,!U.body||"string"==typeof U.body){e.next=26;break}return Se("".concat(u," @mockyeah/fetch does not yet support non-string request bodies, falling back to normal fetch")),e.abrupt("return",this.fallbackFetch(F,r,{noProxy:N}));case 26:if(B=K&&he(K,U.body),V=J.query?x.a.parse(J.query):void 0,X=U.method?U.method.toLowerCase():"get",!U.headers||g()(U.headers)){e.next=32;break}return Se("".concat(u," @mockyeah/fetch does not yet support non-object request headers, falling back to normal fetch")),e.abrupt("return",this.fallbackFetch(F,r,{noProxy:N}));case 32:z=U.headers;try{(Q=z&&(z.cookie||z.Cookie))?G=q.a.parse(Q):"undefined"!=typeof window&&(G=q.a.parse(window.document.cookie))}catch(e){Se("".concat(u," @mockyeah/fetch couldn't parse cookies: ").concat(e.message))}if(Z=G&&G[P],!(ee=I||Z)||!T){e.next=43;break}return te=ee.split(",").map((function(e){return e.trim()})),re=te.map(T),e.next=41,Promise.all(re);case 41:e.sent.forEach((function(e,t){var r=te[t];(e.default||e).forEach((function(e){var t,n=s()(e,2),o=n[0],a=n[1];Z?(t=g()(o)?we({},o):{url:o}).cookies=we({},t.cookies,{mockSuite:function(e){return!!e&&e.split(",").map((function(e){return e.trim()})).includes(r)}}):t=o,A.push(Ie.makeMock(t,a,{name:r,keepExisting:!0}).mock)}))}));case 43:if(ne={url:F.replace(v,""),query:V,headers:z,body:B,method:X,cookies:G},ae=null!==(n=null==k?void 0:k(ne))&&void 0!==n?n:[ne],ie=(Array.isArray(ae)?ae:[ae]).map((function(e){return Y(e,!0)})),O()(ie.map((function(e){return[e].concat(i()(g()(e)?O()(p&&Object.entries(p).map((function(t){var r=s()(t,2),n=r[0],o=r[1],a=e.url;return"string"==typeof a&&a.replace(/^\//,"").startsWith(n)?o.map((function(t){return we({},e,{url:a.replace(n,t)})})):[]}))):[]))}))).filter(Boolean).find((function(e){return[].concat(i()(A),i()(l)).find((function(t){if(!t)return!1;var r=s()(t,2),n=r[0],o=r[1],a=E()(e,n,{skipKeys:["$meta"]});return a.result?(ce=t,!0):(_e("".concat(u," @mockyeah/fetch missed mock ").concat(o.name?'"'.concat(o.name,'" '):"","for"),F,a.message,{request:ne,match:n}),!1)}))})),se="".concat(J.protocol?"".concat(J.protocol,"//"):"").concat(J.host||"").concat(J.pathname||"/"),ue={url:se,path:se,query:V,method:X,headers:z,body:B,cookies:G},!ce){e.next=76;break}if(ce[0]&&ce[0].$meta&&ce[0].$meta.expectation&&ce[0].$meta.expectation.request(ue),!(fe=ce[1])||!be.some((function(e){return"function"==typeof fe[e]&&fe[e].length>1}))){e.next=64;break}return e.next=56,this.fallbackFetch(F,U);case 56:return pe=e.sent,e.t1=he,e.t2=pe.headers,e.next=61,pe.text();case 61:e.t3=e.sent,de=(0,e.t1)(e.t2,e.t3),le={status:pe.status,body:de,headers:me(pe.headers)};case 64:return e.next=66,oe(ce,ue,f,le);case 66:ve=e.sent,ye=ve.response,ke=ve.json,xe=ve.body,ge=ve.headers;try{ye.url=F}catch(e){}return H&&(Oe={status:ye.status,body:xe,headers:ge},Te[je=We+=1]={response:Oe},R(F,we({},U,{headers:we({},U.headers,{"x-mockyeah-service-worker-request":je})}))),Ee=ce,(Re=s()(Ee,2))[0],$e=Re[1],Pe("".concat(u," @mockyeah/fetch matched mock ").concat($e.name?'"'.concat($e.name,'" '):"","for"),F,{request:ue,mock:ce,response:ye,body:xe,json:ke,headers:ge}),e.abrupt("return",ye);case 76:return qe("".concat(u," @mockyeah/fetch missed all mocks for"),F,{request:ue}),De="http".concat(j?"s":"","://").concat(W,":").concat(j||S),Ce=U,w&&De&&(F="".concat(De,"/").concat(F.replace("://","~~~")),"undefined"!=typeof document&&(Me=document.cookie.match("\\b".concat(P,"=([^;]+)\\b")),He=Me&&Me[1]),Ce=we({},U,{headers:we({},U.headers,{},He&&m()({},_,He))})),e.abrupt("return",this.fallbackFetch(F,Ce,{noProxy:N}));case 81:case"end":return e.stop()}}),e,this,[[5,10]])}))),function(e,t){return n.apply(this,arguments)})},{key:"fallbackFetch",value:(r=l()(o.a.mark((function e(t,r){var n,a,i,c,s,u,l,f,p,h,d,v,m,y,k,x,b,g,w,O,P=arguments;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=P.length>2&&void 0!==P[2]?P[2]:{},a=n.noProxy,i=this.__private.bootOptions,c=i.responseHeaders,s=i.fetch,u="string"==typeof t?t:t.url,!a&&u.startsWith("http")){e.next=8;break}return l={},c&&(l["x-mockyeah-missed"]="true"),e.abrupt("return",new Response("",{status:404,headers:l}));case 8:return f=(new Date).getTime(),e.next=11,s(t,r);case 11:return p=e.sent,e.next=14,pe(p);case 14:return h=e.sent,d=this.__private,v=d.ws,d.recording&&(m=p.status,y=me(p.headers),v&&(k={type:"recordPush",payload:{reqUrl:u,req:{method:r&&r.method,body:r&&r.body},startTime:f,body:h,headers:y,status:m}},v.send(JSON.stringify(k)))),c&&(b=(x=p).status,g=x.statusText,w=x.headers,(O=w&&new Headers(w))&&(O.set("x-mockyeah-proxied","true"),O.set("x-mockyeah-missed","true")),p=new Response(h,{headers:O,status:b,statusText:g})),e.abrupt("return",p);case 19:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"expect",value:function(e){return this.all("*").expect(e)}},{key:"all",value:function(e,t){return this.mock(e,t)}},{key:"get",value:function(e,t){return this.mock($e(e,"get"),t)}},{key:"post",value:function(e,t){return this.mock($e(e,"post"),t)}},{key:"put",value:function(e,t){return this.mock($e(e,"put"),t)}},{key:"delete",value:function(e,t){return this.mock($e(e,"delete"),t)}},{key:"options",value:function(e,t){return this.mock($e(e,"options"),t)}},{key:"patch",value:function(e,t){return this.mock($e(e,"patch"),t)}},{key:"reset",value:function(){this.__private.mocks=[]}},{key:"makeMock",value:function(e,t){var r,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=n.keepExisting,a=n.name,i=Y(e),c=this.__private.mocks,s=[];if(!o){var u,l=c.findIndex((function(e){return Q(i,e[0])}));if(l>=0)r=null!==(u=r)&&void 0!==u?u:l,s.push(c[l]),c.splice(l,1)}var f="string"==typeof t?{name:a,text:t}:we({name:a},t);return f=f||{status:200},i.$meta&&(i.$meta.expectation=new fe(i),i.$meta.id=xe()),{mock:[i,f],removed:s,removedIndex:r}}},{key:"mock",value:function(e,t){var r,n=this.makeMock(e,t),o=n.mock,a=n.removed,i=n.removedIndex,c=null===(r=o[0].$meta)||void 0===r?void 0:r.id,s=this.__private,u=s.mocks,l=s.logPrefix;Oe("".concat(l," mocked"),e,t),null!=i?u.splice(i,0,o):u.push(o);var f=o[0].$meta&&o[0].$meta.expectation,p=a.map((function(e){var t,r;return null===(t=e[0])||void 0===t||null===(r=t.$meta)||void 0===r?void 0:r.id})),h=f.api.bind(f);return{id:c,removedIds:p,expect:function(e){return h(e)}}}},{key:"unmock",value:function(e){var t=this.__private,r=t.mocks,n=t.logPrefix,o=r.findIndex((function(t){var r;return(null===(r=t[0].$meta)||void 0===r?void 0:r.id)===e}));return-1===o?(Oe("".concat(n," didn't find id to unmock"),e),!1):(r.splice(o,1),Oe("".concat(n," unmocked"),e),!0)}},{key:"connectWebSocket",value:(t=l()(o.a.mark((function e(){var t,r,n,a,i=this;return o.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("undefined"!=typeof WebSocket){e.next=2;break}return e.abrupt("return");case 2:if(!this.__private.ws){e.next=4;break}return e.abrupt("return");case 4:t=this.__private.bootOptions,r=t.adminPort,n=t.adminHost,a="ws://".concat(n,":").concat(r),je("WebSocket trying to connect to '".concat(a,"'.")),e.prev=7,this.__private.ws=new WebSocket(a),e.next=16;break;case 11:throw e.prev=11,e.t0=e.catch(7),Ee("WebSocket couldn't connect to '".concat(a,"':"),e.t0),delete this.__private.ws,e.t0;case 16:return e.next=18,new Promise((function(e,t){var r=i.__private.ws;r&&(r.onopen=function(){je("WebSocket opened"),r.send(JSON.stringify({type:"opened"})),e()},r.onerror=function(e){Ee("WebSocket errored",e),t(e)},r.onclose=function(){Ee("WebSocket closed"),i.__private.recording=!1,delete i.__private.ws,t(new Error("WebSocket closed"))},r.onmessage=function(e){var t;je("WebSocket message",e);try{t=JSON.parse(e.data)}catch(t){return void Ee("Couldn't parse WebSocket message data '".concat(e.data,"':"),t)}t&&(je("WebSocket action",t),"record"===t.type?i.__private.recording=!0:"recordStop"===t.type&&(i.__private.recording=!1))})}));case 18:case"end":return e.stop()}}),e,this,[[7,11]])}))),function(){return t.apply(this,arguments)})}]),e}();t.default=Ce}]).default;
{
"name": "@mockyeah/fetch",
"version": "1.0.1",
"version": "1.0.2",
"description": "fetch integration for mockyeah request mocking utility.",

@@ -73,3 +73,3 @@ "main": "dist/main.js",

"@babel/register": "^7.9.0",
"@mockyeah/tools": "^1.0.1",
"@mockyeah/tools": "^1.0.2",
"@types/cookie": "^0.3.3",

@@ -108,3 +108,3 @@ "@types/debug": "^4.1.5",

"lodash": "^4.17.15",
"match-deep": "^1.0.1",
"match-deep": "^1.0.2",
"mime": "^2.4.4",

@@ -114,3 +114,3 @@ "path-to-regexp": "^3.1.0",

},
"gitHead": "3cfa3b54c9eb771a07381d5d7560168dbcce96b0"
"gitHead": "5dd441031bc37df5406dd7a89db2eba5adafd250"
}

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc