@claspo/renderer 18.10.0 → 18.10.2-datalayer-ecommerce-16105161.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claspo/renderer",
3
- "version": "18.10.0",
3
+ "version": "18.10.2-datalayer-ecommerce-16105161.0",
4
4
  "scripts": {
5
5
  "dev": " tsc --project tsconfig.json --watch",
6
6
  "build": "rm -rf out && tsc --project tsconfig.json && npm run minify",
@@ -1 +1 @@
1
- import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import isDictionary from"@claspo/common/object/isDictionary";import flatMap from"@claspo/common/utils/flatMap";function getPropPathArray(r){return r?flatMap(r.value.split(".").map(r=>r.trim()).map(r=>r.split(/[\[\]]/)),r=>r).filter(r=>!!r):[]}class DataLayerSource extends DefaultEventEmitter{constructor(){super()}subscribe(r){}getValue(r){return r?{processor:(r,e)=>DataLayerSource.processModel(e)}:{}}static processModel(r,e){if(!r.arguments)return"";const t=r.arguments.find(r=>"dataLayerEventName"===r.name),a=r.arguments.find(r=>"dataLayerPropPath"===r.name),o=!!(null==t?void 0:t.value);if(!window.dataLayer)return"";let n;for(let i=window.dataLayer.length-1;i>=0;i--){const u=window.dataLayer[i];if(o){if((null==u?void 0:u.event)===t.value){n=u;break}if("event"===(null==u?void 0:u[0])&&(null==u?void 0:u[1])===t.value){n=u[2];break}}else{const t=getPropPathArray(a),o=DataLayerSource.getValueByPropPath(u,t,r,e);if(o)return o}}if(!n)return"";const i=getPropPathArray(a);return DataLayerSource.getValueByPropPath(n,i,r,e)}static getValueByPropPath(r,e,t,a){try{const t=e.reduce((r,e)=>{if(isDictionary(r)||Array.isArray(r))return r[e];throw new Error(`Tried to access non object data by propName "${e}". Data: ${r}`)},r);return Array.isArray(t)&&!a?t.join(", "):t}catch(r){return console.error("DataLayerSource: error while getting data by prop path. Model: ",t,"Error: ",r),""}}}DataLayerSource.sourceId="DATA_LAYER";export default DataLayerSource;
1
+ import DefaultEventEmitter from"@claspo/common/DefaultEventEmitter";import isDictionary from"@claspo/common/object/isDictionary";import flatMap from"@claspo/common/utils/flatMap";import transformDataLayerEvent from"./transformDataLayerEvent";function getPropPathArray(r){return r?flatMap(r.value.split(".").map(r=>r.trim()).map(r=>r.split(/[\[\]]/)),r=>r).filter(r=>!!r):[]}class DataLayerSource extends DefaultEventEmitter{constructor(){super()}subscribe(r){}getValue(r){return r?{processor:(r,a)=>DataLayerSource.processModel(a)}:{}}static processModel(r,a){if(!r.arguments)return"";const t=r.arguments.find(r=>"dataLayerEventName"===r.name),e=r.arguments.find(r=>"dataLayerPropPath"===r.name),o=!!(null==t?void 0:t.value);if(!window.dataLayer)return"";let n;for(let s=window.dataLayer.length-1;s>=0;s--){const i=window.dataLayer[s];if(o){const r=transformDataLayerEvent(i,{eventName:null==t?void 0:t.value,allowAccessors:!0});if(r){n=r.data;break}}else{const t=getPropPathArray(e),o=DataLayerSource.getValueByPropPath(i,t,r,a);if(o)return o}}if(!n)return"";const s=getPropPathArray(e);return DataLayerSource.getValueByPropPath(n,s,r,a)}static getValueByPropPath(r,a,t,e){try{const t=a.reduce((r,a)=>{if(isDictionary(r)||Array.isArray(r))return r[a];throw new Error(`Tried to access non object data by propName "${a}". Data: ${r}`)},r);return Array.isArray(t)&&!e?t.join(", "):t}catch(r){return console.error("DataLayerSource: error while getting data by prop path. Model: ",t,"Error: ",r),""}}}DataLayerSource.sourceId="DATA_LAYER";export default DataLayerSource;
@@ -0,0 +1,2 @@
1
+ import { DataLayerEventI, TransformDataLayerEventOptionsI } from './transformDataLayerEvent.interface';
2
+ export default function transformDataLayerEvent(record: any, options?: TransformDataLayerEventOptionsI): DataLayerEventI | undefined;
@@ -0,0 +1,9 @@
1
+ export interface DataLayerEventI {
2
+ name: string;
3
+ format: 'object' | 'command';
4
+ data: any;
5
+ }
6
+ export interface TransformDataLayerEventOptionsI {
7
+ eventName?: string;
8
+ allowAccessors?: boolean;
9
+ }
@@ -0,0 +1 @@
1
+ function readProperty(e,r,t){if(t)return e[r];const o=Object.getOwnPropertyDescriptor(e,r);if(o){if(!("value"in o))throw new TypeError(`DataLayer event property "${r}" is an accessor`);return o.value}}export default function transformDataLayerEvent(e,r={}){if(null==e||!r.allowAccessors&&"object"!=typeof e)return;const t=readProperty(e,"event",r.allowAccessors);if("string"==typeof t&&(void 0===r.eventName||t===r.eventName))return{name:t,format:"object",data:e};if("event"!==readProperty(e,"0",r.allowAccessors))return;const o=readProperty(e,"1",r.allowAccessors);return"string"!=typeof o||void 0!==r.eventName&&o!==r.eventName?void 0:{name:o,format:"command",data:readProperty(e,"2",r.allowAccessors)}}