frontexpress/frontexpress.min.js

1 line
14 KiB
JavaScript

!function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={exports:{},id:n,loaded:!1};return e[n].call(a.exports,a,a.exports,t),a.loaded=!0,a.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}var a=r(8);n(a)},function(e,t){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?"":arguments[0];r(this,e),this.name=t}return n(e,[{key:"entered",value:function(e){}},{key:"exited",value:function(e){}},{key:"updated",value:function(e,t){}},{key:"failed",value:function(e,t){}},{key:"next",value:function(){return!0}}]),e}();t["default"]=a,e.exports=t["default"]},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"],e.exports=t["default"]},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=r(2),u=n(o),s=r(1),l=n(s),d=function(){function e(t,r,n,i){a(this,e),this.router=t,this.uriPart=r,this.method=n,this.middleware=i,this.visited=!1}return i(e,[{key:"uri",get:function(){if(this.uriPart||this.method)return this.uriPart instanceof RegExp?this.uriPart:this.router.baseUri instanceof RegExp?this.router.baseUri:this.router.baseUri&&this.uriPart?(this.router.baseUri.trim()+this.uriPart.trim()).replace(/\/{2,}/,"/"):this.router.baseUri?this.router.baseUri.trim():this.uriPart}}]),e}(),f=function(){function e(t){a(this,e),t&&(this._baseUri=t),this._routes=[]}return i(e,[{key:"_add",value:function(e){return this._routes.push(e),this}},{key:"routes",value:function(e,t){return this._routes.filter(function(r){if(!r.uri&&!r.method)return!0;if(r.method!==t)return!1;if(!r.uri)return!0;var n=e,a=n.indexOf("?");a>=0&&(n=n.slice(0,a));var i=n.indexOf("#");return i>=0&&(n=n.slice(0,i)),r.uri instanceof RegExp?n.match(r.uri):r.uri===n})}},{key:"visited",value:function(){return this._routes.filter(function(e){return e.visited})}},{key:"use",value:function(e){if(!(e instanceof l["default"])&&"function"!=typeof e)throw new TypeError("use method takes at least a middleware");return this._add(new d(this,(void 0),(void 0),e)),this}},{key:"all",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];if(0===t.length)throw new TypeError("use all method takes at least a middleware");var n=void 0;if(n=1===t.length?t[0]:t[1],!(n instanceof l["default"])&&"function"!=typeof n)throw new TypeError("use all method takes at least a middleware");var a=!0,i=!1,o=void 0;try{for(var s,d=u["default"][Symbol.iterator]();!(a=(s=d.next()).done);a=!0){var f=s.value;this[f.toLowerCase()].apply(this,t)}}catch(c){i=!0,o=c}finally{try{!a&&d["return"]&&d["return"]()}finally{if(i)throw o}}return this}},{key:"baseUri",set:function(e){if(e){if(!this._baseUri)return void(this._baseUri=e);if(this._baseUri instanceof RegExp)throw new TypeError("the router already contains a regexp uri "+this._baseUri.toString()+" It cannot be mixed with "+e.toString());if(e instanceof RegExp)throw new TypeError("the router already contains an uri "+this._baseUri.toString()+" It cannot be mixed with regexp "+e.toString())}},get:function(){return this._baseUri}}]),e}();t["default"]=f;var c=!0,h=!1,v=void 0;try{for(var y,w=function(){var e=y.value,t=e.toLowerCase();f.prototype[t]=function(){for(var r=arguments.length,n=Array(r),a=0;a<r;a++)n[a]=arguments[a];if(0===n.length)throw new TypeError("use "+t+" method takes at least a middleware");var i=void 0,o=void 0;if(1===n.length?o=n[0]:(i=n[0],o=n[1]),!(o instanceof l["default"])&&"function"!=typeof o)throw new TypeError("use "+t+" method takes at least a middleware");if(i&&this._baseUri&&this._baseUri instanceof RegExp)throw new TypeError("router contains a regexp cannot mix with route uri/regexp");return this._add(new d(this,i,e,o)),this}},p=u["default"][Symbol.iterator]();!(c=(y=p.next()).done);c=!0)w()}catch(m){h=!0,v=m}finally{try{!c&&p["return"]&&p["return"]()}finally{if(h)throw v}}e.exports=t["default"]},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function a(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),u=r(2),s=n(u),l=r(7),d=n(l),f=r(3),c=n(f),h=r(1),v=n(h),y=function(){function e(){i(this,e),this.routers=[],this.isDOMLoaded=!1,this.isDOMReady=!1,this.settings=new d["default"]}return o(e,[{key:"set",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];if(1===t.length){var n=[t];return this.settings.get(n)}var a=t[0],i=t[1];return this.settings.set(a,i),this}},{key:"listen",value:function(e){var t=this;window.onbeforeunload=function(){t._callMiddlewareExited()},window.onpopstate=function(e){if(e.state){var r=e.state,n=r.request,a=r.response,i=t._routes(n.uri,n.method);t._callMiddlewareEntered(i,n),t._callMiddlewareUpdated(i,n,a)}},document.onreadystatechange=function(){var r={method:"GET",uri:window.location.pathname+window.location.search},n={status:200,statusText:"OK"},a=t._routes();"loading"!==document.readyState||t.isDOMLoaded?"interactive"!==document.readyState||t.isDOMReady||(t.isDOMLoaded||(t.isDOMLoaded=!0,t._callMiddlewareEntered(a,r)),t.isDOMReady=!0,t._callMiddlewareUpdated(a,r,n),e&&e(r,n)):(t.isDOMLoaded=!0,t._callMiddlewareEntered(a,r))}}},{key:"route",value:function(e){var t=new c["default"](e);return this.routers.push(t),t}},{key:"use",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];if(0===t.length)throw new TypeError("use method takes at least a middleware or a router");var n=void 0,a=void 0,i=void 0,o=void 0;if(1===t.length?o=t[0]:(n=t[0],o=t[1]),!(o instanceof v["default"]||"function"==typeof o||o instanceof c["default"]))throw new TypeError("use method takes at least a middleware or a router");if(o instanceof c["default"])i=o,i.baseUri=n;else{a=o,i=new c["default"](n);var u=!0,l=!1,d=void 0;try{for(var f,h=s["default"][Symbol.iterator]();!(u=(f=h.next()).done);u=!0){var y=f.value;i[y.toLowerCase()](a)}}catch(w){l=!0,d=w}finally{try{!u&&h["return"]&&h["return"]()}finally{if(l)throw d}}}return this.routers.push(i),this}},{key:"_routes",value:function(){var e=arguments.length<=0||void 0===arguments[0]?window.location.pathname+window.location.search:arguments[0],t=arguments.length<=1||void 0===arguments[1]?"GET":arguments[1],r=[],n=!0,i=!1,o=void 0;try{for(var u,s=this.routers[Symbol.iterator]();!(n=(u=s.next()).done);n=!0){var l=u.value,d=l.routes(e,t);r.push.apply(r,a(d))}}catch(f){i=!0,o=f}finally{try{!n&&s["return"]&&s["return"]()}finally{if(i)throw o}}return r}},{key:"_callMiddlewareEntered",value:function(e,t){var r=!0,n=!1,a=void 0;try{for(var i,o=e[Symbol.iterator]();!(r=(i=o.next()).done);r=!0){var u=i.value;if(u.middleware.entered&&u.middleware.entered(t),u.middleware.next&&!u.middleware.next())break}}catch(s){n=!0,a=s}finally{try{!r&&o["return"]&&o["return"]()}finally{if(n)throw a}}}},{key:"_callMiddlewareUpdated",value:function(e,t,r){var n=!0,a=!1,i=void 0;try{for(var o,u=e[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value;if(s.visited=t,s.middleware.updated){if(s.middleware.updated(t,r),s.middleware.next&&!s.middleware.next())break}else{var l=!0,d=function(){l=!1};if(s.middleware(t,r,d),l)break}}}catch(f){a=!0,i=f}finally{try{!n&&u["return"]&&u["return"]()}finally{if(a)throw i}}}},{key:"_callMiddlewareExited",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,a=this.routers[Symbol.iterator]();!(e=(n=a.next()).done);e=!0){var i=n.value,o=i.visited(),u=!0,s=!1,l=void 0;try{for(var d,f=o[Symbol.iterator]();!(u=(d=f.next()).done);u=!0){var c=d.value;c.middleware.exited&&(c.middleware.exited(c.visited),c.visited=null)}}catch(h){s=!0,l=h}finally{try{!u&&f["return"]&&f["return"]()}finally{if(s)throw l}}}}catch(h){t=!0,r=h}finally{try{!e&&a["return"]&&a["return"]()}finally{if(t)throw r}}}},{key:"_callMiddlewareFailed",value:function(e,t,r){var n=!0,a=!1,i=void 0;try{for(var o,u=e[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var s=o.value;if(s.middleware.failed){if(s.middleware.failed(t,r),s.middleware.next&&!s.middleware.next())break}else{var l=!0,d=function(){l=!1};if(s.middleware(t,r,d),l)break}}}catch(f){a=!0,i=f}finally{try{!n&&u["return"]&&u["return"]()}finally{if(a)throw i}}}},{key:"_fetch",value:function(e,t,r){var n=this,a=e.method,i=e.uri,o=e.headers,u=e.data,s=e.history,l=this.get("http "+a+" transformer");l&&(i=l.uri?l.uri({uri:i,headers:o,data:u}):i,o=l.headers?l.headers({uri:i,headers:o,data:u}):o,u=l.data?l.data({uri:i,headers:o,data:u}):u),this._callMiddlewareExited();var d=this._routes(i,a);this._callMiddlewareEntered(d,e),this.settings.get("http requester").fetch(e,function(e,r){s&&window.history.pushState({request:e,response:r},s.title,s.uri),n._callMiddlewareUpdated(d,e,r),t&&t(e,r)},function(e,t){n._callMiddlewareFailed(d,e,t),r&&r(e,t)})}}]),e}();t["default"]=y,s["default"].reduce(function(e,t){var r=t.toLowerCase();e[r]=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];if("get"===r){if(0===t.length)throw new TypeError(r+" method takes at least a string or a middleware");if(1===t.length){var a=t[0];if("string"==typeof a)return this.settings.get(a)}}else if(0===t.length)throw new TypeError(r+" method takes at least a middleware");var i=void 0,o=void 0,u=void 0;if(1===t.length?u=t[0]:(i=t[0],u=t[1]),!(u instanceof v["default"])&&"function"!=typeof u)throw new TypeError(r+" method takes at least a middleware");var s=new c["default"];return o=u,s[r](i,o),this.routers.push(s),this};var n="http"+t.charAt(0).toUpperCase()+t.slice(1).toLowerCase();return e[n]=function(e,r,n){var a=e.uri,i=e.headers,o=e.data,u=e.history;return a||(a=e),this._fetch({uri:a,method:t,headers:i,data:o,history:u},r,n)},e},y.prototype),e.exports=t["default"]},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var a=r(4),i=n(a),o=r(3),u=n(o),s=r(1),l=n(s),d=function(){return new i["default"]};d.Router=function(e){return new u["default"](e)},d.Middleware=function(e){return new l["default"](e)},t["default"]=d,e.exports=t["default"]},function(e,t){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=function(){function e(){r(this,e)}return n(e,[{key:"fetch",value:function(e,t,r){var n=this,a=e.method,i=e.uri,o=e.headers,u=e.data,s=function(r){t(e,{status:200,statusText:"OK",responseText:r})},l=function(t){var a=t.status,i=t.statusText,o=t.errorThrown,u=n._analyzeErrors({status:a,statusText:i,errorThrown:o});r(e,{status:a,statusText:i,errorThrown:o,errors:u})},d=new XMLHttpRequest;d.onreadystatechange=function(){4===d.readyState&&(200===d.status?s(d.responseText):l({status:d.status,statusText:d.statusText}))};try{if(d.open(a,i,!0),o){var f=!0,c=!1,h=void 0;try{for(var v,y=Object.keys(o)[Symbol.iterator]();!(f=(v=y.next()).done);f=!0){var w=v.value;d.setRequestHeader(w,o[w])}}catch(p){c=!0,h=p}finally{try{!f&&y["return"]&&y["return"]()}finally{if(c)throw h}}}u?d.send(u):d.send()}catch(m){l({errorThrown:m})}}},{key:"_analyzeErrors",value:function(e){if(e.errorThrown){if("SyntaxError"===e.errorThrown.name)return"Problem during data decoding [JSON]";if("TimeoutError"===e.errorThrown.name)return"Server is taking too long to reply";if("AbortError"===e.errorThrown.name)return"Request cancelled on server";if("NetworkError"===e.errorThrown.name)return"A network error occurred";throw e.errorThrown}return 0===e.status?"Server access problem. Check your network connection":401===e.status?"Your session has expired, Please reconnect. [code: 401]":404===e.status?"Page not found on server. [code: 404]":500===e.status?"Internal server error. [code: 500]":"Unknown error. "+(e.statusText?e.statusText:"")}}]),e}();t["default"]=a,e.exports=t["default"]},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=r(6),u=n(o),s=function(){function e(){a(this,e),this.settings={"http requester":new u["default"],"http GET transformer":{uri:function(e){var t=e.uri,r=(e.headers,e.data);if(!r)return t;var n="",a=t,i=t.indexOf("#");return i>=1&&(a=t.slice(0,i),n=t.slice(i,t.length)),a=Object.keys(r).reduce(function(e,t,n){return e+=0===n&&e.indexOf("?")===-1?"?":"&",e+=t+"="+r[t]},a),a+n},data:function(e){e.uri,e.headers,e.data}}},this.rules={"http requester":function(e){if("function"!=typeof e.fetch)throw new TypeError("setting http requester has no fetch method")}}}return i(e,[{key:"set",value:function(e,t){var r=this.rules[e];r&&r(t),this.settings[e]=t}},{key:"get",value:function(e){return this.settings[e]}}]),e}();t["default"]=s,e.exports=t["default"]},function(e,t,r){(function(t){e.exports=t.frontexpress=r(5)}).call(t,function(){return this}())}]);