UNPKG

@bolttech/server-side-next

Version:

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

3 lines (2 loc) 12.5 kB
"use strict";var e=require("./_rollupPluginBabelHelpers-41c00fec.js"),t=require("@bolttech/essentials"),r=require("ua-parser-js"),n=require("./_tslib-0e64cda4.js"),a=require("lodash");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s,o,c=i(r);!function(e){e.B2B="b2b",e.B2C="b2c"}(s||(s={})),exports.HttpStatusEnum=void 0,(o=exports.HttpStatusEnum||(exports.HttpStatusEnum={})).notFound="404",o.serverError="500";var l,u=e._defineProperty(e._defineProperty(e._defineProperty(e._defineProperty(e._defineProperty(e._defineProperty(e._defineProperty(e._defineProperty({},t.Vertical.CarInsurance,t.VerticalComponentMapper[t.Vertical.CarInsurance]),t.Vertical.PersonalAccidentInsurance,t.VerticalComponentMapper[t.Vertical.PersonalAccidentInsurance]),t.Vertical.MotorcycleInsurance,t.VerticalComponentMapper[t.Vertical.MotorcycleInsurance]),t.Vertical.TravelInsurance,t.VerticalComponentMapper[t.Vertical.TravelInsurance]),t.Vertical.CriticalIllnessInsurance,t.VerticalComponentMapper[t.Vertical.CriticalIllnessInsurance]),t.Vertical.HealthInsurance,t.VerticalComponentMapper[t.Vertical.HealthInsurance]),t.Vertical.PropertyInsurance,t.VerticalComponentMapper[t.Vertical.PropertyInsurance]),t.Vertical.ECancerLifeInsurance,t.VerticalComponentMapper[t.Vertical.ECancerLifeInsurance]),p=function(){function r(){e._classCallCheck(this,r),this._country="th-TH",this._locale="th",this._vertical=t.Vertical.CarInsurance,this._source=s.B2C,this._flow="Direct",this._request=null,this._device=null}return e._createClass(r,[{key:"locale",get:function(){return this._locale}},{key:"vertical",get:function(){return this._vertical}},{key:"country",get:function(){return this._country}},{key:"source",get:function(){return this._source}},{key:"flow",get:function(){return this._flow}},{key:"request",get:function(){return this._request}},{key:"device",get:function(){return this._device}},{key:"setLocale",value:function(e){return this._locale=e,this}},{key:"setVertical",value:function(e){return this._vertical=e,this}},{key:"setRequest",value:function(e){return this._request=e,this}},{key:"setCountry",value:function(e){return this._country=e||this._country,this}},{key:"setDevice",value:function(e){return this._device=e||(this.isMobileDevice()?"mobile":"desktop"),this}},{key:"setSource",value:function(e){return this._source=e||this._source,this}},{key:"setFlow",value:function(e){return this._flow=e||this._flow,this}},{key:"isMobileDevice",value:function(){var e;return"mobile"===new c.default(null===(e=this._request)||void 0===e?void 0:e.headers["user-agent"]).getDevice().type}}],[{key:"getInstance",value:function(){return!(arguments.length>0&&void 0!==arguments[0]&&arguments[0])&&r.instance||(r.instance=new r),r.instance}}])}(),h=function(t){var r="",n="";try{if(r=(t.htmlContent||"").replace(/<style((.|\n|\r)*?)<\/style>/gm,"").replace(/<edi((.|\n|\r)*?)<\/edi((.|\n|\r)*?)>/gm,"").replace(/<meta charset="utf-8" \/>/gm,"").replace(/<meta name="viewport" content="width=device-width, initial-scale=1">/gm,"").replace(/<\/meta>/gm,"").replace(/<center>/gm,"").replace(/<\/center>/gm,"").replace(/ & /gm," &amp; ").replace(/'/gm,"&rsquo;").replace(/ 100=""/gm,"").replace(/<br>/gm,"<br />").replace(/<\/br>/gm,"<br />").replace(/<a(.*?)(target="_blank")((.|\n|\r)*?)<\/a>/gm,'<a$1$2 rel="noreferrer"$3</a>').replace(/<!--((.|\n|\r)*?)-->/gm,""),"production"===process.env.NODE_ENV){var a=(r=r.replace(/class=/gm,"className=").replace(/srcset=/gm,"srcSet=")).match(/ style="([^.]+?)"/gm),i=!!a&&a.reduce((function(t,r){return Object.assign(Object.assign({},t),e._defineProperty({},r,r.replace(/ style="([^.]+?)"/gm,"$1").split(";").reduce((function(t,r){if(!r)return t;var n=r.split(":"),a=n[0].trim().replace(/-([a-z])/g,(function(e){return e[1].toUpperCase()}));return Object.assign(Object.assign({},t),e._defineProperty({},a,n[1].trim()))}),{})))}),{})||{};Object.keys(i).forEach((function(e){r=r.replace(new RegExp(e,"g")," style={".concat(JSON.stringify(i[e]),"}"))}))}var s=(t.htmlContent||"").replace(/<style>/gm,'<style type="text/css">').match(/<style.+>((.|\n|\r)*?)<\/style>/gm);s&&(n=s.map((function(e){return e.replace(/<style((.|\n|\r)*?)>/gm,"").replace(/<\/style>/gm,"")})).join("").replace(/url\((?!"|')(.+)(?!"|')\)/gm,"url('$1')"))}catch(e){console.error("error",e)}return{bodyParsed:r,cssParsed:n}},d=function(t){function r(t,n,a,i){var s;return e._classCallCheck(this,r),(s=e._callSuper(this,r)).cmsService=t,s.cmsHelper=n,s.loggerService=a,s.page=i,s}return e._inherits(r,t),e._createClass(r,[{key:"renderChildrenFromId",value:function(){var t;return n.__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(!(null===(t=this.page.children_ids)||void 0===t?void 0:t.length)){e.next=6;break}return e.next=3,this.cmsService.renderPagesComponentsById(this.page.children_ids,this.importMapper);case 3:e.t0=e.sent,e.next=7;break;case 6:e.t0=[];case 7:return e.abrupt("return",e.t0);case 8:case"end":return e.stop()}}),r,this)})))}},{key:"renderChildren",value:function(){var t;return n.__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(!(null===(t=this.page.children)||void 0===t?void 0:t.length)){e.next=6;break}return e.next=3,this.cmsService.renderPagesComponents(this.page.children,this.importMapper);case 3:e.t0=e.sent,e.next=7;break;case 6:e.t0=[];case 7:return e.abrupt("return",e.t0);case 8:case"end":return e.stop()}}),r,this)})))}},{key:"mapValueFromEnum",value:function(e){var t=e.typeEnum,r=e.content,n=void 0===r?this.page.content:r,i=e.contentKey,s=e.keyPrefix,o=void 0===s?"option":s,c=e.defaultKey,l=void 0===c?"option1":c,u=e.defaultValue,p=void 0===u?null:u;return t[a.has(n,i)?"".concat(o).concat(this.mapContentField({content:n,contentKey:i,defaultValue:""})):l]||p}},{key:"mapContentField",value:function(e){var t=e.content,r=void 0===t?this.page.content:t,n=e.contentKey,i=e.defaultValue,s=e.returnFirstofArray,o=void 0===s||s;return a.has(r,n)?o&&a.isArray(r[n])?r[n].pop():r[n]:i}},{key:"mapBoolContent",value:function(e){var t=e.content,r=void 0===t?this.page.content:t,n=e.contentKey,i=e.defaultValue,s=void 0!==i&&i;return a.has(r,n)?"1"===r[n]:s}},{key:"mapTextLanguageFields",value:function(e){var t=e.content,r=void 0===t?this.page.content:t,n=e.fieldsToMap,i=this.cmsHelper.locale,s={};return n.forEach((function(e){var t=e.key,n=e.mappedKey,o=e.defaultValue;a.has(r,"".concat(t,".").concat(i))&&r[t][i].length>0?s[n]=r[t][i]:a.isUndefined(o)||(s[n]=o)})),s}},{key:"toPascalCase",value:function(e){return e.replace(/(module_)|(module-)/,"").replace(/(^\w|-\w)|(^\w|_\w)/g,this.clearAndUpper)}},{key:"clearAndUpper",value:function(e){return e.replace(/(-)|(_)/,"").toUpperCase()}}])}(function(){return e._createClass((function t(){e._classCallCheck(this,t)}),[{key:"setMapper",value:function(e){this.importMapper=e}}])}()),m=function(t){function r(){return e._classCallCheck(this,r),e._callSuper(this,r,arguments)}return e._inherits(r,t),e._createClass(r,[{key:"generateComponent",value:function(){return n.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function t(){var r;return e._regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=[],t.t1=e._toConsumableArray,t.next=4,this.renderChildrenFromId();case 4:return t.t2=t.sent,t.t3=(0,t.t1)(t.t2),t.t4=e._toConsumableArray,t.next=9,this.renderChildren();case 9:return t.t5=t.sent,t.t6=(0,t.t4)(t.t5),r=t.t0.concat.call(t.t0,t.t3,t.t6),t.abrupt("return",{name:"FallbackComponent",props:{name:this.toPascalCase(this.page.template)},childrens:r});case 13:case"end":return t.stop()}}),t,this)})))}}])}(d);!function(e){e.lightTitle="lightTitle",e.boldTitle="boldTitle",e.text="text",e.icon="icon",e.url="url"}(l||(l={}));var _,f=function(t){function r(){return e._classCallCheck(this,r),e._callSuper(this,r,arguments)}return e._inherits(r,t),e._createClass(r,[{key:"generateComponent",value:function(){return n.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function t(){var r;return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=this.getProps(),e.abrupt("return",{name:"CardLight",props:r});case 2:case"end":return e.stop()}}),t,this)})))}},{key:"getProps",value:function(){var e={};return Object.assign(e,this.mapTextLanguageFields({fieldsToMap:[{key:"module_card_special_title",mappedKey:"lightTitle"},{key:"module_card_vertical_pill_text",mappedKey:"text"},{key:"module_card_light_url",mappedKey:"url"}]})),e.icon=this.mapContentField({contentKey:"module_card_light_image",defaultValue:""}),e}}])}(d),g=function(t){function r(){return e._classCallCheck(this,r),e._callSuper(this,r,arguments)}return e._inherits(r,t),e._createClass(r,[{key:"generateComponent",value:function(){return n.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function t(){return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",{name:"CustomHtml",props:this.getProps()});case 1:case"end":return e.stop()}}),t,this)})))}},{key:"getProps",value:function(){var e=this.cmsHelper.locale,t=this.page.content.module_simple_html_body_raw[e];"1"===this.page.content.module_simple_html_body_type.pop()&&(t=this.page.content.module_simple_html_body[e]);var r=h({htmlContent:t});return{bodyParsed:r.bodyParsed,cssParsed:r.cssParsed,device:parseInt(this.mapContentField({contentKey:"target_device"}),10)||1}}}])}(d);!function(e){e.boldTitle="boldTitle",e.lightTitle="lightTitle"}(_||(_={}));var v,y=function(t){function r(){return e._classCallCheck(this,r),e._callSuper(this,r,arguments)}return e._inherits(r,t),e._createClass(r,[{key:"generateComponent",value:function(){return n.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function t(){var r,n;return e._regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getProps(),t.t0=[],t.t1=e._toConsumableArray,t.next=5,this.renderChildrenFromId();case 5:return t.t2=t.sent,t.t3=(0,t.t1)(t.t2),t.t4=e._toConsumableArray,t.next=10,this.renderChildren();case 10:return t.t5=t.sent,t.t6=(0,t.t4)(t.t5),n=t.t0.concat.call(t.t0,t.t3,t.t6),t.abrupt("return",{name:"HeroSectionLight",props:r,childrens:n});case 14:case"end":return t.stop()}}),t,this)})))}},{key:"getProps",value:function(){var e={};return Object.assign(e,this.mapTextLanguageFields({fieldsToMap:[{key:"module_section_light_sub_title",mappedKey:"lightTitle"},{key:"module_bubble_title",mappedKey:"boldTitle"}]})),e}}])}(d);!function(e){e.option1="Both",e.option2="Desktop",e.option3="Mobile"}(v||(v={}));var C=function(t){function r(){return e._classCallCheck(this,r),e._callSuper(this,r,arguments)}return e._inherits(r,t),e._createClass(r,[{key:"generateComponent",value:function(){return n.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function t(){return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",{name:"Image",props:this.getProps()});case 1:case"end":return e.stop()}}),t,this)})))}},{key:"getProps",value:function(){var e=this.mapTextLanguageFields({fieldsToMap:[{key:"module_image_alt",mappedKey:"alt"}]}),t=this.mapBoolContent({contentKey:"module_image_grey"}),r=this.mapBoolContent({contentKey:"module_image_disable_lazy_load"}),n=this.mapValueFromEnum({typeEnum:v,contentKey:"target_device"}),a=this.mapContentField({contentKey:"module_image_src",defaultValue:""});return Object.assign(Object.assign({},e),{isGrey:t,lazy:r,targetDevice:n,src:a})}}])}(d),k=function(t){function r(){return e._classCallCheck(this,r),e._callSuper(this,r,arguments)}return e._inherits(r,t),e._createClass(r,[{key:"generateComponent",value:function(){return n.__awaiter(this,void 0,void 0,e._regeneratorRuntime().mark((function t(){var r,n;return e._regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={},e.next=3,this.renderChildrenFromId();case 3:return n=e.sent,e.abrupt("return",{name:"PageModular",props:r,childrens:n});case 5:case"end":return e.stop()}}),t,this)})))}}])}(d);exports.BaseMapper=d,exports.CmsHelper=p,exports.FallbackComponent=m,exports.ModuleCardLight=f,exports.ModuleCustomHtml=g,exports.ModuleHeroSectionLight=y,exports.ModuleImage=C,exports.PageModular=k,exports.VerticalComponents=u,exports.cmsHtmlParser=h; //# sourceMappingURL=page-modular-d7472110.js.map