-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
1 lines (1 loc) · 79.1 KB
/
server.js
1
!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}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=16)}([function(e,t){e.exports=require("firebase")},function(e,t){e.exports=require("moment")},function(e,t){e.exports=require("dotenv/config")},function(e,t){e.exports=require("body-parser")},function(e,t){e.exports=require("jsonwebtoken")},function(e,t){e.exports=require("axios")},function(e,t){e.exports=require("express")},function(e,t){e.exports=require("cors")},function(e,t){e.exports=require("oauth")},function(e,t){e.exports=require("xml-js")},function(e,t){e.exports=require("multer")},function(e,t){e.exports=require("firebase/app")},function(e,t){e.exports=require("core-js/stable")},function(e,t){e.exports=require("regenerator-runtime/runtime")},function(e,t){e.exports=require("firebase/storage")},function(e,t){e.exports=require("xhr2")},function(e,t,r){"use strict";r.r(t);r(12),r(13),r(2);var n=r(6),o=r.n(n),a=r(3),s=r.n(a),i=r(7),u=r.n(i),c=r(0),f=r.n(c);function l(e){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){return!t||"object"!==l(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function d(e){var t="function"==typeof Map?new Map:void 0;return(d=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return v(e,arguments,b(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),y(n,e)})(e)}function v(e,t,r){return(v=g()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&y(o,r.prototype),o}).apply(null,arguments)}function g(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function y(e,t){return(y=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function b(e){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var m=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&y(e,t)}(o,e);var t,r,n=(t=o,r=g(),function(){var e,n=b(t);if(r){var o=b(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return h(this,e)});function o(e,t){var r;p(this,o);for(var a=arguments.length,s=new Array(a>2?a-2:0),i=2;i<a;i++)s[i-2]=arguments[i];return(r=n.call.apply(n,[this].concat(s))).httpCode=e,r.userMessage=t,r}return o}(d(Error)),w=function(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Someting went wrong. Try again.",n=500;if(e.userMessage)throw e;if(!e.code)throw new m(n,r);throw"auth/email-already-in-use"===e.code?t="The email is already in use":"auth/invalid-email"===e.code?(t="Invalid email",n=400):"auth/weak-password"===e.code?(t="Password must be at least 6 symbols long",n=400):"auth/user-disabled"===e.code?t="Account with given email has been disabled.":"auth/user-not-found"===e.code?(t="User with that email does not exist!",n=404):t="auth/wrong-password"===e.code?"Incorrect password!":e.code.includes("different-credential")?"Email is already associated with another account":r,new m(n,t)},k=r(8),x=r.n(k);function S(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 R(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?S(Object(r),!0).forEach((function(t){O(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):S(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function O(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function B(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function j(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){B(a,n,o,s,i,"next",e)}function i(e){B(a,n,o,s,i,"throw",e)}s(void 0)}))}}function P(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)}}var C=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.tokenService=t,this.consumer=new x.a.OAuth("https://twitter.com/oauth/request_token","https://twitter.com/oauth/access_token",process.env.TWITTER_KEY,process.env.TWITTER_SECRET,"1.0A","https://bookshelf-a2203.web.app/login","HMAC-SHA1")}var t,r,n,o,a,s,i,u,c;return t=e,(r=[{key:"getUserProfile",value:(c=j(regeneratorRuntime.mark((function e(t){var r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,f.a.firestore().collection("users").doc(t).get();case 2:if((r=e.sent).exists){e.next=5;break}return e.abrupt("return",null);case 5:return(n=r.data()).id=t,e.abrupt("return",n);case 8:case"end":return e.stop()}}),e)}))),function(e){return c.apply(this,arguments)})},{key:"createToken",value:function(e,t){return this.tokenService.createToken({id:e,email:t},2592e3)}},{key:"getUser",value:(u=j(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,f.a.auth().setPersistence(f.a.auth.Auth.Persistence.NONE);case 3:return e.next=5,f.a.auth().signInWithEmailAndPassword(t,r);case 5:return n=f.a.auth().currentUser.uid,e.next=8,this.getUserProfile(n);case 8:if(o=e.sent){e.next=11;break}throw new m(404,"User with email ".concat(t," does not exist!"));case 11:return e.abrupt("return",R(R({},o),{},{token:this.createToken(n,t)}));case 14:e.prev=14,e.t0=e.catch(0),console.log(e.t0),w(e.t0,"Someting went wrong while signing you in! Try again!");case 18:case"end":return e.stop()}}),e,this,[[0,14]])}))),function(e,t){return u.apply(this,arguments)})},{key:"createUser",value:(i=j(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,f.a.auth().setPersistence(f.a.auth.Auth.Persistence.NONE);case 3:return e.next=5,f.a.auth().createUserWithEmailAndPassword(t,r);case 5:return n=f.a.auth().currentUser.uid,e.next=8,this.saveUser(t,n);case 8:return o=e.sent,e.abrupt("return",R({},o));case 12:e.prev=12,e.t0=e.catch(0),console.log(e.t0),w(e.t0,"Ooops! Something went wrong while creating your account! Try again.");case 16:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e,t){return i.apply(this,arguments)})},{key:"saveUser",value:(s=j(regeneratorRuntime.mark((function e(t,r){var n,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n={email:t},o=f.a.firestore().collection("users").doc(r),e.next=4,o.set(n);case 4:return n.id=r,a=this.createToken(r,t),e.abrupt("return",R(R({},n),{},{token:a}));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return s.apply(this,arguments)})},{key:"signInGoogle",value:(a=j(regeneratorRuntime.mark((function e(t){var r,n,o,a,s,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,f.a.auth().setPersistence(f.a.auth.Auth.Persistence.NONE);case 3:return r=f.a.auth.GoogleAuthProvider.credential(t),e.next=6,f.a.auth().signInWithCredential(r);case 6:if(n=e.sent,!(o=n.user).email){e.next=21;break}return e.next=11,this.getUserProfile(o.uid);case 11:if(a=e.sent,s=this.createToken(o.uid,o.email),!a){e.next=15;break}return e.abrupt("return",R(R({},a),{},{token:s}));case 15:return e.next=17,this.saveUser(o.email,o.uid);case 17:return i=e.sent,e.abrupt("return",R({},i));case 21:throw new m(500,"Failed to authenticate Google user");case 22:e.next=28;break;case 24:e.prev=24,e.t0=e.catch(0),console.log(e.t0),w(e.t0,"Ooops! Something went wrong while linking your Google account! Try again.");case 28:case"end":return e.stop()}}),e,this,[[0,24]])}))),function(e){return a.apply(this,arguments)})},{key:"getAuthorizeUrl",value:function(){var e=this;return new Promise((function(t,r){e.consumer.getOAuthRequestToken((function(e,n,o){e&&r(new m(500,"Failed to get request token")),t({url:"https://api.twitter.com/oauth/authenticate?oauth_token=".concat(n)})}))}))}},{key:"getAccessToken",value:function(e,t){var r=this;return new Promise((function(n,o){r.consumer.getOAuthAccessToken(e,process.env.TWITTER_SECRET,t,(function(e,t,r){e&&o(new m(500,"Failed to get access token")),n({token:t,secret:r})}))}))}},{key:"signInTwitter",value:(o=j(regeneratorRuntime.mark((function e(t,r){var n,o,a,s,i,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,f.a.auth().setPersistence(f.a.auth.Auth.Persistence.NONE);case 3:return n=f.a.auth.TwitterAuthProvider.credential(t,r),e.next=6,f.a.auth().signInWithCredential(n);case 6:if(o=e.sent,!(a=o.user).email){e.next=21;break}return e.next=11,this.getUserProfile(a.uid);case 11:if(s=e.sent,i=this.createToken(a.uid,a.email),!s){e.next=15;break}return e.abrupt("return",R(R({},s),{},{token:i}));case 15:return e.next=17,this.saveUser(a.email,a.uid);case 17:return u=e.sent,e.abrupt("return",R({},u));case 21:throw new m(500,"Failed to authenticate Twitter user");case 22:e.next=27;break;case 24:e.prev=24,e.t0=e.catch(0),w(e.t0,message||"Ooops! Something went wrong while linking your Twitter account! Try again.");case 27:case"end":return e.stop()}}),e,this,[[0,24]])}))),function(e,t){return o.apply(this,arguments)})}])&&P(t.prototype,r),n&&P(t,n),e}(),_=r(4),U=r.n(_);function A(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)}}var F=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.createToken=this.createToken.bind(this),this.validateToken=this.validateToken.bind(this)}var t,r,n;return t=e,(r=[{key:"createToken",value:function(e,t){if(!e||t<=0)throw new m(400,"Error creating a token");return U.a.sign(e,process.env.JWT_KEY,{expiresIn:t})}},{key:"validateToken",value:function(e){if(!e)throw new m(401,"Missing access token");return U.a.verify(e,process.env.JWT_KEY,(function(e,t){if(e){if("jwt expired"===e.message)throw new m(401,"Token has expired");throw new m(401,"Failed to authenticate token")}return t}))}}])&&A(t.prototype,r),n&&A(t,n),e}();function T(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function I(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){T(a,n,o,s,i,"next",e)}function i(e){T(a,n,o,s,i,"throw",e)}s(void 0)}))}}function D(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)}}var E=new C(new F),M=new(function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.authService=t,this.signInUser=this.signInUser.bind(this),this.signUpUser=this.signUpUser.bind(this),this.signInWithGoogle=this.signInWithGoogle.bind(this),this.signInWithTwitter=this.signInWithTwitter.bind(this),this.getRequestUrl=this.getRequestUrl.bind(this)}var t,r,n,o,a,s,i,u;return t=e,(r=[{key:"signInUser",value:(u=I(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("SignIn request accepted"),(n=t.body)&&n.email&&n.password){e.next=5;break}throw new m(400,"User credentials are invalid");case 5:return e.next=7,this.authService.getUser(n.email,n.password);case 7:o=e.sent,r.json(o),e.next=14;break;case 11:e.prev=11,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 14:case"end":return e.stop()}}),e,this,[[0,11]])}))),function(e,t){return u.apply(this,arguments)})},{key:"signUpUser",value:(i=I(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("SignUp request accepted"),(n=t.body)&&n.email&&n.password){e.next=5;break}throw new m(400,"User credentials are invalid");case 5:return e.next=7,this.authService.createUser(n.email,n.password);case 7:o=e.sent,r.json(o),e.next=14;break;case 11:e.prev=11,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 14:case"end":return e.stop()}}),e,this,[[0,11]])}))),function(e,t){return i.apply(this,arguments)})},{key:"signInWithGoogle",value:(s=I(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("Sign In With Google request accepted"),e.prev=1,n=t.body.token,e.next=5,this.authService.signInGoogle(n);case 5:o=e.sent,r.json(o),e.next=13;break;case 9:e.prev=9,e.t0=e.catch(1),console.log(e.t0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 13:case"end":return e.stop()}}),e,this,[[1,9]])}))),function(e,t){return s.apply(this,arguments)})},{key:"signInWithTwitter",value:(a=I(regeneratorRuntime.mark((function e(t,r){var n,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(console.log("Sign In With Twitter request accepted"),e.prev=1,n=t.query.token,o=t.query.verifier,console.log(n,o),n&&o){e.next=7;break}throw new m(400,"Invalid request paramrs");case 7:return e.next=9,this.authService.getAccessToken(n,o);case 9:return a=e.sent,e.next=12,this.authService.signInTwitter(a.token,a.secret);case 12:s=e.sent,r.json(s),e.next=20;break;case 16:e.prev=16,e.t0=e.catch(1),console.log(e.t0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 20:case"end":return e.stop()}}),e,this,[[1,16]])}))),function(e,t){return a.apply(this,arguments)})},{key:"getRequestUrl",value:(o=I(regeneratorRuntime.mark((function e(t,r){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("Get OAuth Request Token request accepted"),e.prev=1,e.next=4,this.authService.getAuthorizeUrl();case 4:n=e.sent,console.log(n),r.json(n),e.next=13;break;case 9:e.prev=9,e.t0=e.catch(1),console.log(e.t0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 13:case"end":return e.stop()}}),e,this,[[1,9]])}))),function(e,t){return o.apply(this,arguments)})}])&&D(t.prototype,r),n&&D(t,n),e}())(E),q=r(5),G=r.n(q),W=r(9),Y=r.n(W);function N(e){return(N="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function V(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function H(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){V(a,n,o,s,i,"next",e)}function i(e){V(a,n,o,s,i,"throw",e)}s(void 0)}))}}function L(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)}}var K=process.env.GOODREADS_KEY,z=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,r,n,o,a;return t=e,(r=[{key:"getValueFromGoodreads",value:(a=H(regeneratorRuntime.mark((function e(t){var r,n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,G.a.get(t);case 3:if(!((r=e.sent).status>=300)){e.next=6;break}throw new m(r.status,"Failed to retrieve book data");case 6:return n=r.data,o=Y.a.xml2js(n,{compact:!0}),e.abrupt("return",o);case 11:if(e.prev=11,e.t0=e.catch(0),!e.t0.userMessage){e.next=15;break}throw e.t0;case 15:if(!e.t0.response||404!=e.t0.response.status){e.next=17;break}throw new m(e.t0.response.status,"Book was not found");case 17:throw new m(500,"Something went wrong while retrieving book info!");case 18:case"end":return e.stop()}}),e,null,[[0,11]])}))),function(e){return a.apply(this,arguments)})},{key:"getHQImage",value:(o=H(regeneratorRuntime.mark((function e(t,r){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n="",!t.includes("nophoto")||!r){e.next=14;break}return n="".concat("https://pictures.abebooks.com/isbn/").concat(r,".jpg"),e.prev=3,e.next=6,G.a.get(n);case 6:if(404===e.sent.status){e.next=9;break}return e.abrupt("return",n);case 9:e.next=14;break;case 11:return e.prev=11,e.t0=e.catch(3),e.abrupt("return","https://s.gr-assets.com/assets/nophoto/book/111x148-bcc042a9c91a29c1d680899eff700a03.png");case 14:return e.abrupt("return",t);case 15:case"end":return e.stop()}}),e,null,[[3,11]])}))),function(e,t){return o.apply(this,arguments)})},{key:"findValue",value:function(e,t){var r,n=this;return Object.keys(e).some((function(o){return o===t?(r=e[o],!0):e[o]&&"object"===N(e[o])?void 0!==(r=n.findValue(e[o],t)):void 0})),r}},{key:"root",get:function(){return"https://www.goodreads.com/"}},{key:"devKey",get:function(){return K}}])&&L(t.prototype,r),n&&L(t,n),e}();function J(e){return(J="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Q(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function X(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){Q(a,n,o,s,i,"next",e)}function i(e){Q(a,n,o,s,i,"throw",e)}s(void 0)}))}}function Z(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)}}function $(e,t){return($=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function ee(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=re(e);if(t){var o=re(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return te(this,r)}}function te(e,t){return!t||"object"!==J(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function re(e){return(re=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var ne=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&$(e,t)}(u,e);var t,r,n,o,a,s,i=ee(u);function u(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u),(t=i.call(this)).formatBookService=e,t}return t=u,(r=[{key:"searchBooks",value:(s=X(regeneratorRuntime.mark((function e(t){var r,n,o,a,s=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r="".concat(this.root,"search/index.xml?key=").concat(this.devKey,"&q=").concat(t),e.next=4,this.getValueFromGoodreads(r);case 4:if(n=e.sent,o=this.findValue(n,"work")){e.next=8;break}throw new m(404,"No books can be found");case 8:return a=o.slice(0,4).map((function(e){var t=s.findValue(e,"best_book");return s.formatBookService.formatBookForSearch(t)})),e.abrupt("return",a);case 12:if(e.prev=12,e.t0=e.catch(0),!e.t0.userMessage){e.next=18;break}throw e.t0;case 18:throw new m(500,"Something went wrong while searching for book");case 19:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e){return s.apply(this,arguments)})},{key:"getBookWithUserData",value:(a=X(regeneratorRuntime.mark((function e(t,r){var n,o,a,s,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.fetchUserBookData(r,t);case 3:if(!(n=e.sent)){e.next=8;break}return e.abrupt("return",n);case 8:return o="".concat(this.root,"book/show/").concat(t,".xml?key=").concat(this.devKey),e.next=11,this.getValueFromGoodreads(o);case 11:if(a=e.sent,s=this.findValue(a,"book")){e.next=15;break}throw new m(404,"Book not found");case 15:return i=this.formatBookService.formatBookForBookPage(s),e.next=18,this.getHQImage(i.imageUrl,i.isbn);case 18:return i.imageUrl=e.sent,e.abrupt("return",i);case 20:e.next=27;break;case 22:if(e.prev=22,e.t0=e.catch(0),!e.t0.userMessage){e.next=26;break}throw e.t0;case 26:throw new m(500,"Something went wrong while retrieving book");case 27:case"end":return e.stop()}}),e,this,[[0,22]])}))),function(e,t){return a.apply(this,arguments)})},{key:"fetchUserBookData",value:(o=X(regeneratorRuntime.mark((function e(t,r){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,f.a.firestore().collection("users").doc(t).collection("books").where("id","==",r).get();case 2:if(!(n=e.sent).empty){e.next=7;break}return e.abrupt("return",!1);case 7:return e.abrupt("return",n.docs[0].data());case 8:case"end":return e.stop()}}),e)}))),function(e,t){return o.apply(this,arguments)})}])&&Z(t.prototype,r),n&&Z(t,n),u}(z);function oe(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)}}var ae=["to-read","currently-reading","owned","default","favorites","books-i-own","ebook","kindle","library","audiobook","owned-books","audiobooks","my-books","ebooks","to-buy","english","calibre","books","british","audio","my-library","favourites","re-read","general","e-books","fiction","ya","series","classic"],se=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,r,n;return t=e,(r=[{key:"mapArrayIds",value:function(e){return e.map((function(e){return e.id._text}))}},{key:"formatGenresForBook",value:function(e){var t=e.filter((function(e){return!ae.includes(e._attributes.name)})).map((function(e){return e._attributes.name.replace(/^\w/,(function(e){return e.toUpperCase()}))}));return t.length>3?t.slice(0,3):t}},{key:"getBookTitle",value:function(e){if(!e)return null;var t=e,r=t.indexOf("(");return t.substring(0,r>0?r:t.length).trim()}},{key:"formatDescription",value:function(e){if(!e)return"";var t=e.replace(new RegExp(/<br\s*\/?>/g),"\n");return t=t.replace(new RegExp(/<[^>]*>/g),"")}},{key:"formatSeriesForBook",value:function(e){if(!e)return null;Array.isArray(e)&&(e=e[0]);var t=e.series.id._text,r=e.user_position._text?" #".concat(e.user_position._text):"";return{id:t,fullName:"(".concat(e.series.title._cdata.trim()).concat(r,")")}}},{key:"formatAuthor",value:function(e){return Array.isArray(e)?this.getAllBookAuthors(e):[this.mapAuthor(e)]}},{key:"formatAuthorForSearch",value:function(e){return Array.isArray(e)?e[0].name._text:e.name._text}},{key:"getAllBookAuthors",value:function(e){var t=this;return e.filter((function(e){return!e.role._text})).map((function(e){return t.mapAuthor(e)}))}},{key:"mapAuthor",value:function(e){return{id:e.id._text,name:e.name._text,imageUrl:e.image_url._cdata,smallImageUrl:e.small_image_url._cdata,goodreadsRating:e.average_rating._text}}},{key:"getLargeImageUrl",value:function(e){if(!e||e.includes("nophoto"))return e;var t=new RegExp(/._(.*?)_/g);return e.replace(t,"")}}])&&oe(t.prototype,r),n&&oe(t,n),e}();var ie=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.status="not reading",this.rating=0,this.pagesRead=0,this.isFavorited=!1,this.finishTimes=[],this.notes=""};var ue=function e(t,r,n,o,a,s,i,u,c,f,l,p){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.isbn=t,this.id=r,this.title=n,this.imageUrl=o,this.smallImageUrl=a,this.description=s,this.publishedYear=i,this.goodreadsRating=u,this.pages=c,this.authors=f,this.series=l,this.genres=p,this.userData=new ie};function ce(e){return(ce="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function fe(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)}}function le(e,t){return(le=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function pe(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=de(e);if(t){var o=de(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return he(this,r)}}function he(e,t){return!t||"object"!==ce(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function de(e){return(de=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var ve=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&le(e,t)}(a,e);var t,r,n,o=pe(a);function a(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),o.call(this)}return t=a,(r=[{key:"formatBookForSearch",value:function(e){try{return{id:e.id._text,title:e.title._text||e.title._cdata,imageUrl:this.getLargeImageUrl(e.image_url._text),author:this.formatAuthorForSearch(e.author)}}catch(e){throw console.log(e),new m(400,"Failed to retrieve data from book")}}},{key:"formatBookForBookPage",value:function(e){try{var t={isbn:e.isbn13._cdata,id:e.id._text,title:this.getBookTitle(e.title._text)||this.getBookTitle(e.title._cdata),imageUrl:this.getLargeImageUrl(e.image_url._text),smallImageUrl:e.small_image_url._text,description:this.formatDescription(e.description._cdata),publishedYear:e.work.original_publication_year._text,goodreadsRating:e.average_rating._text,pages:e.num_pages._cdata};return t.authors=this.formatAuthor(e.authors.author),t.series=this.formatSeriesForBook(e.series_works.series_work),t.genres=this.formatGenresForBook(e.popular_shelves.shelf),new ue(t.isbn,t.id,t.title,t.imageUrl,t.smallImageUrl,t.description,t.publishedYear,t.goodreadsRating,t.pages,t.authors,t.series,t.genres)}catch(e){throw console.log(e),new m(400,"Failed to retrieve data from book")}}}])&&fe(t.prototype,r),n&&fe(t,n),a}(se),ge=new F;function ye(e){var t=e.headers["x-access-token"];return ge.validateToken(t)}function be(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function me(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){be(a,n,o,s,i,"next",e)}function i(e){be(a,n,o,s,i,"throw",e)}s(void 0)}))}}function we(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)}}var ke=new ne(new ve),xe=new(function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.goodreadsBookService=t,this.searchByTitleOrAuthor=this.searchByTitleOrAuthor.bind(this),this.getBookById=this.getBookById.bind(this)}var t,r,n,o,a;return t=e,(r=[{key:"searchByTitleOrAuthor",value:(a=me(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("Search request accepted!"),n=t.query.query){e.next=5;break}throw new m(400,"Search query is empty");case 5:return ye(t),e.next=8,this.goodreadsBookService.searchBooks(n);case 8:o=e.sent,r.json(o),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e,t){return a.apply(this,arguments)})},{key:"getBookById",value:(o=me(regeneratorRuntime.mark((function e(t,r){var n,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("Get Book By Id request accepted"),(n=t.params.bookId)&&!isNaN(n)){e.next=5;break}throw new m(400,"Book identifier is invalid");case 5:return o=ye(t),e.next=8,this.goodreadsBookService.getBookWithUserData(n,o.id);case 8:a=e.sent,r.json(a),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e,t){return o.apply(this,arguments)})}])&&we(t.prototype,r),n&&we(t,n),e}())(ke);function Se(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?Se(Object(r),!0).forEach((function(t){Oe(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Se(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function Oe(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Be(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function je(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)}}var Pe=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,r,n,o,a;return t=e,(r=[{key:"getUserById",value:(o=regeneratorRuntime.mark((function e(t){var r,n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=f.a.firestore().collection("users").doc(t),e.next=4,r.get();case 4:if((n=e.sent).exists){e.next=9;break}throw new m(404,"User not found");case 9:return o=n.data(),e.abrupt("return",Re(Re({},o),{},{id:t}));case 11:e.next=20;break;case 13:if(e.prev=13,e.t0=e.catch(0),!e.t0.userMessage){e.next=19;break}throw e.t0;case 19:throw new m(500,"Could not retrieve user");case 20:case"end":return e.stop()}}),e,null,[[0,13]])})),a=function(){var e=this,t=arguments;return new Promise((function(r,n){var a=o.apply(e,t);function s(e){Be(a,r,n,s,i,"next",e)}function i(e){Be(a,r,n,s,i,"throw",e)}s(void 0)}))},function(e){return a.apply(this,arguments)})}])&&je(t.prototype,r),n&&je(t,n),e}();function Ce(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function _e(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){Ce(a,n,o,s,i,"next",e)}function i(e){Ce(a,n,o,s,i,"throw",e)}s(void 0)}))}}function Ue(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)}}var Ae=["finished","stopped","2read","reading","not reading"],Fe=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.feedService=t}var t,r,n,o,a,s,i,u,c,l,p;return t=e,(r=[{key:"getUserBooksAsFBCollection",value:function(e){return f.a.firestore().collection("users").doc(e).collection("books")}},{key:"getUserBooksAsArray",value:(p=_e(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,console.log(f.a.auth().currentUser.email),e.next=4,this.getUserBooksAsFBCollection(t).get();case 4:if(!(r=e.sent).empty){e.next=9;break}return e.abrupt("return",[]);case 9:return e.abrupt("return",r.docs.map((function(e){return e.data()})));case 10:e.next=18;break;case 12:if(e.prev=12,e.t0=e.catch(0),console.log(e.t0),!e.t0.userMessage){e.next=17;break}throw e.t0;case 17:throw new m(500,"Could not retrieve user books");case 18:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e){return p.apply(this,arguments)})},{key:"getUserCollection",value:(l=_e(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,Ae.includes(r.toLowerCase())){e.next=3;break}throw new m(400,"Book status is invalid");case 3:return n=this.getUserBooksAsFBCollection(t),e.next=6,n.where("userData.status","==",r).get();case 6:if(!(o=e.sent).empty){e.next=11;break}return e.abrupt("return",[]);case 11:return e.abrupt("return",o.docs.map((function(e){return e.data()})));case 12:e.next=20;break;case 14:if(e.prev=14,e.t0=e.catch(0),console.log(e.t0),!e.t0.userMessage){e.next=19;break}throw e.t0;case 19:throw new m(500,"Ooops! Something went wrong while retrieving user books");case 20:case"end":return e.stop()}}),e,this,[[0,14]])}))),function(e,t){return l.apply(this,arguments)})},{key:"addToUserCollection",value:(c=_e(regeneratorRuntime.mark((function e(t,r,n){var o,a,s,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,Ae.includes(r.toLowerCase())){e.next=3;break}throw new m(400,"Book status is invalid");case 3:return console.log(n),o=this.getUserBooksAsFBCollection(t),e.next=7,o.where("id","==",n.id).get();case 7:if(a=e.sent,n.userData.status=r,!a.empty){e.next=14;break}return e.next=12,o.doc().set(n);case 12:e.next=18;break;case 14:return s=a.docs[0],i=s.id,e.next=18,o.doc(i).update({userData:n.userData});case 18:return e.next=20,this.feedService.saveFeed(n,r,t);case 20:return e.abrupt("return",n);case 23:if(e.prev=23,e.t0=e.catch(0),!e.t0.userMessage){e.next=27;break}throw e.t0;case 27:throw new m(500,"Something went wrong while updating user books!");case 28:case"end":return e.stop()}}),e,this,[[0,23]])}))),function(e,t,r){return c.apply(this,arguments)})},{key:"deleteBookFromCollection",value:(u=_e(regeneratorRuntime.mark((function e(t,r){var n,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.getUserBooksAsFBCollection(t).where("id","==",r).get();case 3:if((n=e.sent).empty){e.next=13;break}return o=n.docs[0],a=o.id,this.getUserBooksAsFBCollection(t).doc(a).delete(),(s=o.data()).userData=new ie,e.next=12,this.feedService.saveFeed(s,"not",t);case 12:return e.abrupt("return",s);case 13:return e.abrupt("return",!1);case 16:if(e.prev=16,e.t0=e.catch(0),!e.t0.userMessage){e.next=20;break}throw e.t0;case 20:throw new m(500,"Something went wrong while deleting book!");case 21:case"end":return e.stop()}}),e,this,[[0,16]])}))),function(e,t){return u.apply(this,arguments)})},{key:"setFavorite",value:(i=_e(regeneratorRuntime.mark((function e(t,r){var n,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,n=this.getUserBooksAsFBCollection(t),e.next=4,n.where("id","==",r.id).get();case 4:if(o=e.sent,r.userData.isFavorited=!r.userData.isFavorited,!o.empty){e.next=11;break}return e.next=9,n.doc().set(r);case 9:e.next=15;break;case 11:return a=o.docs[0],s=a.id,e.next=15,n.doc(s).update({"userData.isFavorited":r.userData.isFavorited});case 15:return e.abrupt("return",r);case 18:if(e.prev=18,e.t0=e.catch(0),!e.t0.userMessage){e.next=22;break}throw e.t0;case 22:throw new m(500,"Something went wrong while updating book!");case 23:case"end":return e.stop()}}),e,this,[[0,18]])}))),function(e,t){return i.apply(this,arguments)})},{key:"getFavorites",value:(s=_e(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.getUserBooksAsFBCollection(t).where("userData.isFavorited","==",!0).get();case 3:if(!(r=e.sent).empty){e.next=6;break}return e.abrupt("return",[]);case 6:return e.abrupt("return",r.docs.map((function(e){return e.data()})));case 9:if(e.prev=9,e.t0=e.catch(0),!e.t0.userMessage){e.next=13;break}throw e.t0;case 13:throw new m(500,"Something went wrong while retrieving user books!");case 14:case"end":return e.stop()}}),e,this,[[0,9]])}))),function(e){return s.apply(this,arguments)})},{key:"updateBook",value:(a=_e(regeneratorRuntime.mark((function e(t,r){var n,o,a,s,i,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,n=this.getUserBooksAsFBCollection(t),e.next=4,n.where("id","==",r.id).get();case 4:if(!(o=e.sent).empty){e.next=9;break}throw new m(404,"Book not found");case 9:return a=o.docs[0],s=a.id,i=a.data(),u=r.userData.pagesRead-i.userData.pagesRead,console.log(u),e.next=16,this.feedService.saveFeed(r,"update",t,{pages:u});case 16:if(!(Math.abs(r.userData.rating-i.userData.rating)>0)){e.next=19;break}return e.next=19,this.feedService.saveFeed(r,"rating",t,{rating:r.userData.rating});case 19:return e.next=21,n.doc(s).update({userData:r.userData});case 21:return e.abrupt("return",r);case 24:if(e.prev=24,e.t0=e.catch(0),!e.t0.userMessage){e.next=28;break}throw e.t0;case 28:throw new m(500,"Ooops! Something went wrong while updating book");case 29:case"end":return e.stop()}}),e,this,[[0,24]])}))),function(e,t){return a.apply(this,arguments)})},{key:"getUserGenres",value:(o=_e(regeneratorRuntime.mark((function e(t){var r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.getUserBooksAsArray(t);case 3:return r=e.sent,n={},r.forEach((function(e){e.genres&&e.genres.slice(0,2).forEach((function(e){n.hasOwnProperty(e)?n[e]+=1:n[e]=1}))})),e.abrupt("return",n);case 9:if(e.prev=9,e.t0=e.catch(0),console.log(e.t0),!e.t0.userMessage){e.next=14;break}throw e.t0;case 14:throw new m(500,"Ooops! Something went wrong while retrieving user genres");case 15:case"end":return e.stop()}}),e,this,[[0,9]])}))),function(e){return o.apply(this,arguments)})}])&&Ue(t.prototype,r),n&&Ue(t,n),e}(),Te=r(1),Ie=r.n(Te);function De(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 Ee(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?De(Object(r),!0).forEach((function(t){Me(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):De(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function Me(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function qe(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function Ge(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){qe(a,n,o,s,i,"next",e)}function i(e){qe(a,n,o,s,i,"throw",e)}s(void 0)}))}}function We(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)}}var Ye={"2read":"Will be reading",finished:"Finished",stopped:"Stopped reading",update:"Has read",rating:"Has rated",reading:"Started reading",not:"Not reading"},Ne=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,r,n,o,a,s,i;return t=e,(r=[{key:"generateFeed",value:function(e,t,r){var n=r.pages,o=r.rating;return Ye[t]&&e&&""!==e.id&&""!==e.title?{date:Ie()().format("DD MMM YYYY"),message:"".concat(Ye[t]," ").concat(n?n+" pages of ":""),data:{id:e.id,title:e.title,rating:o||null}}:null}},{key:"saveFeed",value:(i=Ge(regeneratorRuntime.mark((function e(t,r,n){var o,a,s,i=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=i.length>3&&void 0!==i[3]?i[3]:{},!(a=this.generateFeed(t,r,o))){e.next=14;break}return e.prev=3,s=this.getUserFeedAsFBCollection(n),e.next=7,s.doc().set(Ee(Ee({},a),{},{timestamp:f.a.firestore.FieldValue.serverTimestamp()}));case 7:e.next=14;break;case 9:if(e.prev=9,e.t0=e.catch(3),!e.t0.userMessage){e.next=13;break}throw e.t0;case 13:throw new m(500,"Something went wrong while recording user feed");case 14:case"end":return e.stop()}}),e,this,[[3,9]])}))),function(e,t,r){return i.apply(this,arguments)})},{key:"getUserFeedAsFBCollection",value:function(e){return f.a.firestore().collection("users").doc(e).collection("feed")}},{key:"getAllUserFeed",value:(s=Ge(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.retrieveUserFeed(t);case 2:if(r=e.sent){e.next=5;break}return e.abrupt("return",{});case 5:return e.abrupt("return",this.formatFeed(r));case 6:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"getUserFeedByDate",value:(a=Ge(regeneratorRuntime.mark((function e(t,r){var n,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=Ie()(r,"DD MMM YYYY")){e.next=3;break}throw new m(400,"Invalid date parameter");case 3:return e.next=5,this.retrieveUserFeed(t);case 5:if(o=e.sent){e.next=8;break}return e.abrupt("return",{});case 8:if(a=this.formatFeed(o),s=Object.keys(a).find((function(e){var t=Ie()(e,"DD MMM YYYY");return n.isSame(t,"days")}))){e.next=12;break}return e.abrupt("return",{});case 12:return e.abrupt("return",Me({},s,a[s]));case 13:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"retrieveUserFeed",value:(o=Ge(regeneratorRuntime.mark((function e(t){var r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=this.getUserFeedAsFBCollection(t),e.next=4,r.orderBy("timestamp","desc").get();case 4:if(!(n=e.sent).empty){e.next=9;break}return e.abrupt("return",null);case 9:return e.abrupt("return",n.docs.map((function(e){return e.data()})));case 10:e.next=15;break;case 12:throw e.prev=12,e.t0=e.catch(0),new m(500,"Something went wrong while retrieving user feed");case 15:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e){return o.apply(this,arguments)})},{key:"formatFeed",value:function(e){var t=this.cleanFeed(e),r=this.formatFeedByDate(t);return this.mergeUpdateRecords(r),r}},{key:"cleanFeed",value:function(e){var t=new Map,r=e.filter((function(e){return!!e.message.includes("pages")||!t.has(e.data.id)&&(t.set(e.data.id,e),!0)}));return r.sort(He),r}},{key:"formatFeedByDate",value:function(e){var t={};return e.forEach((function(e){t.hasOwnProperty(e.date)?t[e.date].push(e):t[e.date]=[e]})),t}},{key:"mergeUpdateRecords",value:function(e){var t=this;return Object.keys(e).forEach((function(r){var n=e[r].filter((function(e){return e.message.includes("pages")})),o="";n.forEach((function(a){if(a.data.id!==o||""===o){o=a.data.id;var s=n.filter((function(e){return e.data.id===o})),i=s.reduce(Ve,0),u=t.getMergeIndex(e[r],a.data.id),c=s.length;i>0?e[r].splice(u,c,t.generateFeed(a.data,"update",{pages:i})):e[r].splice(u,c)}}))})),e}},{key:"getMergeIndex",value:function(e,t){var r=e.find((function(e){return e.data.id===t&&e.message.includes("pages")}));return e.indexOf(r)}},{key:"isFeedClean",value:function(e,t){return e.data.id!==t.data.id||e.message.includes("pages")||t.message.includes("pages")}}])&&We(t.prototype,r),n&&We(t,n),e}(),Ve=function(e,t){return e+Number.parseInt(t.message.replace(/[^-\d]/g,""))},He=function(e,t){var r=Ie()(e.date,"DD MMM YYYY"),n=Ie()(t.date,"DD MMM YYYY");return r.isAfter(n)?-1:r.isBefore(n)?1:0},Le=Ne;r(14);function Ke(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 ze(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Ke(Object(r),!0).forEach((function(t){Je(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Ke(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function Je(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Qe(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function Xe(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){Qe(a,n,o,s,i,"next",e)}function i(e){Qe(a,n,o,s,i,"throw",e)}s(void 0)}))}}function Ze(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)}}var $e=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,r,n,o,a,s,i,u,c;return t=e,(r=[{key:"getUserBooksAsFBCollection",value:function(e){return f.a.firestore().collection("users").doc(e).collection("books")}},{key:"getPrivateBookById",value:(c=Xe(regeneratorRuntime.mark((function e(t,r){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.getUserBooksAsFBCollection(t).doc(r).get();case 3:if(!(n=e.sent).exists){e.next=8;break}return e.abrupt("return",ze({id:n.id},n.data()));case 8:throw new m(404,"Book not found");case 9:e.next=16;break;case 11:if(e.prev=11,e.t0=e.catch(0),!e.t0.userMessage){e.next=15;break}throw e.t0;case 15:throw new m(500,"Something went wrong while retrieving user book");case 16:case"end":return e.stop()}}),e,this,[[0,11]])}))),function(e,t){return c.apply(this,arguments)})},{key:"getPrivateBooks",value:(u=Xe(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.getUserBooksAsFBCollection(t).where("private","==",!0).get();case 3:if(!(r=e.sent).empty){e.next=8;break}return e.abrupt("return",[]);case 8:return e.abrupt("return",r.docs.map((function(e){return ze({id:e.id},e.data())})));case 9:e.next=16;break;case 11:if(e.prev=11,e.t0=e.catch(0),!e.t0.userMessage){e.next=15;break}throw e.t0;case 15:throw new m(500,"Something went wrong while retrieving user books");case 16:case"end":return e.stop()}}),e,this,[[0,11]])}))),function(e){return u.apply(this,arguments)})},{key:"saveUserBook",value:(i=Xe(regeneratorRuntime.mark((function e(t,r,n){var o,a,s,i,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,r.title&&r.author&&!Number.isNaN(+r.pages)){e.next=3;break}throw new m(400,"Book information is invalid");case 3:if(o=this.getUserBooksAsFBCollection(t).doc(),a={id:o.id,title:r.title,authors:r.author,pages:+r.pages,imageUrl:"",description:r.description,userData:ze({},new ie),private:!0},n){e.next=19;break}return a.imageUrl="https://s.gr-assets.com/assets/nophoto/book/111x148-bcc042a9c91a29c1d680899eff700a03.png",e.next=9,o.set(a);case 9:return e.next=11,o.get();case 11:if(!(s=e.sent).exists){e.next=16;break}return e.abrupt("return",ze({id:s.id},s.data()));case 16:throw new m(500,"Someting wrong happened while saving private book");case 17:e.next=27;break;case 19:return e.next=21,this.saveBookCover(t,o.id,n);case 21:return i=e.sent,e.next=24,this.updateImageUrl(t,o.id,i,a);case 24:return(u=e.sent).id=o.id,e.abrupt("return",u);case 27:e.next=35;break;case 29:if(e.prev=29,e.t0=e.catch(0),console.log(e.t0),!e.t0.userMessage){e.next=34;break}throw e.t0;case 34:throw new m(500,"Something went wrong while saving private book");case 35:case"end":return e.stop()}}),e,this,[[0,29]])}))),function(e,t,r){return i.apply(this,arguments)})},{key:"saveBookCover",value:(s=Xe(regeneratorRuntime.mark((function e(t,r,n){var o,a,s,i,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=f.a.storage().ref(),a=n.originalname.slice(n.originalname.indexOf(".")),s=o.child(t).child(r).child("cover".concat(a)),i=Uint8Array.from(n.buffer).buffer,u={contentType:n.mimetype},e.next=7,s.put(i,u);case 7:return e.abrupt("return",s.getDownloadURL());case 8:case"end":return e.stop()}}),e)}))),function(e,t,r){return s.apply(this,arguments)})},{key:"updateImageUrl",value:(a=Xe(regeneratorRuntime.mark((function e(t,r,n,o){var a,s,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(a=o).imageUrl=n,s=this.getUserBooksAsFBCollection(t).doc(r),e.next=5,s.set(a);case 5:return e.next=7,s.get();case 7:if(!(i=e.sent).exists){e.next=12;break}return e.abrupt("return",i.data());case 12:throw new m(500,"Something went wrong while saving private book");case 13:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return a.apply(this,arguments)})},{key:"removePrivateBook",value:(o=Xe(regeneratorRuntime.mark((function e(t,r,n){var o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,o=this.getUserBooksAsFBCollection(t),e.next=4,o.doc(r).delete();case 4:if(n.includes("nophoto")){e.next=7;break}return e.next=7,f.a.storage().refFromURL(n).delete();case 7:return e.abrupt("return",!0);case 10:throw e.prev=10,e.t0=e.catch(0),console.log(e.t0),new m(500,"Something went wrong while removing private book");case 14:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(e,t,r){return o.apply(this,arguments)})}])&&Ze(t.prototype,r),n&&Ze(t,n),e}();function et(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function tt(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){et(a,n,o,s,i,"next",e)}function i(e){et(a,n,o,s,i,"throw",e)}s(void 0)}))}}function rt(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)}}var nt=new Pe,ot=new Le,at=new $e,st=new Fe(ot),it=new(function(){function e(t,r,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.userService=t,this.userBooksService=r,this.privateBookService=n,this.getUser=this.getUser.bind(this),this.getUserBooks=this.getUserBooks.bind(this),this.getCollection=this.getCollection.bind(this),this.addToCollection=this.addToCollection.bind(this),this.deleteBook=this.deleteBook.bind(this),this.setFavorite=this.setFavorite.bind(this),this.getFavoriteBooks=this.getFavoriteBooks.bind(this),this.updateBook=this.updateBook.bind(this),this.getUserGenres=this.getUserGenres.bind(this),this.savePrivateBook=this.savePrivateBook.bind(this),this.getAllPrivateBooks=this.getAllPrivateBooks.bind(this),this.getPrivateBookById=this.getPrivateBookById.bind(this),this.removePrivateBook=this.removePrivateBook.bind(this)}var t,r,n,o,a,s,i,u,c,f,l,p,h,d,v,g;return t=e,(r=[{key:"getUser",value:(g=tt(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,console.log("Get User request accepted"),n=ye(t),e.next=5,this.userService.getUserById(n.id);case 5:o=e.sent,r.json(o),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 12:case"end":return e.stop()}}),e,this,[[0,9]])}))),function(e,t){return g.apply(this,arguments)})},{key:"getUserBooks",value:(v=tt(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,console.log("Get User Books request accepted"),n=ye(t),e.next=5,this.userBooksService.getUserBooksAsArray(n.id);case 5:o=e.sent,r.json(o),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 12:case"end":return e.stop()}}),e,this,[[0,9]])}))),function(e,t){return v.apply(this,arguments)})},{key:"getCollection",value:(d=tt(regeneratorRuntime.mark((function e(t,r){var n,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,n=t.params.collection,console.log("Get Books from ".concat(n," request accepted")),n){e.next=5;break}throw new m(400,"Book status is invalid");case 5:return o=ye(t),e.next=8,this.userBooksService.getUserCollection(o.id,n);case 8:a=e.sent,r.json(a),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e,t){return d.apply(this,arguments)})},{key:"addToCollection",value:(h=tt(regeneratorRuntime.mark((function e(t,r){var n,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,n=t.params.collection,console.log("Get Books from ".concat(n," request accepted")),(o=t.body.book)&&n){e.next=6;break}throw new m(400,"Params are invalid");case 6:return a=ye(t),e.next=9,this.userBooksService.addToUserCollection(a.id,n,o);case 9:s=e.sent,r.json(s),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 16:case"end":return e.stop()}}),e,this,[[0,13]])}))),function(e,t){return h.apply(this,arguments)})},{key:"deleteBook",value:(p=tt(regeneratorRuntime.mark((function e(t,r){var n,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("Book Delete Request accepted"),(n=t.query.bookId)&&!isNaN(n)){e.next=5;break}throw new m(400,"Book params are invalid");case 5:return o=ye(t),e.next=8,this.userBooksService.deleteBookFromCollection(o.id,n);case 8:a=e.sent,r.json(a),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e,t){return p.apply(this,arguments)})},{key:"setFavorite",value:(l=tt(regeneratorRuntime.mark((function e(t,r){var n,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("Favorite book request accepted"),n=t.body.book){e.next=5;break}throw new m(400,"Invalid parameter");case 5:return o=ye(t),e.next=8,this.userBooksService.setFavorite(o.id,n);case 8:a=e.sent,r.json(a),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e,t){return l.apply(this,arguments)})},{key:"getFavoriteBooks",value:(f=tt(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,console.log("Get favorite books request accepted"),n=ye(t),e.next=5,this.userBooksService.getFavorites(n.id);case 5:o=e.sent,r.json(o),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 12:case"end":return e.stop()}}),e,this,[[0,9]])}))),function(e,t){return f.apply(this,arguments)})},{key:"updateBook",value:(c=tt(regeneratorRuntime.mark((function e(t,r){var n,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("Update Book request accepted"),n=t.body.book){e.next=5;break}throw new m(400,"Invalid parameter");case 5:return o=ye(t),e.next=8,this.userBooksService.updateBook(o.id,n);case 8:a=e.sent,r.json(a),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e,t){return c.apply(this,arguments)})},{key:"getUserGenres",value:(u=tt(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,console.log("GET User Genres request accepted"),n=ye(t),e.next=5,this.userBooksService.getUserGenres(n.id);case 5:o=e.sent,r.json(o),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 12:case"end":return e.stop()}}),e,this,[[0,9]])}))),function(e,t){return u.apply(this,arguments)})},{key:"savePrivateBook",value:(i=tt(regeneratorRuntime.mark((function e(t,r){var n,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("Save User's private book request accepted"),e.prev=1,n=ye(t),o=t.body,a=t.file,console.log(o),console.log(a),e.next=9,this.privateBookService.saveUserBook(n.id,o,a);case 9:s=e.sent,r.json(s),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(1),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 16:case"end":return e.stop()}}),e,this,[[1,13]])}))),function(e,t){return i.apply(this,arguments)})},{key:"getAllPrivateBooks",value:(s=tt(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("GET User's private books request accepted"),e.prev=1,n=ye(t),e.next=5,this.privateBookService.getPrivateBooks(n.id);case 5:o=e.sent,r.json(o),e.next=12;break;case 9:e.prev=9,e.t0=e.catch(1),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 12:case"end":return e.stop()}}),e,this,[[1,9]])}))),function(e,t){return s.apply(this,arguments)})},{key:"getPrivateBookById",value:(a=tt(regeneratorRuntime.mark((function e(t,r){var n,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("Get User's private book By Id"),e.prev=1,n=ye(t),o=t.params.id,e.next=6,this.privateBookService.getPrivateBookById(n.id,o);case 6:a=e.sent,r.json(a),e.next=13;break;case 10:e.prev=10,e.t0=e.catch(1),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 13:case"end":return e.stop()}}),e,this,[[1,10]])}))),function(e,t){return a.apply(this,arguments)})},{key:"removePrivateBook",value:(o=tt(regeneratorRuntime.mark((function e(t,r){var n,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("Delete User's private book request accepted"),e.prev=1,n=ye(t),o=t.query.id,a=t.query.url,console.log(a),e.next=8,this.privateBookService.removePrivateBook(n.id,o,a);case 8:s=e.sent,r.json(s),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(1),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[1,12]])}))),function(e,t){return o.apply(this,arguments)})}])&&rt(t.prototype,r),n&&rt(t,n),e}())(nt,st,at);function ut(e){return(ut="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ct(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function ft(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)}}function lt(e,t){return(lt=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function pt(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=dt(e);if(t){var o=dt(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return ht(this,r)}}function ht(e,t){return!t||"object"!==ut(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function dt(e){return(dt=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var vt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&<(e,t)}(i,e);var t,r,n,o,a,s=pt(i);function i(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,i),(t=s.call(this)).formatSeriesService=e,t}return t=i,(r=[{key:"getSeriesByGoodreadsId",value:(o=regeneratorRuntime.mark((function e(t){var r,n,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r="".concat(this.root,"series/").concat(t,"?key=").concat(this.devKey),e.next=4,this.getValueFromGoodreads(r);case 4:if(n=e.sent,o=this.findValue(n,"series"),a=this.findValue(o,"author"),o){e.next=9;break}throw new ErrorWithHttpCode(404,"Data was not found");case 9:return(s=this.formatSeriesService.formatSeriesForSeriesPage(o)).author=this.formatSeriesService.formatSeriesAuthor(a),e.abrupt("return",s);case 14:if(e.prev=14,e.t0=e.catch(0),!e.t0.userMessage){e.next=18;break}throw e.t0;case 18:throw new ErrorWithHttpCode(e.t0.httpCode||500,e.t0.message);case 19:case"end":return e.stop()}}),e,this,[[0,14]])})),a=function(){var e=this,t=arguments;return new Promise((function(r,n){var a=o.apply(e,t);function s(e){ct(a,r,n,s,i,"next",e)}function i(e){ct(a,r,n,s,i,"throw",e)}s(void 0)}))},function(e){return a.apply(this,arguments)})}])&&ft(t.prototype,r),n&&ft(t,n),i}(z);function gt(e){return(gt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function yt(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)}}function bt(e,t){return(bt=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function mt(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=kt(e);if(t){var o=kt(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return wt(this,r)}}function wt(e,t){return!t||"object"!==gt(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function kt(e){return(kt=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var xt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&bt(e,t)}(a,e);var t,r,n,o=mt(a);function a(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),o.call(this)}return t=a,(r=[{key:"formatSeriesAuthor",value:function(e){return e.name._text}},{key:"formatSeriesForAuthorPage",value:function(e){return e.filter((function(e,t,r){return t===r.findIndex((function(t){var r=t.series.title._cdata,n=e.series.title._cdata;return r.toLowerCase()===n.toLowerCase()}))})).map((function(e){return{id:e.series.id._text,title:e.series.title._cdata,rating:e.work.ratings_sum._text}})).sort((function(e,t){return t.rating-e.rating}))}},{key:"formatSeriesForSeriesPage",value:function(e){var t={id:e.id._text,title:e.title._cdata,workCount:e.primary_work_count._text,allWorks:e.series_works_count._text};return t.bookIds=this.formatSeriesWork(e,t.workCount),t}},{key:"formatSeriesWork",value:function(e,t){return e.series_works.series_work.slice(0,t).map((function(e){return e.work.best_book.id._text}))}}])&&yt(t.prototype,r),n&&yt(t,n),a}(se);function St(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function Rt(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)}}var Ot=new vt(new xt),Bt=new(function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.goodreadsSeriesService=t,this.getSeriesById=this.getSeriesById.bind(this)}var t,r,n,o,a;return t=e,(r=[{key:"getSeriesById",value:(o=regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("Get Series By Id request accepted!"),(n=t.params.id)&&!isNaN(n)){e.next=5;break}throw new m(400,"Series id is empty");case 5:return ye(t),e.next=8,this.goodreadsSeriesService.getSeriesByGoodreadsId(n);case 8:o=e.sent,r.json(o),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[0,12]])})),a=function(){var e=this,t=arguments;return new Promise((function(r,n){var a=o.apply(e,t);function s(e){St(a,r,n,s,i,"next",e)}function i(e){St(a,r,n,s,i,"throw",e)}s(void 0)}))},function(e,t){return a.apply(this,arguments)})}])&&Rt(t.prototype,r),n&&Rt(t,n),e}())(Ot);function jt(e){return(jt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Pt(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function Ct(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){Pt(a,n,o,s,i,"next",e)}function i(e){Pt(a,n,o,s,i,"throw",e)}s(void 0)}))}}function _t(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)}}function Ut(e,t){return(Ut=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function At(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=Tt(e);if(t){var o=Tt(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return Ft(this,r)}}function Ft(e,t){return!t||"object"!==jt(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function Tt(e){return(Tt=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function It(e){return(It="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Dt(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)}}function Et(e,t){return(Et=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function Mt(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=Gt(e);if(t){var o=Gt(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return qt(this,r)}}function qt(e,t){return!t||"object"!==It(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function Gt(e){return(Gt=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Wt(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function Yt(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function s(e){Wt(a,n,o,s,i,"next",e)}function i(e){Wt(a,n,o,s,i,"throw",e)}s(void 0)}))}}function Nt(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)}}var Vt=new(function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Ut(e,t)}(u,e);var t,r,n,o,a,s,i=At(u);function u(e,t){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u),(r=i.call(this)).formatAuthorService=e,r.formatSeriesService=t,r}return t=u,(r=[{key:"getAuthorByGoodreadsId",value:(s=Ct(regeneratorRuntime.mark((function e(t){var r,n,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r="".concat(this.root,"author/show/").concat(t,"?key=").concat(this.devKey),e.next=4,this.getValueFromGoodreads(r);case 4:if(n=e.sent,o=this.findValue(n,"author"),a=this.findValue(n,"books"),o&&a){e.next=9;break}throw new ErrorWithHttpCode(404,"Data was not found");case 9:return o=this.formatAuthorService.formatAuthorForAuthorPage(o,a),e.abrupt("return",o);case 13:if(e.prev=13,e.t0=e.catch(0),console.log(e.t0),!e.t0.userMessage){e.next=18;break}throw e.t0;case 18:throw new ErrorWithHttpCode(e.t0.httpCode||500,e.t0.message);case 19:case"end":return e.stop()}}),e,this,[[0,13]])}))),function(e){return s.apply(this,arguments)})},{key:"getAuthorBooks",value:(a=Ct(regeneratorRuntime.mark((function e(t){var r,n,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r="".concat(this.root,"author/list/").concat(t,"?key=").concat(this.devKey),e.next=4,this.getValueFromGoodreads(r);case 4:if(n=e.sent,o=this.findValue(n,"author"),o=this.formatAuthorService.formatAuthorMin(o),(a=this.findValue(n,"books"))&&!(a.length<1)){e.next=10;break}throw new ErrorWithHttpCode(404,"Data was not found");case 10:return s=this.formatAuthorService.formatAuthorBooks(a),e.abrupt("return",{author:o,bookIds:s});case 14:if(e.prev=14,e.t0=e.catch(0),console.log(e.t0),!e.t0.userMessage){e.next=19;break}throw e.t0;case 19:throw new ErrorWithHttpCode(e.t0.httpCode||500,e.t0.message);case 20:case"end":return e.stop()}}),e,this,[[0,14]])}))),function(e){return a.apply(this,arguments)})},{key:"getAuthorSeries",value:(o=Ct(regeneratorRuntime.mark((function e(t){var r,n,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r="".concat(this.root,"series/list/").concat(t,".xml?key=").concat(this.devKey),e.next=4,this.getValueFromGoodreads(r);case 4:if(n=e.sent,o=this.findValue(n,"series_work")){e.next=8;break}throw new ErrorWithHttpCode(404,"Data was not found");case 8:return a=this.formatSeriesService.formatSeriesForAuthorPage(o),e.abrupt("return",a);case 12:if(e.prev=12,e.t0=e.catch(0),console.log(e.t0),!e.t0.userMessage){e.next=17;break}throw e.t0;case 17:throw new ErrorWithHttpCode(e.t0.httpCode||500,e.t0.message);case 18:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e){return o.apply(this,arguments)})}])&&_t(t.prototype,r),n&&_t(t,n),u}(z))(new(function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Et(e,t)}(a,e);var t,r,n,o=Mt(a);function a(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),o.call(this)}return t=a,(r=[{key:"formatAuthorForAuthorPage",value:function(e,t){return{id:e.id._text,name:e.name._text,imageUrl:e.large_image_url._cdata,about:this.formatDescription(e.about._cdata),workCount:e.works_count._text,bornDate:e.born_at._text,deathDate:e.died_at._text,bookIds:this.formatAuthorBooks(t)}}},{key:"formatAuthorMin",value:function(e){return{name:e.name._text}}},{key:"formatAuthorBooks",value:function(e){var t=e.book;return this.mapArrayIds(t)}}])&&Dt(t.prototype,r),n&&Dt(t,n),a}(se)),new xt),Ht=new(function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.goodreadsAuthorService=t,this.getAuthorInfo=this.getAuthorInfo.bind(this),this.getAuthorBooks=this.getAuthorBooks.bind(this),this.getAuthorSeries=this.getAuthorSeries.bind(this)}var t,r,n,o,a,s;return t=e,(r=[{key:"getAuthorInfo",value:(s=Yt(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("Get Author request accepted!"),(n=t.params.id)&&!isNaN(n)){e.next=5;break}throw new m(400,"Request param is not valid");case 5:return ye(t),e.next=8,this.goodreadsAuthorService.getAuthorByGoodreadsId(n);case 8:o=e.sent,r.json(o),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e,t){return s.apply(this,arguments)})},{key:"getAuthorBooks",value:(a=Yt(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("Get Author's Books request accepted"),n=t.params.id){e.next=5;break}throw new m(400,"Request param is not valid");case 5:return ye(t),e.next=8,this.goodreadsAuthorService.getAuthorBooks(n);case 8:o=e.sent,r.json(o),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e,t){return a.apply(this,arguments)})},{key:"getAuthorSeries",value:(o=Yt(regeneratorRuntime.mark((function e(t,r){var n,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("Get Author's Series request accepted"),n=t.params.id){e.next=5;break}throw new m(400,"Request param is not valid");case 5:return ye(t),e.next=8,this.goodreadsAuthorService.getAuthorSeries(n);case 8:o=e.sent,r.json(o),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(0),r.status(e.t0.httpCode).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 15:case"end":return e.stop()}}),e,this,[[0,12]])}))),function(e,t){return o.apply(this,arguments)})}])&&Nt(t.prototype,r),n&&Nt(t,n),e}())(Vt);function Lt(e,t,r,n,o,a,s){try{var i=e[a](s),u=i.value}catch(e){return void r(e)}i.done?t(u):Promise.resolve(u).then(n,o)}function Kt(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)}}var zt=new Le,Jt=new(function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.feedService=t,this.getFeed=this.getFeed.bind(this)}var t,r,n,o,a;return t=e,(r=[{key:"getFeed",value:(o=regeneratorRuntime.mark((function e(t,r){var n,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,console.log("Get Feed request accepted"),n=t.query.date,o=ye(t),n){e.next=10;break}return e.next=7,this.feedService.getAllUserFeed(o.id);case 7:a=e.sent,e.next=13;break;case 10:return e.next=12,this.feedService.getUserFeedByDate(o.id,n);case 12:a=e.sent;case 13:r.json(a),e.next=19;break;case 16:e.prev=16,e.t0=e.catch(0),r.status(e.t0.httpCode||500).json({httpCode:e.t0.httpCode,message:e.t0.userMessage});case 19:case"end":return e.stop()}}),e,this,[[0,16]])})),a=function(){var e=this,t=arguments;return new Promise((function(r,n){var a=o.apply(e,t);function s(e){Lt(a,r,n,s,i,"next",e)}function i(e){Lt(a,r,n,s,i,"throw",e)}s(void 0)}))},function(e,t){return a.apply(this,arguments)})}])&&Kt(t.prototype,r),n&&Kt(t,n),e}())(zt),Qt=r(10),Xt=r.n(Qt)()(),Zt=r(11),$t=r.n(Zt);global.XMLHttpRequest=r(15);var er,tr=o()(),rr=process.env.PORT;null!=rr&&""!=rr||(rr=4200),tr.use(u()()),tr.use(s.a.urlencoded({extended:!1})),tr.use(s.a.json()),(er=tr).post("/auth/login",M.signInUser),er.post("/auth/register",M.signUpUser),er.post("/auth/google/login",M.signInWithGoogle),er.get("/auth/twitter/url",M.getRequestUrl),er.post("/auth/twitter/login",M.signInWithTwitter),er.get("/books/search",xe.searchByTitleOrAuthor),er.get("/books/:bookId",xe.getBookById),er.get("/user",it.getUser),er.get("/user/books",it.getUserBooks),er.get("/user/books/favorite",it.getFavoriteBooks),er.post("/user/books/favorite",it.setFavorite),er.get("/user/books/:collection",it.getCollection),er.post("/user/books/:collection",it.addToCollection),er.delete("/user/books",it.deleteBook),er.put("/user/books",it.updateBook),er.get("/user/genres",it.getUserGenres),er.get("/user/feed",Jt.getFeed),er.get("/series/:id",Bt.getSeriesById),er.get("/author/:id",Ht.getAuthorInfo),er.get("/author/:id/books",Ht.getAuthorBooks),er.get("/author/:id/series",Ht.getAuthorSeries),er.get("/user/upload",it.getAllPrivateBooks),er.get("/user/upload/:id",it.getPrivateBookById),er.post("/user/upload",Xt.single("cover"),it.savePrivateBook),er.delete("/user/upload",it.removePrivateBook),$t.a.initializeApp({apiKey:"AIzaSyBJquLDDsi6VJl8kJQ8zRqAHHyGG0SLD9o",authDomain:"bookshelf-a2203.firebaseapp.com",databaseURL:"https://bookshelf-a2203.firebaseio.com",projectId:"bookshelf-a2203",storageBucket:"bookshelf-a2203.appspot.com",messagingSenderId:"942217212778",appId:"1:942217212778:web:2795a60ea9260c875f6b13",measurementId:"G-SV2WRHQ6G2"}),tr.listen(rr,(function(){return console.log("Started on port ".concat(rr,"!"))}));t.default=tr}]);