UNPKG

@bolttech/server-side-next

Version:

This library was generated with [Nx](https://nx.dev).

3 lines (2 loc) 15.8 kB
"use strict";var e=require("./_rollupPluginBabelHelpers-41c00fec.js"),r=require("./_tslib-0e64cda4.js"),t=require("lodash"),n=require("@edirect/request"),o=require("@edirect/oidc-client"),s=require("./logger.service-16a2faf9.js"),i=require("lodash/fp");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a,c,d,p=u(o),v=new(function(){return e._createClass((function r(){e._classCallCheck(this,r),this.serverClient=null,this.userClient=null,this.userRetries=0,this.serverRetries=0}),[{key:"createClient",value:function(t){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",p.default(Object.assign({baseUrl:process.env.AUTH_SERVICE_URL||s.configService.get("AUTH_SERVICE_URL"),oidcPath:process.env.AUTH_SERVICE_OIDC_PATH||s.configService.get("AUTH_SERVICE_OIDC_PATH"),clientId:process.env.AUTH_SERVICE_CLIENT_ID||s.configService.get("AUTH_SERVICE_CLIENT_ID"),clientSecret:process.env.AUTH_SERVICE_CLIENT_SECRET||s.configService.get("AUTH_SERVICE_CLIENT_SECRET")},t)));case 1:case"end":return e.stop()}}),r)})))}},{key:"getServerClient",value:function(){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,this.serverClient){e.next=7;break}return s.loggerService.debug("[serverClient] Connecting to auth-service..."),e.next=5,this.createClient({grantType:"client_credentials"});case 5:this.serverClient=e.sent,s.loggerService.debug("[serverClient] Successfully connection to auth-service.");case 7:return e.abrupt("return",this.serverClient);case 10:return e.prev=10,e.t0=e.catch(0),s.loggerService.error("[serverClient] Error connecting to auth-service: ",e.t0),this.serverRetries||(this.serverRetries=0),this.serverRetries++,5===this.serverRetries&&s.loggerService.error("[serverClient] Limit number of attempts reached",e.t0),e.abrupt("return",this.getUserClient());case 17:case"end":return e.stop()}}),r,this,[[0,10]])})))}},{key:"getUserClient",value:function(){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,this.userClient){e.next=7;break}return s.loggerService.debug("[userClient] Connecting to auth-service..."),e.next=5,this.createClient({grantType:"client_credentials"});case 5:this.userClient=e.sent,s.loggerService.debug("[userClient] Successfully connection to auth-service.");case 7:return e.abrupt("return",this.userClient);case 10:return e.prev=10,e.t0=e.catch(0),s.loggerService.error("[userClient] Error connecting to auth-service: ",e.t0),this.userRetries||(this.userRetries=0),this.userRetries++,5===this.userRetries&&s.loggerService.error("[userClient] Limit number of attempts reached",e.t0),e.abrupt("return",this.getUserClient());case 17:case"end":return e.stop()}}),r,this,[[0,10]])})))}}])}()),h=new(function(){return e._createClass((function r(){e._classCallCheck(this,r)}),[{key:"sendServerRequest",value:function(e,r,t){return this.getClientToken().then((function(o){var s=o.accessToken;return n.sendRequest("auth-service",{headers:{Authorization:"Bearer ".concat(s)}}).request(e,r,t)}))}},{key:"sendUserRequest",value:function(e,r,t,o){return n.sendRequest("auth-service",{headers:{Authorization:"".concat(e.tokenType," ").concat(e.accessToken)}}).request(r,t,o)}},{key:"createUser",value:function(e){return this.sendServerRequest("POST","/user",e)}},{key:"createUserExternal",value:function(e){return this.sendServerRequest("POST","/user/external",e)}},{key:"updateUser",value:function(e,r){return this.sendServerRequest("PUT","/user/".concat(e),r)}},{key:"sendConfirmationEmail",value:function(e){return this.sendServerRequest("POST","/user/confirm",e)}},{key:"getUser",value:function(e){return this.sendServerRequest("GET","/user/".concat(e))}},{key:"getUsers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.sendServerRequest("GET","/user?".concat(new URLSearchParams(e)))}},{key:"newRecoverPassword",value:function(e){return this.sendServerRequest("PATCH","/user/recover-password",e)}},{key:"setNewPassword",value:function(e,r,t){return this.sendServerRequest("PUT","/user/recover-password/".concat(e,"/").concat(r),t)}},{key:"getClientToken",value:function(){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){var t;return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,v.getServerClient();case 2:return t=e.sent,e.abrupt("return",t.getAccessToken({scope:"openid accountId username status roles permissions entityUser"}));case 4:case"end":return e.stop()}}),r)})))}},{key:"getAccessToken",value:function(t,n,o){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){var s;return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,v.getUserClient();case 2:return s=e.sent,e.abrupt("return",s.getAccessToken({scope:"openid accountId username status roles permissions entityUser",username:t,password:n,passwordPlainText:o}));case 4:case"end":return e.stop()}}),r)})))}},{key:"getRefreshToken",value:function(t){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){var n;return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,v.getUserClient();case 2:return n=e.sent,e.abrupt("return",n.getRefreshToken(t));case 4:case"end":return e.stop()}}),r)})))}},{key:"getAccount",value:function(e){return this.sendUserRequest(e,"GET","/oidc/me").then((function(e){var r=e,t=Object.assign(Object.assign({},r),{user:r.entityUser});return delete t.entityUser,t}))}},{key:"validateToken",value:function(e){return this.sendServerRequest("POST","/token/validate",{jwt:e})}}])}()),l=[200,201,202,204],_=new(function(){return e._createClass((function r(t){e._classCallCheck(this,r),this.baseURL=t||process.env.INSURTECH_GATEWAY_URL||s.configService.get("INSURTECH_GATEWAY_URL"),this.http=new n.SendRequest}),[{key:"sendRequest",value:function(o,s,i,u,a){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.isEmpty(u)){e.next=4;break}return e.next=3,h.getClientToken();case 3:u=e.sent;case 4:return!0,e.abrupt("return",this.http.sendRequest("",{baseURL:this.baseURL,headers:Object.assign({Authorization:"".concat(null==u?void 0:u.tokenType," ").concat(null==u?void 0:u.accessToken)},a)}).request(o,s,i,void 0,true).then((function(e){var r=e;if(!l.includes(r.status))throw r.data;return n.parseJSON(r.data)})));case 6:case"end":return e.stop()}}),r,this)})))}}])}()),E=["insuredPersons","car","motorcycle","property","applicant","device","insuredHome","certificate","taxInformation"],g=function(){return e._createClass((function r(){e._classCallCheck(this,r)}),[{key:"sendRequest",value:function(t,n,o,s){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",_.sendRequest(t,n,o,s).then((function(e){return e.result})));case 1:case"end":return e.stop()}}),r)})))}},{key:"getQuoteById",value:function(t,n){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.abrupt("return",this.sendRequest("GET","/quotes/".concat(t),void 0,n));case 4:throw e.prev=4,e.t0=e.catch(0),s.loggerService.error("Error on getQuoteById:",e.t0),new Error("Error on getQuoteById: ".concat(e.t0));case 8:case"end":return e.stop()}}),r,this,[[0,4]])})))}},{key:"getQuoteByHash",value:function(t,n,o){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){var i,u;return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.getQuoteIdByHash(t,n,o);case 3:return i=e.sent,u=i.quoteId,e.next=7,this.getQuoteById(u,o);case 7:return e.abrupt("return",e.sent);case 10:throw e.prev=10,e.t0=e.catch(0),s.loggerService.error("Error on getQuoteByHash:",e.t0),new Error("Error on getQuoteByHash: ".concat(e.t0));case 14:case"end":return e.stop()}}),r,this,[[0,10]])})))}},{key:"getQuoteIdByHash",value:function(t,n,o){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.abrupt("return",this.sendRequest("GET","/quote-hashes?h=".concat(t,"&x=").concat(n),void 0,o));case 4:throw e.prev=4,e.t0=e.catch(0),s.loggerService.error("Error on getQuoteIdByHash:",e.t0),new Error("Error on getQuoteIdByHash: ".concat(e.t0));case 8:case"end":return e.stop()}}),r,this,[[0,4]])})))}},{key:"getQuoteHashById",value:function(t,n){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.abrupt("return",this.sendRequest("GET","/quotes/".concat(t,"/hashes"),void 0,n));case 4:throw e.prev=4,e.t0=e.catch(0),s.loggerService.error("Error on getQuoteHashById:",e.t0),new Error("Error on getQuoteHashById: ".concat(e.t0));case 8:case"end":return e.stop()}}),r,this,[[0,4]])})))}},{key:"createQuote",value:function(e,r){try{return this.sendRequest("POST","/quotes",e,r||e.tokenSet)}catch(e){throw s.loggerService.error("Error on createQuote:",e),new Error("Error on createQuote: ".concat(e))}}},{key:"updateQuoteByHash",value:function(t,n,o,i){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){var u,a;return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.getQuoteIdByHash(t,n,i);case 3:return u=e.sent,a=u.quoteId,e.next=7,this.updateQuoteById(a,o,i);case 7:e.next=13;break;case 9:throw e.prev=9,e.t0=e.catch(0),s.loggerService.error("Error on updateQuoteByHash:",e.t0),new Error("Error on updateQuoteByHash: ".concat(e.t0));case 13:case"end":return e.stop()}}),r,this,[[0,9]])})))}},{key:"updateQuoteById",value:function(t,n,o){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){var u,a;return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,u=i.pick(E,n),!Object.keys(u).length||n.planState){e.next=9;break}return e.next=5,this.putWithMerge(t,u,o);case 5:if(a=e.sent,E.forEach((function(e){delete n[e]})),!i.isEmpty(n)){e.next=9;break}return e.abrupt("return",a);case 9:return e.abrupt("return",this.sendRequest("PUT","/quotes/".concat(t),n,o));case 12:throw e.prev=12,e.t0=e.catch(0),s.loggerService.error("Error on updateQuote:",e.t0),new Error("Error on updateQuote: ".concat(e.t0));case 16:case"end":return e.stop()}}),r,this,[[0,12]])})))}},{key:"putWithMerge",value:function(e,r,t){try{return this.sendRequest("PUT","/quotes/".concat(e),Object.assign(Object.assign({},r),{mergeData:!0}),t)}catch(e){throw s.loggerService.error("Error on putWithMerge:",e),new Error("Error on putWithMerge: ".concat(e))}}},{key:"put",value:function(r,t,n,o){try{var i=e._defineProperty({},r,t);return this.updateQuoteById(n,i,o)}catch(e){throw s.loggerService.error("Error on put:",e),new Error("Error on put: ".concat(e))}}},{key:"putMany",value:function(t,n,o){return r.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function r(){var i;return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,n){e.next=3;break}return e.abrupt("return");case 3:return i=Object.assign({},t),e.abrupt("return",this.updateQuoteById(n,i,o));case 7:throw e.prev=7,e.t0=e.catch(0),s.loggerService.error("Error on putMany:",e.t0),new Error("Error on putMany: ".concat(e.t0));case 11:case"end":return e.stop()}}),r,this,[[0,7]])})))}},{key:"duplicateQuote",value:function(e,r){try{return this.sendRequest("POST","/quotes/duplicate",{quoteId:e},r)}catch(e){throw s.loggerService.error("Error on duplicateQuote:",e),new Error("Error on duplicateQuote: ".concat(e))}}},{key:"updateExternalReferenceCodeToEntityUserId",value:function(e,r,t,n){try{return this.sendRequest("POST","/quotes/external-reference-code",{externalReferenceCode:e,entityUserId:r,entityId:t},n)}catch(e){throw s.loggerService.error("Error on updateExternalReferenceCodeToEntityUserId:",e),new Error("Error on updateExternalReferenceCodeToEntityUserId: ".concat(e))}}},{key:"resetVoucher",value:function(e,r){try{return this.sendRequest("GET","/quotes/".concat(e,"/reset-voucher"),void 0,r)}catch(e){throw s.loggerService.error("Error on resetVoucher:",e),new Error("Error on resetVoucher: ".concat(e))}}},{key:"hasInsuredPolicy",value:function(e,r){try{return this.sendRequest("GET","/quotes/".concat(e,"/validation/insured"),void 0,r)}catch(e){throw s.loggerService.error("Error on hasInsuredPolicy:",e),new Error("Error on hasInsuredPolicy: ".concat(e))}}}])}(),f=new g;exports.QUOTE_STATUS=void 0,(a=exports.QUOTE_STATUS||(exports.QUOTE_STATUS={})).IN_PROGRESS="in_progress",a.PAID="paid",a.ISSUED="issued",a.REFUNDED="refunded",a.ARCHIVED="archived",a.CANCELED="canceled",exports.QUOTE_SUB_STATUS=void 0,(c=exports.QUOTE_SUB_STATUS||(exports.QUOTE_SUB_STATUS={})).EMPTY="",c.PENDING_QUOTATION="pending_quotation",c.PENDING_PRODUCT_SELECTION="pending_product_selection",c.PENDING_PAYMENT_DETAILS="pending_payment_details",c.PENDING_CUSTOMER_PAYMENT="pending_customer_payment",c.PENDING_CUSTOMER_DETAILS="pending_customer_details",c.PENDING_DETAILS="pending_details",c.INVITED="invited",c.INVITE_OPENED="invite_opened",c.PLAN_SELECTED="plan_selected",exports.ORDER_STATUS=void 0,(d=exports.ORDER_STATUS||(exports.ORDER_STATUS={})).ORDER_PENDING="order.pending",d.ORDER_COMPLETED="order.completed";var S;!function(e){e.YES="Y",e.NO="N"}(S||(S={})),exports.PERMISSIONS_OMITTING_FIELDS={"QUOTE.ENTITY.SHOW_COMMISSION":["order.agentCommissionValue","order.agentCommissionOfferedEarned","order.agentCommissionOfferedValue","order.formatted.agentCommissionOfferedEarned","order.formatted.agentCommissionValue","order.formatted.agentCommissionOfferedValue"]},exports.QUOTEHASH_STATUS={CREATED:"created",SENT:"sent",CLICKED:"clicked",PAID:"paid",REVOKED:"revoked"},exports.QuoteService=g,exports.STATUS={IN_PROGRESS:"in_progress",PAID:"paid",ISSUED:"issued",REFUNDED:"refunded",ARCHIVED:"archived",CANCELED:"canceled"},exports.SUBSTATUS={LICENSED:{PENDING_QUOTATION:"pending_quotation",PENDING_PRODUCT_SELECTION:"pending_product_selection",PENDING_PAYMENT_DETAILS:"pending_payment_details",PENDING_CUSTOMER_PAYMENT:"pending_customer_payment"},UNLICENSED:{PENDING_QUOTATION:"pending_quotation",PENDING_CUSTOMER_DETAILS:"pending_customer_details",INVITE_SENT:"invite_sent",QUOTE_VIEWED:"quote_viewed",PLAN_SELECTED:"plan_selected"}},exports.authService=h,exports.crmStatusReason=[1,2,3,4,5,6,7,8,9,10,11,12],exports.gatewayService=_,exports.oidcService=v,exports.pickFieldsOnPaymentConfirmed=["policyIssued","policies","policiesStatus","status","substatus","order","scoreForm"],exports.quoteHashStatuses=["created","sent","clicked","paid","revoked"],exports.quoteParams=["h","x"],exports.quoteService=f,exports.quoteStatus=["in_progress","paid","issued","refunded","archived","canceled"],exports.quoteSubStatus=["","pending_quotation","pending_product_selection","pending_payment_details","pending_customer_payment","pending_customer_details","pending_quotation","pending_details","invited","invite_opened","plan_selected"]; //# sourceMappingURL=quote.constants-da151fc5.js.map