@claspo/renderer 18.7.4-ctx.9 → 18.7.5
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.
- package/action/UTMParamsExtractor.js +1 -1
- package/action/actions/BaseRequestAction.js +1 -1
- package/package.json +1 -1
- package/sdk/context/ContextSDK.d.ts +1 -9
- package/sdk/context/ContextSDK.js +1 -1
- package/sdk/merge-tags/AbstractMergeTagsProcessor.d.ts +0 -9
- package/sdk/merge-tags/AbstractMergeTagsProcessor.js +1 -1
- package/sdk/merge-tags/StaticMergeTagsProcessor.d.ts +0 -2
- package/sdk/merge-tags/StaticMergeTagsProcessor.js +1 -1
- package/sdk/merge-tags/UpdatingMergeTagsProcessor.js +1 -1
- package/sdk/source/Source.d.ts +2 -0
- package/sdk/source/Source.js +1 -1
- package/sdk/source/SourceRegistry.d.ts +3 -3
- package/sdk/source/SourceRegistry.js +1 -1
- package/sdk/source/sources/JSApiVariablesSource.d.ts +1 -7
- package/sdk/source/sources/JSApiVariablesSource.js +1 -1
- package/sdk/source/sources/resolveVariableValue.d.ts +0 -1
- package/sdk/source/sources/resolveVariableValue.js +0 -1
|
@@ -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)
|
|
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).getSessionHistory(),r={};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,a])=>{const c=getLastMarTechValue(e,a);c&&(r[t]=c)}),r}}
|
|
@@ -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,
|
|
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
|
@@ -7,9 +7,6 @@ export interface SourceUpdateDataI {
|
|
|
7
7
|
value: string;
|
|
8
8
|
componentId?: string;
|
|
9
9
|
}
|
|
10
|
-
export interface ContextRecordUpdatedParamsI extends SourceUpdateDataI {
|
|
11
|
-
sourceId: string;
|
|
12
|
-
}
|
|
13
10
|
export default class ContextSDK extends DefaultEventEmitter {
|
|
14
11
|
sourceRegistry: SourceRegistry;
|
|
15
12
|
data: ContextData;
|
|
@@ -17,7 +14,7 @@ export default class ContextSDK extends DefaultEventEmitter {
|
|
|
17
14
|
constructor(sourceRegistry: SourceRegistry, contextData: ContextData, isStaticMode: boolean);
|
|
18
15
|
getRegistry(): SourceRegistry;
|
|
19
16
|
addRecord: (key: string, params: ContextRecordValueI) => void;
|
|
20
|
-
updateRecord: (key: string, params: Partial<ContextRecordValueI
|
|
17
|
+
updateRecord: (key: string, params: Partial<ContextRecordValueI>) => void;
|
|
21
18
|
deleteRecord(key: string): void;
|
|
22
19
|
getRecord: (key: string) => Record | undefined;
|
|
23
20
|
getRecordsMap(): {
|
|
@@ -28,9 +25,4 @@ export default class ContextSDK extends DefaultEventEmitter {
|
|
|
28
25
|
};
|
|
29
26
|
initSources(): void;
|
|
30
27
|
subscribeToSource(params: ContextRecordValueI): void;
|
|
31
|
-
getAffectedRecordKeys(sourceId: string, changedKey: string, componentId?: string): string[];
|
|
32
|
-
resolveRecordValueFromSource(record: ContextRecordValueI, source: {
|
|
33
|
-
getValue: (key?: string) => any;
|
|
34
|
-
}, fallbackValue: any): any;
|
|
35
|
-
arePathsOverlapping(targetPath: string, changedPath: string): boolean;
|
|
36
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import{ContextEvents}from"./ContextEvents";export default class ContextSDK extends DefaultEventEmitter{constructor(e,
|
|
1
|
+
import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import{ContextEvents}from"./ContextEvents";export default class ContextSDK extends DefaultEventEmitter{constructor(t,e,s){super(),this.addRecord=(t,e)=>{const s=this.data.addRecord(t,e);this.subscribeToSource(e),this.emit(ContextEvents.RECORD_ADDED,s)},this.updateRecord=(t,e)=>{const s=this.data.getRecord(t);(null==s?void 0:s.update(e))&&this.emit(ContextEvents.RECORD_UPDATED,s.getValue())},this.getRecord=t=>this.data.getRecord(t),this.sourceRegistry=t,this.data=e,this.isStaticMode=s,this.initSources()}getRegistry(){return this.sourceRegistry}deleteRecord(t){const e=this.data.getRecord(t);e&&!this.isStaticMode&&(this.data.deleteRecord(t),this.emit(ContextEvents.RECORD_DELETED,e))}getRecordsMap(){return this.data.getRecordsMap()}getKVMap(){return this.data.getKVMap()}initSources(){this.sourceRegistry.registerInitialSources(),this.sourceRegistry.getSources().forEach(t=>{const e=t.getValue();!this.isStaticMode&&e&&Object.keys(e).length&&Object.entries(e).forEach(([t,e])=>{this.addRecord(t,e)})})}subscribeToSource(t){const e=this.sourceRegistry.getSource(t.sourceId);e&&!e.isSubscribed()&&e.subscribe(({key:t,value:e,componentId:s})=>{this.updateRecord(s,{value:e})})}}
|
|
@@ -16,17 +16,8 @@ export default class AbstractMergeTagsProcessor {
|
|
|
16
16
|
element: HTMLElement | null;
|
|
17
17
|
mergeTags: MergeTagsMapI | null;
|
|
18
18
|
componentId: string | null;
|
|
19
|
-
contextRecordUpdatesSubscription: {
|
|
20
|
-
off: () => void;
|
|
21
|
-
} | null;
|
|
22
19
|
constructor(context: ContextSDK, configService: ConfigService);
|
|
23
20
|
destroy(): void;
|
|
24
21
|
process(element: HTMLElement, mergeTags: MergeTagsMapI, componentId: string): void;
|
|
25
22
|
processSingleMergeTag(containerElement: HTMLElement, mergeTag: MergeTagI): void;
|
|
26
|
-
_subscribeToDynamicMergeTagUpdates(): void;
|
|
27
|
-
_processDynamicMergeTags(record: {
|
|
28
|
-
key?: string;
|
|
29
|
-
id?: string;
|
|
30
|
-
} | null): void;
|
|
31
|
-
_findMergeTagElement(mergeTagId: string): HTMLElement | null;
|
|
32
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export default class AbstractMergeTagsProcessor{constructor(e,t){this.context=e,this.configService=t,this.element=null,this.mergeTags=null,this.componentId=null}destroy(){}process(e,t,s){this.element=e,this.mergeTags=t,this.componentId=s,this.mergeTags&&0!==Object.keys(this.mergeTags).length&&this.element.childNodes.forEach(e=>{if(e.nodeType!==Node.TEXT_NODE&&"MERGE_TAG"===e.getAttribute("cl-type")){const t=e.getAttribute("cl-id"),s=this.mergeTags[t];if(!s)return;this.processSingleMergeTag(e,s)}})}processSingleMergeTag(e,t){throw new Error("BaseMergeTagsProcessor: processSingleMergeTag is not implemented")}}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import AbstractMergeTagsProcessor, { MergeTagI } from './AbstractMergeTagsProcessor';
|
|
2
2
|
export default class StaticMergeTagsProcessor extends AbstractMergeTagsProcessor {
|
|
3
|
-
_getRecordId(mergeTag: MergeTagI): string;
|
|
4
|
-
_getMergeTagDependencyPath(mergeTag: MergeTagI): string;
|
|
5
3
|
processSingleMergeTag(tagContainerElement: HTMLElement, mergeTag: MergeTagI): void;
|
|
6
4
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import AbstractMergeTagsProcessor from"./AbstractMergeTagsProcessor";import getMostNestedNode from"@claspo/common/dom/getMostNestedNode";import{PreviewMode}from"../PreviewMode";
|
|
1
|
+
import AbstractMergeTagsProcessor from"./AbstractMergeTagsProcessor";import getMostNestedNode from"@claspo/common/dom/getMostNestedNode";import{PreviewMode}from"../PreviewMode";export default class StaticMergeTagsProcessor extends AbstractMergeTagsProcessor{processSingleMergeTag(e,t){const o=this.context.getRecord(t.id),s=this.context.getRegistry().getSource(t.sourceId),i=this.context.getKVMap();let r,c;if(!o&&i[t.id]&&(c=i[t.id]),s){const e=s.getValue((null==o?void 0:o.value.id)||t.id);c=(null==e?void 0:e.value)||c,e&&"function"==typeof e.processor&&(r=e.processor(s,t))}const d=this.configService.getConfig(PreviewMode.CABINET_PREVIEW)||this.configService.getConfig(PreviewMode.EDITOR_PREVIEW)||this.configService.getConfig(PreviewMode.DEMO);let g=r||c||(null==o?void 0:o.value.value)||t.fallbackValue||(d?t.exampleValue:"");o||this.context.addRecord(t.id,Object.assign(Object.assign({recordKey:t.id,id:t.id,sourceId:t.sourceId},s?s.getValue(t.id):{}),{value:g})),e.style.fontFamily="inherit",getMostNestedNode(e).textContent=g}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ContextEvents}from"../context/ContextEvents";import AbstractMergeTagsProcessor from"./AbstractMergeTagsProcessor";import getMostNestedNode from"@claspo/common/dom/getMostNestedNode";import DataLayerSource from"../source/sources/DataLayerSource";import UrlQueryParamsSource from"../source/sources/UrlQueryParamsSource";import JSApiVariablesSource from"../source/sources/JSApiVariablesSource";import CookieSource from"../source/sources/CookieSource";import LocalStorageSource from"../source/sources/LocalStorageSource";export default class UpdatingMergeTagsProcessor extends AbstractMergeTagsProcessor{constructor(e,o){super(e,o),this.contextSubscriptions=[this.context.on(ContextEvents.RECORD_ADDED,this._handleContextEvents.bind(this)),this.context.on(ContextEvents.RECORD_DELETED,this._handleContextEvents.bind(this))]}destroy(){super.destroy(),this.contextSubscriptions&&this.contextSubscriptions.forEach(e=>e.off())}processSingleMergeTag(e,o){if(!e)return;const
|
|
1
|
+
import{ContextEvents}from"../context/ContextEvents";import AbstractMergeTagsProcessor from"./AbstractMergeTagsProcessor";import getMostNestedNode from"@claspo/common/dom/getMostNestedNode";import DataLayerSource from"../source/sources/DataLayerSource";import UrlQueryParamsSource from"../source/sources/UrlQueryParamsSource";import JSApiVariablesSource from"../source/sources/JSApiVariablesSource";import CookieSource from"../source/sources/CookieSource";import LocalStorageSource from"../source/sources/LocalStorageSource";export default class UpdatingMergeTagsProcessor extends AbstractMergeTagsProcessor{constructor(e,o){super(e,o),this.contextSubscriptions=[this.context.on(ContextEvents.RECORD_ADDED,this._handleContextEvents.bind(this)),this.context.on(ContextEvents.RECORD_UPDATED,this._handleContextEvents.bind(this)),this.context.on(ContextEvents.RECORD_DELETED,this._handleContextEvents.bind(this))]}destroy(){super.destroy(),this.contextSubscriptions&&this.contextSubscriptions.forEach(e=>e.off())}processSingleMergeTag(e,o){if(!e)return;const t=this.context.getRecord(o.id);e.style.fontFamily="inherit",getMostNestedNode(e).textContent=o.exampleValue,this._setMergeTagValidity(t,o,e)}_setMergeTagValidity(e,o,t){let r=!1;if(e||o.sourceId===DataLayerSource.sourceId||o.sourceId===UrlQueryParamsSource.sourceId||o.sourceId===JSApiVariablesSource.sourceId||o.sourceId===CookieSource.sourceId||o.sourceId===LocalStorageSource.sourceId||(r=!0),o.sourceId===DataLayerSource.sourceId){const e=o.arguments.find(e=>"dataLayerPropPath"===e.name);e&&e.value||(r=!0)}else{(!o.exampleValue||o.arguments&&!o.arguments.find(e=>e.value))&&(r=!0)}const s="tag-error";r?t.classList.add(s):t.classList.remove(s)}_handleContextEvents(e){var o;const t=null===(o=this.mergeTags)||void 0===o?void 0:o[e.key];t&&this.processSingleMergeTag(this.element.querySelector(`[cl-id="${t.id}"]`),t)}}
|
package/sdk/source/Source.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { SourceUpdateDataI } from '../context/ContextSDK';
|
|
|
2
2
|
export interface SubscriptionEntryI {
|
|
3
3
|
subscribe(cb: (data: SourceUpdateDataI) => void): void;
|
|
4
4
|
getValue(key?: string): any;
|
|
5
|
+
getSessionHistory?(): string[];
|
|
5
6
|
}
|
|
6
7
|
export interface SourceConfigI {
|
|
7
8
|
[key: string]: any;
|
|
@@ -14,5 +15,6 @@ export default class Source {
|
|
|
14
15
|
constructor(id: string, subscriptionEntry: SubscriptionEntryI, config?: SourceConfigI);
|
|
15
16
|
subscribe(cb: (data: SourceUpdateDataI) => void): void;
|
|
16
17
|
getValue(key?: string): any;
|
|
18
|
+
getSessionHistory(): string[];
|
|
17
19
|
isSubscribed(): boolean;
|
|
18
20
|
}
|
package/sdk/source/Source.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default class Source{constructor(s,i,t={}){this.id=s,this.subscriptionEntry=i,this.config=t,this.subscribed=!1}subscribe(s){this.subscribed=!0,this.subscriptionEntry.subscribe(s)}getValue(s){return this.subscriptionEntry.getValue(s)}isSubscribed(){return this.subscribed}}
|
|
1
|
+
export default class Source{constructor(s,i,t={}){this.id=s,this.subscriptionEntry=i,this.config=t,this.subscribed=!1}subscribe(s){this.subscribed=!0,this.subscriptionEntry.subscribe(s)}getValue(s){return this.subscriptionEntry.getValue(s)}getSessionHistory(){var s,i;return(null===(i=(s=this.subscriptionEntry).getSessionHistory)||void 0===i?void 0:i.call(s))||[new URL(window.location.href).search]}isSubscribed(){return this.subscribed}}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Source from "./Source";
|
|
2
2
|
import { UrlQueryParamsConfigI } from "./sources/UrlQueryParamsSource";
|
|
3
|
+
import { JSApiVariablesConfigI } from "./sources/JSApiVariablesSource";
|
|
3
4
|
import FormGroup from '../../form/FormGroup';
|
|
4
|
-
export interface SourceRegistryConfigI extends UrlQueryParamsConfigI {
|
|
5
|
-
jsSource?: Source;
|
|
5
|
+
export interface SourceRegistryConfigI extends UrlQueryParamsConfigI, JSApiVariablesConfigI {
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}
|
|
8
8
|
export default class SourceRegistry {
|
|
@@ -10,7 +10,7 @@ export default class SourceRegistry {
|
|
|
10
10
|
[key: string]: Source;
|
|
11
11
|
};
|
|
12
12
|
sources: Source[];
|
|
13
|
-
constructor(form: FormGroup, config
|
|
13
|
+
constructor(form: FormGroup, config: SourceRegistryConfigI);
|
|
14
14
|
registerSource(source: Source): Source;
|
|
15
15
|
getSource(id: string): Source | undefined;
|
|
16
16
|
getSources(): Source[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Source from"./Source";import FormSource from"./sources/FormSource";import UrlQueryParamsSource from"./sources/UrlQueryParamsSource";import DataLayerSource from"./sources/DataLayerSource";import CookieSource from"./sources/CookieSource";import LocalStorageSource from"./sources/LocalStorageSource";export default class SourceRegistry{constructor(r,e
|
|
1
|
+
import Source from"./Source";import FormSource from"./sources/FormSource";import UrlQueryParamsSource from"./sources/UrlQueryParamsSource";import DataLayerSource from"./sources/DataLayerSource";import JSApiVariablesSource from"./sources/JSApiVariablesSource";import CookieSource from"./sources/CookieSource";import LocalStorageSource from"./sources/LocalStorageSource";export default class SourceRegistry{constructor(r,e){this.registeredSourcesMap={},this.sources=[new Source("FORM",new FormSource(r)),new Source("DATA_LAYER",new DataLayerSource),new Source("URL_QUERY_PARAMS",new UrlQueryParamsSource(e)),new Source("JS_API_VARIABLE",new JSApiVariablesSource(e)),new Source("COOKIE",new CookieSource),new Source("LOCAL_STORAGE",new LocalStorageSource)]}registerSource(r){if(this.registeredSourcesMap[r.id])throw new Error(`Source with id ${r.id} already registered`);return this.registeredSourcesMap[r.id]=r}getSource(r){return this.registeredSourcesMap[r]}getSources(){return Object.values(this.registeredSourcesMap)}registerInitialSources(){return this.sources.map(r=>this.registerSource(r))}}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import DefaultEventEmitter from "@claspo/common/DefaultEventEmitter";
|
|
2
2
|
import { SourceUpdateDataI } from '../../context/ContextSDK';
|
|
3
|
-
import { SourceType } from "@claspo/common/document/hidden-fields.interface";
|
|
4
3
|
declare global {
|
|
5
4
|
interface Window {
|
|
6
5
|
[key: string]: any;
|
|
@@ -22,15 +21,10 @@ export interface JSApiVariablesProcessorResultI {
|
|
|
22
21
|
processor: (ctx: any, model: JSApiVariablesModelI) => string;
|
|
23
22
|
}
|
|
24
23
|
export default class JSApiVariablesSource extends DefaultEventEmitter {
|
|
25
|
-
static sourceId:
|
|
24
|
+
static sourceId: string;
|
|
26
25
|
instanceName: string | undefined;
|
|
27
26
|
constructor(config?: JSApiVariablesConfigI);
|
|
28
|
-
get appInstance(): any;
|
|
29
|
-
get variables(): any;
|
|
30
27
|
subscribe(cb: (data: SourceUpdateDataI) => void): void;
|
|
31
28
|
getValue(key?: string): JSApiVariablesProcessorResultI | Record<string, never>;
|
|
32
|
-
addValues<T extends {
|
|
33
|
-
[key: string]: any;
|
|
34
|
-
}>(values: T): void;
|
|
35
29
|
static processModel(model: JSApiVariablesModelI, instanceName?: string): string;
|
|
36
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";
|
|
1
|
+
import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";class JSApiVariablesSource extends DefaultEventEmitter{constructor(e={}){super(),this.instanceName=e.instanceName}subscribe(e){}getValue(e){return e?{processor:(e,r)=>JSApiVariablesSource.processModel(r,this.instanceName)}:{}}static processModel(e,r){var a;if(!e.arguments)return"";const t=e.arguments.find(e=>"JavaScriptVariable"===e.name);if(!(null==t?void 0:t.value)||!r||!(null===(a=window[r])||void 0===a?void 0:a.variables))return"";try{return window[r].variables[t.value]||""}catch(r){return console.error("JSApiVariablesSource: error while getting variable. Model: ",e,"Error: ",r),""}}}JSApiVariablesSource.sourceId="JS_API_VARIABLE";export default JSApiVariablesSource;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function resolveVariableValue(variables: Record<string, any> | undefined, key: string | undefined): any;
|
|
@@ -1 +0,0 @@
|
|
|
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)}
|