@claspo/renderer 18.7.4-ctx.9 → 18.7.5-ctx.10

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 UrlQueryParamsSource from"../sdk/source/sources/UrlQueryParamsSource";function getLastMarTechValue(t,e){for(let r=t.length-1;r>=0;r--){const a=new URLSearchParams(t[r]),c=[];for(const[t,r]of a.entries())e.includes(t)&&r&&c.push(r);if(c.length)return c[c.length-1]}return""}export default class UTMParamsExtractor{static extractTrackingParams(t){return Object.assign(Object.assign({},UTMParamsExtractor.extractUtmParams(t)),UTMParamsExtractor.extractMarTechParams(t))}static extractUtmParams(t){const e={id:"id",fallbackValue:"",exampleValue:"exampleValue",sourceId:UrlQueryParamsSource.sourceId,arguments:[{type:"string",name:"urlQueryParamName",value:""}]},r={},a=t.getRegistry().getSource(e.sourceId),c=a.getValue("utm");return["utm_source","utm_medium","utm_campaign","utm_term","utm_content","utm_id"].forEach(t=>{const s=c.processor(a,Object.assign(Object.assign({},e),{arguments:[Object.assign(Object.assign({},e.arguments[0]),{value:t})]}));s&&(r[t]=s)}),r}static extractMarTechParams(t){const e=t.getRegistry().getSource(UrlQueryParamsSource.sourceId),r=(null==e?void 0:e.subscriptionEntry).getSessionHistory(),a={};return Object.entries({rdt_cid:["rdt_cid"],sccid:["sccid","ScCid"],gclid:["gclid"],fbclid:["fbclid"],ttclid:["ttclid"],li_fat_id:["li_fat_id"],ascsubtag:["ascsubtag"],msclkid:["msclkid"],twclid:["twclid"],epik:["epik"]}).forEach(([t,e])=>{const c=getLastMarTechValue(r,e);c&&(a[t]=c)}),a}}
1
+ import UrlQueryParamsSource from"../sdk/source/sources/UrlQueryParamsSource";function getLastMarTechValue(t,e){for(let r=t.length-1;r>=0;r--){const a=new URLSearchParams(t[r]),c=[];for(const[t,r]of a.entries())e.includes(t)&&r&&c.push(r);if(c.length)return c[c.length-1]}return""}export default class UTMParamsExtractor{static extractTrackingParams(t){return Object.assign(Object.assign({},UTMParamsExtractor.extractUtmParams(t)),UTMParamsExtractor.extractMarTechParams(t))}static extractUtmParams(t){const e={id:"id",fallbackValue:"",exampleValue:"exampleValue",sourceId:UrlQueryParamsSource.sourceId,arguments:[{type:"string",name:"urlQueryParamName",value:""}]},r={},a=t.getRegistry().getSource(e.sourceId),c=null==a?void 0:a.getValue("utm");return a&&c?(["utm_source","utm_medium","utm_campaign","utm_term","utm_content","utm_id"].forEach(t=>{const s=c.processor(a,Object.assign(Object.assign({},e),{arguments:[Object.assign(Object.assign({},e.arguments[0]),{value:t})]}));s&&(r[t]=s)}),r):r}static extractMarTechParams(t){var e,r;const a=t.getRegistry().getSource(UrlQueryParamsSource.sourceId),c=null==a?void 0:a.subscriptionEntry,s=null!==(r=null===(e=null==c?void 0:c.getSessionHistory)||void 0===e?void 0:e.call(c))&&void 0!==r?r:[new URL(window.location.href).search],i={};return Object.entries({rdt_cid:["rdt_cid"],sccid:["sccid","ScCid"],gclid:["gclid"],fbclid:["fbclid"],ttclid:["ttclid"],li_fat_id:["li_fat_id"],ascsubtag:["ascsubtag"],msclkid:["msclkid"],twclid:["twclid"],epik:["epik"]}).forEach(([t,e])=>{const r=getLastMarTechValue(s,e);r&&(i[t]=r)}),i}}
@@ -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 getConfiguredResultViewIds from"../../document-model/getConfiguredResultViewIds";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 isResultView(t,e){return!!t&&(systemResultStateNames.includes(t.label)||e.includes(t.id))}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""}async execute(t,e,s,i){var n;if(this.formEventsListener&&this.formEventsListener.off(),this.form.submitQueuedAfterPending)return;if(this.form.preventSubmit)return void(this.form.submitQueuedAfterPending=!1);if(this.form.isPending()&&(this.form.submitQueuedAfterPending=!0,await this.form.waitForPendingValidationAndCheckIfValid()),this.form.submitQueuedAfterPending=!1,this.form.preventSubmit)return;const o=new Promise(t=>{this.submit(t,s,i)});return null===(n=this.getServices().submitState)||void 0===n||n.trackSubmission(o),o}submit(t,e,s){var i;const n=this.getServices().viewRouter.getCurrentViewIndex(),o=getConfiguredResultViewIds(this.getServices().documentModel.getShared(),this.hasFormControls()),r=this.getServices().documentModel.getViews()[n+1],a=r&&!isResultView(r,o),c=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()&&!c.skipValidation)return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),void t(!1);const u=this.stateService,S=u.getState().conditionalRedirectViewId,d=c.conditionalRedirectViewId||S;S&&(c.conditionalRedirectViewId=S,u.setState({conditionalRedirectViewId:null}));let m=this.getServices().documentModel.getViews()[n+1];const l=this.getServices().documentModel.getViews()[n];if(!c.skipNavigation&&d&&getComponentCountOnView(l,"SysNetPromoterScoreComponent")+getComponentCountOnView(l,"SysFeedbackComponent")===1&&(m=this.getServices().documentModel.getViews().find(t=>t.id===c.conditionalRedirectViewId),viewHasControls(m)||isResultView(m,o)))return this.goToView(m.path[0],c),void t(!0);const E=null!==(i=c.formValue)&&void 0!==i?i:this.form.getControlsMap(),h=this.getContextValue(c);if(!c.skipNavigation&&a&&(viewHasControls(m)||!Object.keys(E).length&&!Object.keys(h).length))return this.goToView(n+1,c),void t(!0);if(!Object.keys(E).length&&!Object.keys(h).length)return void t(!0);const g=UTMParamsExtractor.extractTrackingParams(this.context),R=this.constructRequestPayload({contextValue:h,formValue:E,utmParams:g});this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_STARTED,R),this.eventEmitter.emit("CONTACT_DATA_SUBMIT",R);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(R).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),c.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:a&&m?this.goToView(m.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getSuccessViewIndex());break;case RequestStatus.ALREADY_SUBSCRIBED:d&&m?this.goToView(m.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getAlreadySubscribedViewIndex());break;case RequestStatus.ERROR:d&&m?this.goToView(m.path[0]):this.handleErrorResponse();break;case RequestStatus.TOO_MANY_REQUESTS:this.goToView(d&&m?m.path[0]:this.getErrorViewIndex()),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}),c.skipNavigation||this.handleErrorResponse(),t(!1)})}getContextValue(t){var e,s;if(!t.excludeFormContext)return this.context.getKVMap();const i=(null===(s=(e=this.context).getRecordsMap)||void 0===s?void 0:s.call(e))||{};return Object.values(i).reduce((t,e)=>{var s;const i=null===(s=null==e?void 0:e.getValue)||void 0===s?void 0:s.call(e);return i&&"FORM"!==i.sourceId?(t[i.id]=i.value,t):t},{})}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())}getSuccessViewIndex(){return this.resolveResultViewIndex("successViewId",["DOCUMENT_VIEW_TYPE_SUCCESS","DOCUMENT_VIEW_TYPE_SUCCESSFUL_REQUEST","REQUEST_FORM_VIEW_TYPE_SUCCESS"])}getErrorViewIndex(){return this.resolveResultViewIndex("errorViewId",["DOCUMENT_VIEW_TYPE_ERROR"])}getAlreadySubscribedViewIndex(){const t=this.getActiveSubmitActionParams();return t&&!t.alreadySubscribedViewId?this.getSuccessViewIndex():this.resolveResultViewIndex("alreadySubscribedViewId",["DOCUMENT_VIEW_TYPE_SUBSCRIBED"])}resolveResultViewIndex(t,e){var s;const i=this.getServices().documentModel.getViews(),n=null===(s=this.getActiveSubmitActionParams())||void 0===s?void 0:s[t];if(n){const t=i.findIndex(t=>t.id===n);if(-1!==t)return t}return i.findIndex(t=>e.includes(t.label))}hasFormControls(){return this.form.getControlsAsArray().length>0}getActiveSubmitActionParams(){if(this.hasFormControls())return this.getServices().documentModel.getShared().submitActionParams}runPostSubmitActionOrGoToView(t){var e;const s=null===(e=this.getActiveSubmitActionParams())||void 0===e?void 0:e.runAction;s?this.getServices().actionFactory.get(s).execute(this.stateService.getState()):this.goToView(t())}handleErrorResponse(){const t=this.getErrorViewIndex();-1!==t?this.goToView(t):this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_ERROR_WITHOUT_VIEW)}}
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 getConfiguredResultViewIds from"../../document-model/getConfiguredResultViewIds";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 isResultView(t,e){return!!t&&(systemResultStateNames.includes(t.label)||e.includes(t.id))}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""}async execute(t,e,s,i){var n;if(this.formEventsListener&&this.formEventsListener.off(),this.form.submitQueuedAfterPending)return;if(this.form.preventSubmit)return void(this.form.submitQueuedAfterPending=!1);if(this.form.isPending()&&(this.form.submitQueuedAfterPending=!0,await this.form.waitForPendingValidationAndCheckIfValid()),this.form.submitQueuedAfterPending=!1,this.form.preventSubmit)return;const o=new Promise(t=>{this.submit(t,s,i)});return null===(n=this.getServices().submitState)||void 0===n||n.trackSubmission(o),o}submit(t,e,s){var i;const n=this.getServices().viewRouter.getCurrentViewIndex(),o=getConfiguredResultViewIds(this.getServices().documentModel.getShared(),this.hasFormControls()),r=this.getServices().documentModel.getViews()[n+1],a=r&&!isResultView(r,o),c=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()&&!c.skipValidation)return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),void t(!1);const u=this.stateService,S=u.getState().conditionalRedirectViewId,m=c.conditionalRedirectViewId||S;S&&(c.conditionalRedirectViewId=S,u.setState({conditionalRedirectViewId:null}));let d=this.getServices().documentModel.getViews()[n+1];const l=this.getServices().documentModel.getViews()[n];if(!c.skipNavigation&&m&&getComponentCountOnView(l,"SysNetPromoterScoreComponent")+getComponentCountOnView(l,"SysFeedbackComponent")===1&&(d=this.getServices().documentModel.getViews().find(t=>t.id===c.conditionalRedirectViewId),viewHasControls(d)||isResultView(d,o)))return this.goToView(d.path[0],c),void t(!0);const E=null!==(i=c.formValue)&&void 0!==i?i:this.form.getControlsMap(),h=this.getContextValue(c);if(!c.skipNavigation&&a&&(viewHasControls(d)||!Object.keys(E).length&&!Object.keys(h).length))return this.goToView(n+1,c),void t(!0);if(!Object.keys(E).length&&!Object.keys(h).length)return void t(!0);const g=UTMParamsExtractor.extractTrackingParams(this.context),R=this.constructRequestPayload({contextValue:h,formValue:E,utmParams:g});this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_STARTED,R),this.eventEmitter.emit("CONTACT_DATA_SUBMIT",R);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(R).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),c.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:a&&d?this.goToView(d.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getSuccessViewIndex());break;case RequestStatus.ALREADY_SUBSCRIBED:m&&d?this.goToView(d.path[0]):this.runPostSubmitActionOrGoToView(()=>this.getAlreadySubscribedViewIndex());break;case RequestStatus.ERROR:m&&d?this.goToView(d.path[0]):this.handleErrorResponse();break;case RequestStatus.TOO_MANY_REQUESTS:this.goToView(m&&d?d.path[0]:this.getErrorViewIndex()),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}),c.skipNavigation||this.handleErrorResponse(),t(!1)})}getContextValue(t){var e,s;if(!t.excludeFormContext)return this.context.getKVMap();const i=(null===(s=(e=this.context).getRecordsMap)||void 0===s?void 0:s.call(e))||{};return Object.values(i).reduce((t,e)=>{var s;const i=null===(s=null==e?void 0:e.getValue)||void 0===s?void 0:s.call(e);return i&&"FORM"!==i.sourceId?(t[i.id]=i.value,t):t},{})}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())}getSuccessViewIndex(){return this.resolveResultViewIndex("successViewId",["DOCUMENT_VIEW_TYPE_SUCCESS","DOCUMENT_VIEW_TYPE_SUCCESSFUL_REQUEST","REQUEST_FORM_VIEW_TYPE_SUCCESS"])}getErrorViewIndex(){return this.resolveResultViewIndex("errorViewId",["DOCUMENT_VIEW_TYPE_ERROR"])}getAlreadySubscribedViewIndex(){const t=this.getActiveSubmitActionParams();return t&&!t.alreadySubscribedViewId?this.getSuccessViewIndex():this.resolveResultViewIndex("alreadySubscribedViewId",["DOCUMENT_VIEW_TYPE_SUBSCRIBED"])}resolveResultViewIndex(t,e){var s;const i=this.getServices().documentModel.getViews(),n=null===(s=this.getActiveSubmitActionParams())||void 0===s?void 0:s[t];if(n){const t=i.findIndex(t=>t.id===n);if(-1!==t)return t}return i.findIndex(t=>e.includes(t.label))}hasFormControls(){return this.form.getControlsAsArray().length>0}getActiveSubmitActionParams(){if(this.hasFormControls())return this.getServices().documentModel.getShared().submitActionParams}runPostSubmitActionOrGoToView(t){var e;const s=null===(e=this.getActiveSubmitActionParams())||void 0===e?void 0:e.runAction;s?setTimeout(()=>{this.getServices().actionFactory.get(s).execute(this.stateService.getState())},1500):this.goToView(t())}handleErrorResponse(){const t=this.getErrorViewIndex();-1!==t?this.goToView(t):this.eventEmitter.emit(SysEventTypes.SUBMIT_REQUEST_ERROR_WITHOUT_VIEW)}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claspo/renderer",
3
- "version": "18.7.4-ctx.9",
3
+ "version": "18.7.5-ctx.10",
4
4
  "scripts": {
5
5
  "dev": " tsc --project tsconfig.json --watch",
6
6
  "build": "rm -rf out && tsc --project tsconfig.json && npm run minify",
@@ -14,6 +14,7 @@ export default class ContextSDK extends DefaultEventEmitter {
14
14
  sourceRegistry: SourceRegistry;
15
15
  data: ContextData;
16
16
  isStaticMode: boolean;
17
+ private subscribedSourceIds;
17
18
  constructor(sourceRegistry: SourceRegistry, contextData: ContextData, isStaticMode: boolean);
18
19
  getRegistry(): SourceRegistry;
19
20
  addRecord: (key: string, params: ContextRecordValueI) => void;
@@ -1 +1 @@
1
- import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import{ContextEvents}from"./ContextEvents";export default class ContextSDK extends DefaultEventEmitter{constructor(e,t,s){super(),this.addRecord=(e,t)=>{const s=this.data.addRecord(e,t);this.subscribeToSource(t),this.emit(ContextEvents.RECORD_ADDED,s)},this.updateRecord=(e,t,s=null)=>{const r=this.data.getRecord(e);(null==r?void 0:r.update(t))&&this.emit(ContextEvents.RECORD_UPDATED,r.getValue(),s)},this.getRecord=e=>this.data.getRecord(e),this.sourceRegistry=e,this.data=t,this.isStaticMode=s,this.initSources()}getRegistry(){return this.sourceRegistry}deleteRecord(e){const t=this.data.getRecord(e);t&&!this.isStaticMode&&(this.data.deleteRecord(e),this.emit(ContextEvents.RECORD_DELETED,t))}getRecordsMap(){return this.data.getRecordsMap()}getKVMap(){return this.data.getKVMap()}initSources(){this.sourceRegistry.registerInitialSources(),this.sourceRegistry.getSources().forEach(e=>{const t=e.getValue();!this.isStaticMode&&t&&Object.keys(t).length&&Object.entries(t).forEach(([e,t])=>{this.addRecord(e,t)})})}subscribeToSource(e){const t=this.sourceRegistry.getSource(e.sourceId);t&&!t.isSubscribed()&&t.subscribe(({key:e,value:s,componentId:r})=>{const o={sourceId:t.id,key:e,value:s,componentId:r};this.getAffectedRecordKeys(t.id,e,r).forEach(e=>{const r=this.data.getRecord(e);if(!r)return;const c=this.resolveRecordValueFromSource(r.getValue(),t,s);this.updateRecord(e,{value:c},o)})})}getAffectedRecordKeys(e,t,s){const r=s||t,o=new Set;return this.data.getRecord(r)&&o.add(r),Object.entries(this.data.getRecordsMap()).forEach(([s,r])=>{const c=r.getValue();c.sourceId===e&&c.sourceDependencyKey&&this.arePathsOverlapping(c.sourceDependencyKey,t)&&o.add(s)}),Array.from(o)}resolveRecordValueFromSource(e,t,s){var r;if(!e.sourceModel)return s;const o=t.getValue(e.sourceDependencyKey||e.id);return o&&"function"==typeof o.processor?o.processor(t,e.sourceModel):null!==(r=null==o?void 0:o.value)&&void 0!==r?r:e.value}arePathsOverlapping(e,t){return e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`)}}
1
+ import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import{ContextEvents}from"./ContextEvents";export default class ContextSDK extends DefaultEventEmitter{constructor(e,t,s){super(),this.subscribedSourceIds=new Set,this.addRecord=(e,t)=>{const s=this.data.addRecord(e,t);this.subscribeToSource(t),this.emit(ContextEvents.RECORD_ADDED,s)},this.updateRecord=(e,t,s=null)=>{const r=this.data.getRecord(e);(null==r?void 0:r.update(t))&&this.emit(ContextEvents.RECORD_UPDATED,r.getValue(),s)},this.getRecord=e=>this.data.getRecord(e),this.sourceRegistry=e,this.data=t,this.isStaticMode=s,this.initSources()}getRegistry(){return this.sourceRegistry}deleteRecord(e){const t=this.data.getRecord(e);t&&!this.isStaticMode&&(this.data.deleteRecord(e),this.emit(ContextEvents.RECORD_DELETED,t))}getRecordsMap(){return this.data.getRecordsMap()}getKVMap(){return this.data.getKVMap()}initSources(){this.sourceRegistry.registerInitialSources(),this.sourceRegistry.getSources().forEach(e=>{const t=e.getValue();!this.isStaticMode&&t&&Object.keys(t).length&&Object.entries(t).forEach(([e,t])=>{this.addRecord(e,t)})})}subscribeToSource(e){const t=this.sourceRegistry.getSource(e.sourceId);t&&!this.subscribedSourceIds.has(t.id)&&(this.subscribedSourceIds.add(t.id),t.subscribe(({key:e,value:s,componentId:r})=>{const o={sourceId:t.id,key:e,value:s,componentId:r};this.getAffectedRecordKeys(t.id,e,r).forEach(e=>{const r=this.data.getRecord(e);if(!r)return;const c=this.resolveRecordValueFromSource(r.getValue(),t,s);this.updateRecord(e,{value:c},o)})}))}getAffectedRecordKeys(e,t,s){const r=s||t,o=new Set;return this.data.getRecord(r)&&o.add(r),Object.entries(this.data.getRecordsMap()).forEach(([s,r])=>{const c=r.getValue();c.sourceId===e&&c.sourceDependencyKey&&this.arePathsOverlapping(c.sourceDependencyKey,t)&&o.add(s)}),Array.from(o)}resolveRecordValueFromSource(e,t,s){var r;if(!e.sourceModel)return s;const o=t.getValue(e.sourceDependencyKey||e.id);return o&&"function"==typeof o.processor?o.processor(t,e.sourceModel):null!==(r=null==o?void 0:o.value)&&void 0!==r?r:e.value}arePathsOverlapping(e,t){return e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`)}}
@@ -1 +1 @@
1
- function flattenDefined(e){return e.reduce((e,r)=>void 0===r?e:Array.isArray(r)?(e.push(...flattenDefined(r)),e):(e.push(r),e),[])}export default function resolveVariableValue(e,r){if(!e||!r)return;if(Object.prototype.hasOwnProperty.call(e,r))return e[r];const t=r.split(".").filter(Boolean);if(!t.length)return;const n=(e,r)=>{if(r>=t.length)return e;if(null!=e){if(Array.isArray(e)){const t=flattenDefined(e.map(e=>n(e,r)));return t.length?t:void 0}return n(e[t[r]],r+1)}};return n(e,0)}
1
+ import{flat}from"@claspo/common/flat";export default function resolveVariableValue(r,t){if(!r||!t)return;if(Object.prototype.hasOwnProperty.call(r,t))return r[t];const e=t.split(".").filter(Boolean);if(!e.length)return;const l=(r,t)=>{if(t>=e.length)return r;if(null!=r){if(Array.isArray(r)){const e=flat(r.map(r=>l(r,t)),1/0).filter(r=>void 0!==r);return e.length?e:void 0}return l(r[e[t]],t+1)}};return l(r,0)}