@claspo/renderer 18.0.5 → 18.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import DefaultState from"./common/DefaultState";import FormGroup from"./form/FormGroup";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import DocumentModelService from"./document-model/DocumentModelService";import ConfigService from"./common/ConfigService";import ClDocumentResizeListener from"./renderer/style/ClDocumentResizeListener";import MobileDeviceOrientationListener from"./renderer/style/MobileDeviceOrientationListener";import DefaultMediaQueryListener from"./renderer/style/DefaultMediaQueryListener";import DocumentService from"./document-model/DocumentService";import CommonStylesService from"./renderer/style/CommonStylesService";import WcFactory from"./wc-renderer/WcFactory";import WcViewRenderer from"./wc-renderer/WcViewRenderer";import ActionFactory from"./action/ActionFactory";import PrizePoolFactory from"./prize-pool/PrizePoolFactory";import httpClient from"@claspo/common/network/HttpClient";import{ActionRegister}from"./action/ActionRegister";import ContextSDK from"./sdk/context/ContextSDK";import{MergeTagsProcessorFactory}from"./sdk/merge-tags/MergeTagsProcessorFactory";import SourceRegistry from"./sdk/source/SourceRegistry";import ContextData from"./sdk/context/ContextData";export default class CompositionRoot{constructor(e,t,o,r,i,n,c,s,m){var a;const l=new DocumentModelService(e),y=!r,f=y?new DefaultMediaQueryListener(l,t):new ClDocumentResizeListener(l,r),u=new DefaultState,p=new ConfigService(t),v=new MobileDeviceOrientationListener(l,p),d=new CommonStylesService;d.setStyles(i);const S=new DefaultEventEmitter,D=new FormGroup(o),g=new SourceRegistry(D,t),w=new ContextData,F=new ContextSDK(g,w,y),C=new(null!==(a=t.actionFactoryClass)&&void 0!==a?a:ActionFactory)(S,D,p,o,u,F,()=>this.services),R=new ActionRegister(S,()=>this.services),M=new PrizePoolFactory(httpClient,p),L=new MergeTagsProcessorFactory(y,F,p),P=new WcFactory({state:u,eventEmitter:S,form:D,documentModel:l,resizeListener:f,config:p,commonStylesService:d,trackingService:o,layoutType:n,actionFactory:C,actionRegister:R,prizePoolFactory:M,context:F,mergeTagsProcessorFactory:L,mobileDeviceOrientationListener:v,componentRegister:s,htmlDocumentObject:m}),h=new WcViewRenderer(l,f,t,P,S),x=new DocumentService(l,h,c);this.services={documentService:x,documentModel:l,state:u,form:D,eventEmitter:S,config:p,resizeListener:f,mobileDeviceOrientationListener:v,componentFactory:P,viewRenderer:h,commonStylesService:d,tracking:o,actionFactory:C,actionRegister:R,prizePoolFactory:M,context:F,mergeTagsProcessorFactory:L}}destroy(){Object.keys(this.services).filter(e=>"viewRenderer"!==e).forEach(e=>this.services[e]&&this.services[e].destroy&&this.services[e].destroy())}}
1
+ import DefaultState from"./common/DefaultState";import FormGroup from"./form/FormGroup";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import DocumentModelService from"./document-model/DocumentModelService";import ConfigService from"./common/ConfigService";import ClDocumentResizeListener from"./renderer/style/ClDocumentResizeListener";import MobileDeviceOrientationListener from"./renderer/style/MobileDeviceOrientationListener";import DefaultMediaQueryListener from"./renderer/style/DefaultMediaQueryListener";import DocumentService from"./document-model/DocumentService";import CommonStylesService from"./renderer/style/CommonStylesService";import WcFactory from"./wc-renderer/WcFactory";import WcViewRenderer from"./wc-renderer/WcViewRenderer";import ActionFactory from"./action/ActionFactory";import PrizePoolFactory from"./prize-pool/PrizePoolFactory";import httpClient from"@claspo/common/network/HttpClient";import{ActionRegister}from"./action/ActionRegister";import ContextSDK from"./sdk/context/ContextSDK";import{MergeTagsProcessorFactory}from"./sdk/merge-tags/MergeTagsProcessorFactory";import SourceRegistry from"./sdk/source/SourceRegistry";import ContextData from"./sdk/context/ContextData";import SubmitStateService from"./submit-state/SubmitStateService";export default class CompositionRoot{constructor(e,t,r,o,i,n,c,m,s){var a;const l=new DocumentModelService(e),u=!o,y=u?new DefaultMediaQueryListener(l,t):new ClDocumentResizeListener(l,o),f=new DefaultState,S=new ConfigService(t),v=new MobileDeviceOrientationListener(l,S),p=new CommonStylesService;p.setStyles(i);const d=new DefaultEventEmitter,D=new FormGroup(r),g=new SubmitStateService(D,d),w=new SourceRegistry(D,t),F=new ContextData,C=new ContextSDK(w,F,u),R=new(null!==(a=t.actionFactoryClass)&&void 0!==a?a:ActionFactory)(d,D,S,r,f,C,()=>this.services),M=new ActionRegister(d,()=>this.services),L=new PrizePoolFactory(httpClient,S),P=new MergeTagsProcessorFactory(u,C,S),b=new WcFactory({state:f,eventEmitter:d,form:D,documentModel:l,resizeListener:y,config:S,commonStylesService:p,trackingService:r,layoutType:n,actionFactory:R,actionRegister:M,prizePoolFactory:L,context:C,mergeTagsProcessorFactory:P,mobileDeviceOrientationListener:v,componentRegister:m,htmlDocumentObject:s}),h=new WcViewRenderer(l,y,t,b,d),x=new DocumentService(l,h,c);this.services={documentService:x,documentModel:l,state:f,form:D,eventEmitter:d,config:S,resizeListener:y,mobileDeviceOrientationListener:v,componentFactory:b,viewRenderer:h,commonStylesService:p,tracking:r,actionFactory:R,actionRegister:M,submitState:g,prizePoolFactory:L,context:C,mergeTagsProcessorFactory:P}}destroy(){Object.keys(this.services).filter(e=>"viewRenderer"!==e).forEach(e=>this.services[e]&&this.services[e].destroy&&this.services[e].destroy())}}
package/ViewRouter.d.ts CHANGED
@@ -9,7 +9,6 @@ export default class ViewRouter extends DefaultEventEmitter {
9
9
  currentViewComponentRef: any;
10
10
  transitions: any;
11
11
  documentContainer: any;
12
- contactDataSubmitted: any;
13
12
  constructor(eventEmitter: any, documentModel: any, viewRenderer: any, optionalDocumentStyles: any, services: any);
14
13
  getCurrentViewIndex(): any;
15
14
  start(viewIndex: any): any;
package/ViewRouter.js CHANGED
@@ -1 +1 @@
1
- import SysActionTypes from"./action/SysActionTypes";import SysEventTypes from"./common/SysEventTypes";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import SysRouterEvent from"./RouterEvent";import systemResultStateNames from"./document-model/systemResultStateNames";import FormGroupEvents from"./form/FormGroupEvents";export default class ViewRouter extends DefaultEventEmitter{constructor(t,e,i,n,s){super(),this.eventEmitter=t,this.documentModel=e,this.viewRenderer=i,this.optionalDocumentStyles=n,this.services=s,this.currentViewIndex=null,this.currentViewComponentRef=null,this.eventEmitter.on(SysEventTypes.TOO_MANY_REQUESTS,()=>{this.viewDestroy(),this.documentContainer.innerText="Too many requests"}),this.transitions=[]}getCurrentViewIndex(){return this.currentViewIndex}start(t){this.documentContainer=window.document.createElement("div"),this.documentContainer.setAttribute("cl-document",""),this.optionalDocumentStyles&&Object.keys(this.optionalDocumentStyles).forEach(t=>{this.documentContainer.style[t]=this.optionalDocumentStyles[t]}),this.navigate(t||0);return this.eventEmitter.on(SysActionTypes.GO_TO_VIEW,(t,e,i)=>{const n="number"==typeof t?t:this.documentModel.getModel().views.findIndex(e=>e.id===t);-1===n?this.eventEmitter.emit("WIDGET_NAVIGATION_STATE_NOT_FOUND",{viewPointer:t}):this.navigate(n,i,n<this.currentViewIndex?this._previousViewDestroyedCb.bind(this):()=>{})}),this.eventEmitter.on(SysActionTypes.GO_TO_PREVIOUS_VIEW,()=>{this.getCurrentViewIndex()<=0||(this.contactDataSubmitted=!1,this.navigate(this.getCurrentViewIndex()-1,{},this._previousViewDestroyedCb.bind(this)))}),this.eventEmitter.on(SysActionTypes.GO_TO_NEXT_VIEW,()=>{this.documentModel.getModel().views[this.getCurrentViewIndex()+1]&&this.navigate(this.getCurrentViewIndex()+1)}),this.eventEmitter.on("CONTACT_DATA_SUBMIT",()=>{this.contactDataSubmitted=!0}),this.services.form.on(FormGroupEvents.valueChanged,()=>{this.contactDataSubmitted&&(this.contactDataSubmitted=!1)}),this.documentContainer}destroy(){this.viewDestroy(),this.documentContainer&&this.documentContainer.remove()}navigate(t,e={},i=()=>{}){let n=this.documentModel.getView(t);const s=this.currentViewIndex;if(this.currentViewIndex===t)return;if(!n)throw this.eventEmitter.emit("WIDGET_NAVIGATION_STATE_NOT_FOUND",{navigateTo:t}),new Error("View was not found by index: "+t);setTimeout(()=>{const t=systemResultStateNames.includes(n.label),e=this.contactDataSubmitted,i=this.services.form.getControlsAsArray().length>0;t&&i&&!e&&(this.eventEmitter.emit("WIDGET_NAVIGATION_STATE_NOT_FOUND",{toSystemStateWithoutSubmitFromIndex:s,ctx:this.services.context.getKVMap()}),this.services.actionFactory.get({type:SysActionTypes.REQUEST}).execute(void 0,void 0,!0,{skipValidation:!0}))},300);const o=this.viewRenderer.render(n,t);this.viewDestroy(),i(),this.documentContainer.appendChild(o),this.currentViewComponentRef=o,this.currentViewIndex=t,this.transitions.push({prevViewIndex:s,currentViewIndex:t,currentViewComponentRef:o,contactDataSubmitted:this.contactDataSubmitted,routeState:e}),this.eventEmitter.emit(SysRouterEvent.NAVIGATION_END,t)}viewDestroy(){this.currentViewComponentRef&&this.viewRenderer.destroy(this.currentViewComponentRef)}getDocumentContainer(){return this.documentContainer}getLastTransition(){return this.transitions[this.transitions.length-1]}_previousViewDestroyedCb(){this.services.form.getControlsAsArray().forEach(t=>{t.viewIdx===this.currentViewIndex&&this.services.form.removeControl(t.name)}),this.services.state.setState({conditionalRedirectViewId:null})}}
1
+ import SysActionTypes from"./action/SysActionTypes";import SysEventTypes from"./common/SysEventTypes";import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import SysRouterEvent from"./RouterEvent";import systemResultStateNames from"./document-model/systemResultStateNames";export default class ViewRouter extends DefaultEventEmitter{constructor(t,e,i,n,s){super(),this.eventEmitter=t,this.documentModel=e,this.viewRenderer=i,this.optionalDocumentStyles=n,this.services=s,this.currentViewIndex=null,this.currentViewComponentRef=null,this.eventEmitter.on(SysEventTypes.TOO_MANY_REQUESTS,()=>{this.viewDestroy(),this.documentContainer.innerText="Too many requests"}),this.transitions=[]}getCurrentViewIndex(){return this.currentViewIndex}start(t){this.documentContainer=window.document.createElement("div"),this.documentContainer.setAttribute("cl-document",""),this.optionalDocumentStyles&&Object.keys(this.optionalDocumentStyles).forEach(t=>{this.documentContainer.style[t]=this.optionalDocumentStyles[t]}),this.navigate(t||0);return this.eventEmitter.on(SysActionTypes.GO_TO_VIEW,(t,e,i)=>{const n="number"==typeof t?t:this.documentModel.getModel().views.findIndex(e=>e.id===t);-1===n?this.eventEmitter.emit("WIDGET_NAVIGATION_STATE_NOT_FOUND",{viewPointer:t}):this.navigate(n,i,n<this.currentViewIndex?this._previousViewDestroyedCb.bind(this):()=>{})}),this.eventEmitter.on(SysActionTypes.GO_TO_PREVIOUS_VIEW,()=>{this.getCurrentViewIndex()<=0||this.navigate(this.getCurrentViewIndex()-1,{},this._previousViewDestroyedCb.bind(this))}),this.eventEmitter.on(SysActionTypes.GO_TO_NEXT_VIEW,()=>{this.documentModel.getModel().views[this.getCurrentViewIndex()+1]&&this.navigate(this.getCurrentViewIndex()+1)}),this.documentContainer}destroy(){this.viewDestroy(),this.documentContainer&&this.documentContainer.remove()}navigate(t,e={},i=()=>{}){var n;let s=this.documentModel.getView(t);const r=this.currentViewIndex;if(this.currentViewIndex===t)return;if(!s)throw this.eventEmitter.emit("WIDGET_NAVIGATION_STATE_NOT_FOUND",{navigateTo:t}),new Error("View was not found by index: "+t);setTimeout(()=>{var t;const e=systemResultStateNames.includes(s.label),i=null===(t=this.services.submitState)||void 0===t?void 0:t.hasSubmitAttemptSinceLastChange(),n=this.services.form.getControlsAsArray().length>0;e&&n&&!i&&(this.eventEmitter.emit("WIDGET_NAVIGATION_STATE_NOT_FOUND",{toSystemStateWithoutSubmitFromIndex:r,ctx:this.services.context.getKVMap()}),this.services.actionFactory.get({type:SysActionTypes.REQUEST}).execute(void 0,void 0,!0,{skipValidation:!0}))},300);const o=this.viewRenderer.render(s,t);this.viewDestroy(),i(),this.documentContainer.appendChild(o),this.currentViewComponentRef=o,this.currentViewIndex=t,this.transitions.push({prevViewIndex:r,currentViewIndex:t,currentViewComponentRef:o,contactDataSubmitted:null===(n=this.services.submitState)||void 0===n?void 0:n.hasSubmitAttemptSinceLastChange(),routeState:e}),this.eventEmitter.emit(SysRouterEvent.NAVIGATION_END,t)}viewDestroy(){this.currentViewComponentRef&&this.viewRenderer.destroy(this.currentViewComponentRef)}getDocumentContainer(){return this.documentContainer}getLastTransition(){return this.transitions[this.transitions.length-1]}_previousViewDestroyedCb(){this.services.form.getControlsAsArray().forEach(t=>{t.viewIdx===this.currentViewIndex&&this.services.form.removeControl(t.name)}),this.services.state.setState({conditionalRedirectViewId:null})}}
@@ -1 +1 @@
1
- import SysActionTypes from"../SysActionTypes";import SysEventTypes from"../../common/SysEventTypes";import{HttpStatus}from"@claspo/common/network/HttpStatus";import ActionCategory from"./ActionCategory";import systemResultStateNames from"../../document-model/systemResultStateNames";import DocumentUtils from"@claspo/common/document/DocumentUtils";import getComponentCountOnView from"../../sdk/getComponentCountOnView";import UTMParamsExtractor from"../UTMParamsExtractor";import isDictionary from"@claspo/common/object/isDictionary";function componentModelHasSubmitAction(t){var e,s;try{return!!(null===(s=null===(e=t.props)||void 0===e?void 0:e.handlers)||void 0===s?void 0:s.find(t=>{var e;return null===(e=null==t?void 0:t.actions)||void 0===e?void 0:e.find(t=>[SysActionTypes.REQUEST,SysActionTypes.SUBSCRIBE_CONTACT].includes(t.type))}))}catch(t){return!1}}function viewHasControls(t){if(!t)return!1;let e=0;return DocumentUtils.iterateDepthFirst(t,t=>{(["INPUT","MULTIPLE_INPUT","PRIZE_BASED_GAMING"].includes(t.type)||componentModelHasSubmitAction(t))&&e++}),e>0}function isSystemView(t){return t&&systemResultStateNames.includes(t.label)}export const RequestStatus={SUCCESS:"SUCCESS",ALREADY_SUBSCRIBED:"ALREADY_SUBSCRIBED",ERROR:"ERROR",TOO_MANY_REQUESTS:"TOO_MANY_REQUESTS"};export default class BaseRequestAction{constructor(t,e,s,i,n,o,r,a,c){this.skipHttpRequest=!0,this.id=s.id,this.params=s.params,this.form=e,this.eventEmitter=t,this.httpClient=i,this.configService=n,this.formEventsListener=null,this.tracking=o,this.stateService=r,this.context=a,this.getServices=c,this.category=ActionCategory.SUBMIT}getTrackingMessageBeforeSentData(){return""}getTrackingMessageByStatus(t){return""}execute(t,e,s,i){if(this.formEventsListener&&this.formEventsListener.off(),!this.form.submitQueuedAfterPending||!0===t){if(!this.form.preventSubmit)return new Promise(n=>{if(!this.form.isPending()){this.form.submitQueuedAfterPending=!1;const o=!0===t?e:n;return this.submit(o,s,i)}this.form.submitQueuedAfterPending=!0,setTimeout(()=>this.execute(!0,n,s,i),500)});this.form.submitQueuedAfterPending=!1}}submit(t,e,s){const i=this.getServices().viewRouter.getCurrentViewIndex(),n=this.getServices().documentModel.getViews().slice(i+1).filter(t=>!systemResultStateNames.includes(t.label)).length>0,o=Object.assign(Object.assign({},this.params),s);if(this.form.markAsTouched(),this.stateService.getState().emitActionOnSubmit&&this.eventEmitter.emit(this.stateService.getState().emitActionOnSubmit.eventName),this.stateService.getState().interceptSubmitActions&&!e)return;if(!this.form.isValid()&&!o.skipValidation)return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),void t(!1);const r=this.stateService,a=r.getState().conditionalRedirectViewId,c=o.conditionalRedirectViewId||a;a&&(o.conditionalRedirectViewId=a,r.setState({conditionalRedirectViewId:null}));let u=this.getServices().documentModel.getViews()[i+1];const m=this.getServices().documentModel.getViews()[i];if(c&&getComponentCountOnView(m,"SysNetPromoterScoreComponent")+getComponentCountOnView(m,"SysFeedbackComponent")===1&&(u=this.getServices().documentModel.getViews().find(t=>t.id===o.conditionalRedirectViewId),viewHasControls(u)||isSystemView(u)))return this.goToView(u.path[0],o),void t(!0);const S=this.form.getControlsMap(),d=this.context.getKVMap();if(n&&(viewHasControls(u)||!Object.keys(S).length&&!Object.keys(d).length))return this.goToView(i+1,o),void t(!0);if(!Object.keys(S).length&&!Object.keys(d).length)return void t(!0);const l=UTMParamsExtractor.extractUtmParams(this.context),g=this.constructRequestPayload({contextValue:d,formValue:S,utmParams:l});this.eventEmitter.emit("CONTACT_DATA_SUBMIT",g);this.getTrackingMessageBeforeSentData()&&this.tracking.send("FormFinish_[Name]"),this.configService.getConfig("isBot")?t():this.sendRequest(g).then(t=>t.json().then(e=>t.status===HttpStatus.TOO_MANY_REQUESTS?{state:RequestStatus.TOO_MANY_REQUESTS}:{contactId:e.contactId,state:e&&e.next&&e.next.type}),()=>({state:RequestStatus.ERROR})).then(e=>{const s=this.getTrackingMessageByStatus(e.state);switch(e.state){case RequestStatus.SUCCESS:s&&this.tracking.send(s),this.goToView(n&&u?u.path[0]:this.getServices().documentModel.getViews().findIndex(t=>"DOCUMENT_VIEW_TYPE_SUCCESS"===t.label||"DOCUMENT_VIEW_TYPE_SUCCESSFUL_REQUEST"===t.label||"REQUEST_FORM_VIEW_TYPE_SUCCESS"===t.label));break;case RequestStatus.ALREADY_SUBSCRIBED:s&&this.tracking.send(s),this.goToView(c&&u?u.path[0]:this.getServices().documentModel.getViews().findIndex(t=>"DOCUMENT_VIEW_TYPE_SUBSCRIBED"===t.label));break;case RequestStatus.ERROR:s&&this.tracking.send(s),this.goToView(c&&u?u.path[0]:this.getServices().documentModel.getViews().findIndex(t=>"DOCUMENT_VIEW_TYPE_ERROR"===t.label));break;case RequestStatus.TOO_MANY_REQUESTS:s&&this.tracking.send(s),this.goToView(c&&u?u.path[0]:this.getServices().documentModel.getViews().findIndex(t=>"DOCUMENT_VIEW_TYPE_ERROR"===t.label)),this.eventEmitter.emit(SysEventTypes.TOO_MANY_REQUESTS)}e.contactId&&"0"!==e.contactId&&this.eventEmitter.emit("CONTACT_ID_WAS_RECEIVED",e.contactId),t(e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED)}).catch(()=>{this.goToView(this.getServices().documentModel.getViews().findIndex(t=>"DOCUMENT_VIEW_TYPE_ERROR"===t.label)),t(!1)})}constructDataToSent({contextValue:t,formValue:e,utmParams:s}){const i=Object.assign({},t);return i.tracking=s,Object.keys(e).forEach(t=>{if(t.startsWith("clConsentId")){if(t.endsWith("_label"))return;const s={value:e[t]};e[`${t}_label`]&&(s.text=e[`${t}_label`]),i.consents?i.consents[t]=s:i.consents={[t]:s}}else{const s=e[t];i[t]=isDictionary(s)||Array.isArray(s)?JSON.stringify(s):s}}),i}constructRequestPayload({contextValue:t,formValue:e,utmParams:s}){let i={data:this.constructDataToSent({contextValue:t,formValue:e,utmParams:s}),referrer:window.location.href,triggeredBy:this.configService.getConfig("triggeredBy")};return this.configService.getConfig("widgetDebugMode")&&(i.ignoreTracking=!0),i}constructRequestHeaders(){const t={},e=this.configService.getConfig("clCustomerId");return e&&Object.assign(t,{"cl-customer-id":e}),t}goToView(t,e){this.eventEmitter.emit(SysActionTypes.GO_TO_VIEW,t,e)}sendRequest(t){return this.skipHttpRequest?Promise.resolve({status:200,json:()=>Promise.resolve({next:{type:RequestStatus.SUCCESS}})}):this.httpClient.execute(this.configService.getConfig("subscribeContactUrl"),"POST",t,this.constructRequestHeaders())}}
1
+ import SysActionTypes from"../SysActionTypes";import SysEventTypes from"../../common/SysEventTypes";import{HttpStatus}from"@claspo/common/network/HttpStatus";import ActionCategory from"./ActionCategory";import systemResultStateNames from"../../document-model/systemResultStateNames";import DocumentUtils from"@claspo/common/document/DocumentUtils";import getComponentCountOnView from"../../sdk/getComponentCountOnView";import UTMParamsExtractor from"../UTMParamsExtractor";import isDictionary from"@claspo/common/object/isDictionary";function componentModelHasSubmitAction(t){var e,s;try{return!!(null===(s=null===(e=t.props)||void 0===e?void 0:e.handlers)||void 0===s?void 0:s.find(t=>{var e;return null===(e=null==t?void 0:t.actions)||void 0===e?void 0:e.find(t=>[SysActionTypes.REQUEST,SysActionTypes.SUBSCRIBE_CONTACT].includes(t.type))}))}catch(t){return!1}}function viewHasControls(t){if(!t)return!1;let e=0;return DocumentUtils.iterateDepthFirst(t,t=>{(["INPUT","MULTIPLE_INPUT","PRIZE_BASED_GAMING"].includes(t.type)||componentModelHasSubmitAction(t))&&e++}),e>0}function isSystemView(t){return t&&systemResultStateNames.includes(t.label)}export const RequestStatus={SUCCESS:"SUCCESS",ALREADY_SUBSCRIBED:"ALREADY_SUBSCRIBED",ERROR:"ERROR",TOO_MANY_REQUESTS:"TOO_MANY_REQUESTS"};export default class BaseRequestAction{constructor(t,e,s,i,n,o,r,a,c){this.skipHttpRequest=!0,this.id=s.id,this.params=s.params,this.form=e,this.eventEmitter=t,this.httpClient=i,this.configService=n,this.formEventsListener=null,this.tracking=o,this.stateService=r,this.context=a,this.getServices=c,this.category=ActionCategory.SUBMIT}getTrackingMessageBeforeSentData(){return""}getTrackingMessageByStatus(t){return""}execute(t,e,s,i){var n;if(this.formEventsListener&&this.formEventsListener.off(),this.form.submitQueuedAfterPending&&!0!==t)return;if(this.form.preventSubmit)return void(this.form.submitQueuedAfterPending=!1);const o=new Promise(n=>{if(!this.form.isPending()){this.form.submitQueuedAfterPending=!1;const o=!0===t?e:n;return this.submit(o,s,i)}this.form.submitQueuedAfterPending=!0,setTimeout(()=>this.execute(!0,n,s,i),500)});return null===(n=this.getServices().submitState)||void 0===n||n.trackSubmission(o),o}submit(t,e,s){const i=this.getServices().viewRouter.getCurrentViewIndex(),n=this.getServices().documentModel.getViews().slice(i+1).filter(t=>!systemResultStateNames.includes(t.label)).length>0,o=Object.assign(Object.assign({},this.params),s);if(this.form.markAsTouched(),this.stateService.getState().emitActionOnSubmit&&this.eventEmitter.emit(this.stateService.getState().emitActionOnSubmit.eventName),this.stateService.getState().interceptSubmitActions&&!e)return;if(!this.form.isValid()&&!o.skipValidation)return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),void t(!1);const r=this.stateService,a=r.getState().conditionalRedirectViewId,c=o.conditionalRedirectViewId||a;a&&(o.conditionalRedirectViewId=a,r.setState({conditionalRedirectViewId:null}));let S=this.getServices().documentModel.getViews()[i+1];const u=this.getServices().documentModel.getViews()[i];if(!o.skipNavigation&&c&&getComponentCountOnView(u,"SysNetPromoterScoreComponent")+getComponentCountOnView(u,"SysFeedbackComponent")===1&&(S=this.getServices().documentModel.getViews().find(t=>t.id===o.conditionalRedirectViewId),viewHasControls(S)||isSystemView(S)))return this.goToView(S.path[0],o),void t(!0);const m=this.form.getControlsMap(),E=this.context.getKVMap();if(!o.skipNavigation&&n&&(viewHasControls(S)||!Object.keys(m).length&&!Object.keys(E).length))return this.goToView(i+1,o),void t(!0);if(!Object.keys(m).length&&!Object.keys(E).length)return void t(!0);const d=UTMParamsExtractor.extractUtmParams(this.context),l=this.constructRequestPayload({contextValue:E,formValue:m,utmParams:d});this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_STARTED,l),this.eventEmitter.emit("CONTACT_DATA_SUBMIT",l);if(this.getTrackingMessageBeforeSentData()&&this.tracking.send("FormFinish_[Name]"),this.configService.getConfig("isBot"))return this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_FINISHED,{state:RequestStatus.SUCCESS,success:!0,skipped:!0}),void t();this.sendRequest(l).then(t=>t.json().then(e=>t.status===HttpStatus.TOO_MANY_REQUESTS?{state:RequestStatus.TOO_MANY_REQUESTS}:{contactId:e.contactId,state:e&&e.next&&e.next.type}),()=>({state:RequestStatus.ERROR})).then(e=>{const s=this.getTrackingMessageByStatus(e.state);if(s&&this.tracking.send(s),o.skipNavigation)return e.state===RequestStatus.TOO_MANY_REQUESTS&&this.eventEmitter.emit(SysEventTypes.TOO_MANY_REQUESTS),e.contactId&&"0"!==e.contactId&&this.eventEmitter.emit("CONTACT_ID_WAS_RECEIVED",e.contactId),this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_FINISHED,Object.assign(Object.assign({},e),{success:e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED})),void t(e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED);switch(e.state){case RequestStatus.SUCCESS:this.goToView(n&&S?S.path[0]:this.getServices().documentModel.getViews().findIndex(t=>"DOCUMENT_VIEW_TYPE_SUCCESS"===t.label||"DOCUMENT_VIEW_TYPE_SUCCESSFUL_REQUEST"===t.label||"REQUEST_FORM_VIEW_TYPE_SUCCESS"===t.label));break;case RequestStatus.ALREADY_SUBSCRIBED:this.goToView(c&&S?S.path[0]:this.getServices().documentModel.getViews().findIndex(t=>"DOCUMENT_VIEW_TYPE_SUBSCRIBED"===t.label));break;case RequestStatus.ERROR:this.goToView(c&&S?S.path[0]:this.getServices().documentModel.getViews().findIndex(t=>"DOCUMENT_VIEW_TYPE_ERROR"===t.label));break;case RequestStatus.TOO_MANY_REQUESTS:this.goToView(c&&S?S.path[0]:this.getServices().documentModel.getViews().findIndex(t=>"DOCUMENT_VIEW_TYPE_ERROR"===t.label)),this.eventEmitter.emit(SysEventTypes.TOO_MANY_REQUESTS)}e.contactId&&"0"!==e.contactId&&this.eventEmitter.emit("CONTACT_ID_WAS_RECEIVED",e.contactId),this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_FINISHED,Object.assign(Object.assign({},e),{success:e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED})),t(e.state===RequestStatus.SUCCESS||e.state===RequestStatus.ALREADY_SUBSCRIBED)}).catch(()=>{this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_FINISHED,{state:RequestStatus.ERROR,success:!1}),o.skipNavigation||this.goToView(this.getServices().documentModel.getViews().findIndex(t=>"DOCUMENT_VIEW_TYPE_ERROR"===t.label)),t(!1)})}constructDataToSent({contextValue:t,formValue:e,utmParams:s}){const i=Object.assign({},t);return i.tracking=s,Object.keys(e).forEach(t=>{if(t.startsWith("clConsentId")){if(t.endsWith("_label"))return;const s={value:e[t]};e[`${t}_label`]&&(s.text=e[`${t}_label`]),i.consents?i.consents[t]=s:i.consents={[t]:s}}else{const s=e[t];i[t]=isDictionary(s)||Array.isArray(s)?JSON.stringify(s):s}}),i}constructRequestPayload({contextValue:t,formValue:e,utmParams:s}){let i={data:this.constructDataToSent({contextValue:t,formValue:e,utmParams:s}),referrer:window.location.href,triggeredBy:this.configService.getConfig("triggeredBy")};return this.configService.getConfig("widgetDebugMode")&&(i.ignoreTracking=!0),i}constructRequestHeaders(){const t={},e=this.configService.getConfig("clCustomerId");return e&&Object.assign(t,{"cl-customer-id":e}),t}goToView(t,e){this.eventEmitter.emit(SysActionTypes.GO_TO_VIEW,t,e)}sendRequest(t){return this.skipHttpRequest?Promise.resolve({status:200,json:()=>Promise.resolve({next:{type:RequestStatus.SUCCESS}})}):this.httpClient.execute(this.configService.getConfig("subscribeContactUrl"),"POST",t,this.constructRequestHeaders())}}
@@ -1 +1 @@
1
- export default class ConfigService{constructor(e){this.config=Object.assign(Object.assign({},{subscribeContactUrl:""}),e)}getConfig(e){return e?"entryModuleType"===e?this.config.renderMode:this.config[e]:this.config}}
1
+ export default class ConfigService{constructor(e){this.config=Object.assign(Object.assign({},{subscribeContactUrl:"",submitOnClose:{enabled:!1,skipValidation:!0}}),e)}getConfig(e){return e?"entryModuleType"===e?this.config.renderMode:this.config[e]:this.config}}
@@ -2,6 +2,8 @@ declare enum SysEventTypes {
2
2
  TOO_MANY_REQUESTS = "TOO_MANY_REQUESTS",
3
3
  COMPONENT_RESOURCES_LOADED = "COMPONENT_RESOURCES_LOADED",
4
4
  FAILED_TO_LOAD_COMPONENT_RESOURCE = "FAILED_TO_LOAD_COMPONENT_RESOURCE",
5
- EXECUTE_ACTION_BY_PREDICATE = "EXECUTE_ACTION_BY_PREDICATE"
5
+ EXECUTE_ACTION_BY_PREDICATE = "EXECUTE_ACTION_BY_PREDICATE",
6
+ SUBMIT_REQUEST_STARTED = "SUBMIT_REQUEST_STARTED",
7
+ SUBMIT_REQUEST_FINISHED = "SUBMIT_REQUEST_FINISHED"
6
8
  }
7
9
  export default SysEventTypes;
@@ -1 +1 @@
1
- var SysEventTypes;!function(E){E.TOO_MANY_REQUESTS="TOO_MANY_REQUESTS",E.COMPONENT_RESOURCES_LOADED="COMPONENT_RESOURCES_LOADED",E.FAILED_TO_LOAD_COMPONENT_RESOURCE="FAILED_TO_LOAD_COMPONENT_RESOURCE",E.EXECUTE_ACTION_BY_PREDICATE="EXECUTE_ACTION_BY_PREDICATE"}(SysEventTypes||(SysEventTypes={}));export default SysEventTypes;
1
+ var SysEventTypes;!function(E){E.TOO_MANY_REQUESTS="TOO_MANY_REQUESTS",E.COMPONENT_RESOURCES_LOADED="COMPONENT_RESOURCES_LOADED",E.FAILED_TO_LOAD_COMPONENT_RESOURCE="FAILED_TO_LOAD_COMPONENT_RESOURCE",E.EXECUTE_ACTION_BY_PREDICATE="EXECUTE_ACTION_BY_PREDICATE",E.SUBMIT_REQUEST_STARTED="SUBMIT_REQUEST_STARTED",E.SUBMIT_REQUEST_FINISHED="SUBMIT_REQUEST_FINISHED"}(SysEventTypes||(SysEventTypes={}));export default SysEventTypes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claspo/renderer",
3
- "version": "18.0.5",
3
+ "version": "18.0.6",
4
4
  "scripts": {
5
5
  "dev": " tsc --project tsconfig.json --watch",
6
6
  "build": "rm -rf out && tsc --project tsconfig.json && npm run minify",
@@ -0,0 +1,26 @@
1
+ import DefaultEventEmitter from '@claspo/common/DefaultEventEmitter';
2
+ import FormGroup from '../form/FormGroup';
3
+ export declare const SubmitState: {
4
+ readonly IDLE: "idle";
5
+ readonly DIRTY: "dirty";
6
+ readonly SUBMITTING: "submitting";
7
+ readonly SUBMITTED: "submitted";
8
+ readonly FAILED: "failed";
9
+ };
10
+ export type SubmitStateValue = typeof SubmitState[keyof typeof SubmitState];
11
+ export default class SubmitStateService {
12
+ form: FormGroup;
13
+ eventEmitter: DefaultEventEmitter;
14
+ state: SubmitStateValue;
15
+ currentSubmission: Promise<boolean> | null;
16
+ subscriptions: Array<{
17
+ off: () => void;
18
+ }>;
19
+ constructor(form: FormGroup, eventEmitter: DefaultEventEmitter);
20
+ getState(): SubmitStateValue;
21
+ hasDirtyFormData(): boolean;
22
+ hasSubmitAttemptSinceLastChange(): boolean;
23
+ trackSubmission(promise: Promise<boolean>): void;
24
+ waitForCurrentSubmission(): Promise<boolean>;
25
+ destroy(): void;
26
+ }
@@ -0,0 +1 @@
1
+ import FormGroupEvents from"../form/FormGroupEvents";import SysEventTypes from"../common/SysEventTypes";export const SubmitState={IDLE:"idle",DIRTY:"dirty",SUBMITTING:"submitting",SUBMITTED:"submitted",FAILED:"failed"};export default class SubmitStateService{constructor(t,s){this.form=t,this.eventEmitter=s,this.state=SubmitState.IDLE,this.currentSubmission=null,this.subscriptions=[this.form.on(FormGroupEvents.valueChanged,()=>{this.state=SubmitState.DIRTY}),this.eventEmitter.on(SysEventTypes.SUBMIT_REQUEST_STARTED,()=>{this.state=SubmitState.SUBMITTING}),this.eventEmitter.on(SysEventTypes.SUBMIT_REQUEST_FINISHED,t=>{this.currentSubmission=null,this.state=(null==t?void 0:t.success)?SubmitState.SUBMITTED:SubmitState.FAILED})]}getState(){return this.state}hasDirtyFormData(){return this.form.getControlsAsArray().some(t=>t.isTouched())}hasSubmitAttemptSinceLastChange(){return[SubmitState.SUBMITTING,SubmitState.SUBMITTED,SubmitState.FAILED].includes(this.state)}trackSubmission(t){this.currentSubmission=t}waitForCurrentSubmission(){return this.currentSubmission||Promise.resolve(!1)}destroy(){this.subscriptions.forEach(t=>t.off()),this.subscriptions=[],this.currentSubmission=null}}