@walkeros/core 1.2.1 → 1.2.2
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/README.md +1 -1
- package/dist/index.d.mts +3 -12
- package/dist/index.d.ts +3 -12
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="left">
|
|
2
2
|
<a href="https://www.walkeros.io">
|
|
3
|
-
<img title="
|
|
3
|
+
<img alt="walkerOS" title="walkerOS" src="https://www.walkeros.io/img/walkerOS_logo.svg" width="256px"/>
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
package/dist/index.d.mts
CHANGED
|
@@ -53,15 +53,6 @@ interface Destinations$1 {
|
|
|
53
53
|
interface Transformers$1 {
|
|
54
54
|
[id: string]: Instance$1;
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Resolved transformer chains for a flow.
|
|
58
|
-
*/
|
|
59
|
-
interface TransformerChain {
|
|
60
|
-
/** Ordered transformer IDs to run before collector (from source.next) */
|
|
61
|
-
pre: string[];
|
|
62
|
-
/** Per-destination transformer chains (from destination.before) */
|
|
63
|
-
post: Record<string, string[]>;
|
|
64
|
-
}
|
|
65
56
|
type CommandType = 'action' | 'config' | 'consent' | 'context' | 'destination' | 'elb' | 'globals' | 'hook' | 'init' | 'link' | 'run' | 'user' | 'walker' | string;
|
|
66
57
|
/**
|
|
67
58
|
* Options passed to collector.push() from sources.
|
|
@@ -108,7 +99,6 @@ interface Instance$4 {
|
|
|
108
99
|
sources: Sources;
|
|
109
100
|
destinations: Destinations$1;
|
|
110
101
|
transformers: Transformers$1;
|
|
111
|
-
transformerChain: TransformerChain;
|
|
112
102
|
globals: Properties;
|
|
113
103
|
group: string;
|
|
114
104
|
hooks: Functions;
|
|
@@ -128,9 +118,8 @@ type collector_InitConfig = InitConfig;
|
|
|
128
118
|
type collector_PushOptions = PushOptions;
|
|
129
119
|
type collector_SessionData = SessionData;
|
|
130
120
|
type collector_Sources = Sources;
|
|
131
|
-
type collector_TransformerChain = TransformerChain;
|
|
132
121
|
declare namespace collector {
|
|
133
|
-
export type { collector_CommandFn as CommandFn, collector_CommandType as CommandType, Config$7 as Config, Destinations$1 as Destinations, collector_InitConfig as InitConfig, Instance$4 as Instance, PushFn$1 as PushFn, collector_PushOptions as PushOptions, collector_SessionData as SessionData, collector_Sources as Sources,
|
|
122
|
+
export type { collector_CommandFn as CommandFn, collector_CommandType as CommandType, Config$7 as Config, Destinations$1 as Destinations, collector_InitConfig as InitConfig, Instance$4 as Instance, PushFn$1 as PushFn, collector_PushOptions as PushOptions, collector_SessionData as SessionData, collector_Sources as Sources, Transformers$1 as Transformers };
|
|
134
123
|
}
|
|
135
124
|
|
|
136
125
|
/**
|
|
@@ -273,6 +262,7 @@ interface Config$6<T extends TypesGeneric$2 = Types$3> {
|
|
|
273
262
|
mapping?: Rules<Rule<Mapping$1<T>>>;
|
|
274
263
|
policy?: Policy$1;
|
|
275
264
|
queue?: boolean;
|
|
265
|
+
before?: string | string[];
|
|
276
266
|
}
|
|
277
267
|
type PartialConfig$1<T extends TypesGeneric$2 = Types$3> = Config$6<Types$3<Partial<Settings$2<T>> | Settings$2<T>, Partial<Mapping$1<T>> | Mapping$1<T>, Env$2<T>>>;
|
|
278
268
|
interface Policy$1 {
|
|
@@ -283,6 +273,7 @@ type Init$2<T extends TypesGeneric$2 = Types$3> = {
|
|
|
283
273
|
code: Code<T>;
|
|
284
274
|
config?: Partial<Config$6<T>>;
|
|
285
275
|
env?: Partial<Env$2<T>>;
|
|
276
|
+
before?: string | string[];
|
|
286
277
|
};
|
|
287
278
|
interface InitDestinations {
|
|
288
279
|
[key: string]: Init$2<any>;
|
package/dist/index.d.ts
CHANGED
|
@@ -53,15 +53,6 @@ interface Destinations$1 {
|
|
|
53
53
|
interface Transformers$1 {
|
|
54
54
|
[id: string]: Instance$1;
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Resolved transformer chains for a flow.
|
|
58
|
-
*/
|
|
59
|
-
interface TransformerChain {
|
|
60
|
-
/** Ordered transformer IDs to run before collector (from source.next) */
|
|
61
|
-
pre: string[];
|
|
62
|
-
/** Per-destination transformer chains (from destination.before) */
|
|
63
|
-
post: Record<string, string[]>;
|
|
64
|
-
}
|
|
65
56
|
type CommandType = 'action' | 'config' | 'consent' | 'context' | 'destination' | 'elb' | 'globals' | 'hook' | 'init' | 'link' | 'run' | 'user' | 'walker' | string;
|
|
66
57
|
/**
|
|
67
58
|
* Options passed to collector.push() from sources.
|
|
@@ -108,7 +99,6 @@ interface Instance$4 {
|
|
|
108
99
|
sources: Sources;
|
|
109
100
|
destinations: Destinations$1;
|
|
110
101
|
transformers: Transformers$1;
|
|
111
|
-
transformerChain: TransformerChain;
|
|
112
102
|
globals: Properties;
|
|
113
103
|
group: string;
|
|
114
104
|
hooks: Functions;
|
|
@@ -128,9 +118,8 @@ type collector_InitConfig = InitConfig;
|
|
|
128
118
|
type collector_PushOptions = PushOptions;
|
|
129
119
|
type collector_SessionData = SessionData;
|
|
130
120
|
type collector_Sources = Sources;
|
|
131
|
-
type collector_TransformerChain = TransformerChain;
|
|
132
121
|
declare namespace collector {
|
|
133
|
-
export type { collector_CommandFn as CommandFn, collector_CommandType as CommandType, Config$7 as Config, Destinations$1 as Destinations, collector_InitConfig as InitConfig, Instance$4 as Instance, PushFn$1 as PushFn, collector_PushOptions as PushOptions, collector_SessionData as SessionData, collector_Sources as Sources,
|
|
122
|
+
export type { collector_CommandFn as CommandFn, collector_CommandType as CommandType, Config$7 as Config, Destinations$1 as Destinations, collector_InitConfig as InitConfig, Instance$4 as Instance, PushFn$1 as PushFn, collector_PushOptions as PushOptions, collector_SessionData as SessionData, collector_Sources as Sources, Transformers$1 as Transformers };
|
|
134
123
|
}
|
|
135
124
|
|
|
136
125
|
/**
|
|
@@ -273,6 +262,7 @@ interface Config$6<T extends TypesGeneric$2 = Types$3> {
|
|
|
273
262
|
mapping?: Rules<Rule<Mapping$1<T>>>;
|
|
274
263
|
policy?: Policy$1;
|
|
275
264
|
queue?: boolean;
|
|
265
|
+
before?: string | string[];
|
|
276
266
|
}
|
|
277
267
|
type PartialConfig$1<T extends TypesGeneric$2 = Types$3> = Config$6<Types$3<Partial<Settings$2<T>> | Settings$2<T>, Partial<Mapping$1<T>> | Mapping$1<T>, Env$2<T>>>;
|
|
278
268
|
interface Policy$1 {
|
|
@@ -283,6 +273,7 @@ type Init$2<T extends TypesGeneric$2 = Types$3> = {
|
|
|
283
273
|
code: Code<T>;
|
|
284
274
|
config?: Partial<Config$6<T>>;
|
|
285
275
|
env?: Partial<Env$2<T>>;
|
|
276
|
+
before?: string | string[];
|
|
286
277
|
};
|
|
287
278
|
interface InitDestinations {
|
|
288
279
|
[key: string]: Init$2<any>;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i=(e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})},s={};i(s,{Collector:()=>a,Const:()=>x,Context:()=>c,Data:()=>u,Destination:()=>l,Elb:()=>f,Flow:()=>p,Hooks:()=>d,Level:()=>m,Logger:()=>g,Mapping:()=>y,On:()=>b,Request:()=>h,Schema:()=>w,Source:()=>j,Transformer:()=>v,WalkerOS:()=>O,anonymizeIP:()=>k,assign:()=>N,castToProperty:()=>fe,castValue:()=>G,clone:()=>q,createDestination:()=>X,createEvent:()=>Q,createLogger:()=>ae,createMockLogger:()=>we,debounce:()=>ne,filterValues:()=>le,getBrowser:()=>Pe,getBrowserVersion:()=>$e,getByPath:()=>W,getDeviceType:()=>_e,getEvent:()=>Y,getFlowConfig:()=>T,getGrantedConsent:()=>J,getHeaders:()=>ke,getId:()=>ee,getMappingEvent:()=>ge,getMappingValue:()=>me,getMarketingParameters:()=>te,getOS:()=>Me,getOSVersion:()=>Te,getPlatform:()=>_,isArguments:()=>D,isArray:()=>V,isBoolean:()=>I,isCommand:()=>L,isDefined:()=>R,isElementOrDocument:()=>z,isFunction:()=>F,isNumber:()=>B,isObject:()=>K,isPropertyType:()=>ue,isSameType:()=>U,isString:()=>H,mockEnv:()=>ve,packageNameToVariable:()=>$,parseUserAgent:()=>Ae,processEventMapping:()=>be,requestToData:()=>je,requestToParameter:()=>Oe,setByPath:()=>Z,throttle:()=>oe,throwError:()=>E,transformData:()=>xe,traverseEnv:()=>he,trim:()=>Ee,tryCatch:()=>pe,tryCatchAsync:()=>de,useHooks:()=>Se,validateEvent:()=>Ce,validateProperty:()=>Ne,wrapCondition:()=>Ve,wrapFn:()=>Ie,wrapValidate:()=>Le}),module.exports=(e=s,((e,i,s,a)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of o(i))r.call(e,c)||c===s||t(e,c,{get:()=>i[c],enumerable:!(a=n(i,c))||a.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a={},c={},u={},l={},f={},p={},d={},g={};i(g,{Level:()=>m});var m=(e=>(e[e.ERROR=0]="ERROR",e[e.INFO=1]="INFO",e[e.DEBUG=2]="DEBUG",e))(m||{}),y={},b={},v={},h={},w={},j={},O={},x={Utils:{Storage:{Local:"local",Session:"session",Cookie:"cookie"}}};function k(e){return/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e)?e.replace(/\.\d+$/,".0"):""}function E(e){throw new Error(String(e))}function S(...e){const t={};for(const n of e)n&&Object.assign(t,n);return t}function A(...e){const t={};for(const n of e)n&&Object.assign(t,n);return t}function P(e,t,n){if("string"==typeof e){const o=e.match(/^\$def\.([a-zA-Z_][a-zA-Z0-9_]*)$/);if(o){const e=o[1];return void 0===n[e]&&E(`Definition "${e}" not found`),P(n[e],t,n)}let r=e.replace(/\$var\.([a-zA-Z_][a-zA-Z0-9_]*)/g,(e,n)=>{if(void 0!==t[n])return String(t[n]);E(`Variable "${n}" not found`)});return r=r.replace(/\$env\.([a-zA-Z_][a-zA-Z0-9_]*)(?::([^"}\s]*))?/g,(e,t,n)=>"undefined"!=typeof process&&void 0!==process.env?.[t]?process.env[t]:void 0!==n?n:void E(`Environment variable "${t}" not found and no default provided`)),r}if(Array.isArray(e))return e.map(e=>P(e,t,n));if(null!==e&&"object"==typeof e){const o={};for(const[r,i]of Object.entries(e))o[r]=P(i,t,n);return o}return e}function $(e){const t=e.startsWith("@"),n=e.replace("@","").replace(/[/-]/g,"_").split("_").filter(e=>e.length>0).map((e,t)=>0===t?e:e.charAt(0).toUpperCase()+e.slice(1)).join("");return t?"_"+n:n}function M(e,t,n){if(t)return t;if(!e||!n)return;return n[e]?$(e):void 0}function T(e,t){const n=Object.keys(e.flows);t||(1===n.length?t=n[0]:E(`Multiple flows found (${n.join(", ")}). Please specify a flow.`));const o=e.flows[t];o||E(`Flow "${t}" not found. Available: ${n.join(", ")}`);const r=JSON.parse(JSON.stringify(o));if(r.sources)for(const[t,n]of Object.entries(r.sources)){const i=S(e.variables,o.variables,n.variables),s=A(e.definitions,o.definitions,n.definitions),a=P(n.config,i,s),c=M(n.package,n.code,r.packages),u="string"==typeof n.code||"object"==typeof n.code?n.code:void 0,l=c||u;r.sources[t]={package:n.package,config:a,env:n.env,primary:n.primary,variables:n.variables,definitions:n.definitions,next:n.next,code:l}}if(r.destinations)for(const[t,n]of Object.entries(r.destinations)){const i=S(e.variables,o.variables,n.variables),s=A(e.definitions,o.definitions,n.definitions),a=P(n.config,i,s),c=M(n.package,n.code,r.packages),u="string"==typeof n.code||"object"==typeof n.code?n.code:void 0,l=c||u;r.destinations[t]={package:n.package,config:a,env:n.env,variables:n.variables,definitions:n.definitions,before:n.before,code:l}}if(r.collector){const t=S(e.variables,o.variables),n=A(e.definitions,o.definitions),i=P(r.collector,t,n);r.collector=i}return r}function _(e){return void 0!==e.web?"web":void 0!==e.server?"server":void E("Config must have web or server key")}var C={merge:!0,shallow:!0,extend:!0};function N(e,t={},n={}){n={...C,...n};const o=Object.entries(t).reduce((t,[o,r])=>{const i=e[o];return n.merge&&Array.isArray(i)&&Array.isArray(r)?t[o]=r.reduce((e,t)=>e.includes(t)?e:[...e,t],[...i]):(n.extend||o in e)&&(t[o]=r),t},{});return n.shallow?{...e,...o}:(Object.assign(e,o),e)}function D(e){return"[object Arguments]"===Object.prototype.toString.call(e)}function V(e){return Array.isArray(e)}function I(e){return"boolean"==typeof e}function L(e){return"walker"===e}function R(e){return void 0!==e}function z(e){return e===document||e instanceof Element}function F(e){return"function"==typeof e}function B(e){return"number"==typeof e&&!Number.isNaN(e)}function K(e){return"object"==typeof e&&null!==e&&!V(e)&&"[object Object]"===Object.prototype.toString.call(e)}function U(e,t){return typeof e==typeof t}function H(e){return"string"==typeof e}function q(e,t=new WeakMap){if("object"!=typeof e||null===e)return e;if(t.has(e))return t.get(e);const n=Object.prototype.toString.call(e);if("[object Object]"===n){const n={};t.set(e,n);for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=q(e[o],t));return n}if("[object Array]"===n){const n=[];return t.set(e,n),e.forEach(e=>{n.push(q(e,t))}),n}if("[object Date]"===n)return new Date(e.getTime());if("[object RegExp]"===n){const t=e;return new RegExp(t.source,t.flags)}return e}function W(e,t="",n){const o=t.split(".");let r=e;for(let e=0;e<o.length;e++){const t=o[e];if("*"===t&&V(r)){const t=o.slice(e+1).join("."),i=[];for(const e of r){const o=W(e,t,n);i.push(o)}return i}if(r=r instanceof Object?r[t]:void 0,!r)break}return R(r)?r:n}function Z(e,t,n){if(!K(e))return e;const o=q(e),r=t.split(".");let i=o;for(let e=0;e<r.length;e++){const t=r[e];e===r.length-1?i[t]=n:(t in i&&"object"==typeof i[t]&&null!==i[t]||(i[t]={}),i=i[t])}return o}function G(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}function J(e,t={},n={}){const o={...t,...n},r={};let i=void 0===e;return Object.keys(o).forEach(t=>{o[t]&&(r[t]=!0,e&&e[t]&&(i=!0))}),!!i&&r}function X(e,t){const n={...e};return n.config=N(e.config,t,{shallow:!0,merge:!0,extend:!0}),e.config.settings&&t.settings&&(n.config.settings=N(e.config.settings,t.settings,{shallow:!0,merge:!0,extend:!0})),e.config.mapping&&t.mapping&&(n.config.mapping=N(e.config.mapping,t.mapping,{shallow:!0,merge:!0,extend:!0})),n}function Q(e={}){const t=e.timestamp||(new Date).setHours(0,13,37,0),n=e.group||"gr0up",o=e.count||1,r=N({name:"entity action",data:{string:"foo",number:1,boolean:!0,array:[0,"text",!1],not:void 0},context:{dev:["test",1]},globals:{lang:"elb"},custom:{completely:"random"},user:{id:"us3r",device:"c00k13",session:"s3ss10n"},nested:[{entity:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${t}-${n}-${o}`,trigger:"test",entity:"entity",action:"action",timestamp:t,timing:3.14,group:n,count:o,version:{source:"1.2.0",tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.name){const[t,n]=e.name.split(" ")??[];t&&n&&(r.entity=t,r.action=n)}return r}function Y(e="entity action",t={}){const n=t.timestamp||(new Date).setHours(0,13,37,0),o={data:{id:"ers",name:"Everyday Ruck Snack",color:"black",size:"l",price:420}},r={data:{id:"cc",name:"Cool Cap",size:"one size",price:42}};return Q({...{"cart view":{data:{currency:"EUR",value:2*o.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:{...o.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:o.data.price+r.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...o,context:{shopping:["checkout",0]},nested:[]},{entity:"product",...r,context:{shopping:["checkout",0]},nested:[]}],trigger:"load"},"order complete":{data:{id:"0rd3r1d",currency:"EUR",shipping:5.22,taxes:73.76,total:555},context:{shopping:["complete",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...o,context:{shopping:["complete",0]},nested:[]},{entity:"product",...r,context:{shopping:["complete",0]},nested:[]},{entity:"gift",data:{name:"Surprise"},context:{shopping:["complete",0]},nested:[]}],trigger:"load"},"page view":{data:{domain:"www.example.com",title:"walkerOS documentation",referrer:"https://www.walkeros.io/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...o,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...o,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...o.data,position:3,promo:!0},context:{shopping:["discover",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"promotion visible":{data:{name:"Setting up tracking easily",position:"hero"},context:{ab_test:["engagement",0]},globals:{pagegroup:"homepage"},trigger:"visible"},"session start":{data:{id:"s3ss10n",start:n,isNew:!0,count:1,runs:1,isStart:!0,storage:!0,referrer:"",device:"c00k13"},user:{id:"us3r",device:"c00k13",session:"s3ss10n",hash:"h4sh",address:"street number",email:"user@example.com",phone:"+49 123 456 789",userAgent:"Mozilla...",browser:"Chrome",browserVersion:"90",deviceType:"desktop",language:"de-DE",country:"DE",region:"HH",city:"Hamburg",zip:"20354",timezone:"Berlin",os:"walkerOS",osVersion:"1.0",screenSize:"1337x420",ip:"127.0.0.0",internal:!0,custom:"value"}}}[e],...t,name:e})}function ee(e=6){let t="";for(let n=36;t.length<e;)t+=(Math.random()*n|0).toString(n);return t}function te(e,t={}){const n="clickId",o={},r={utm_campaign:"campaign",utm_content:"content",utm_medium:"medium",utm_source:"source",utm_term:"term",dclid:n,fbclid:n,gclid:n,msclkid:n,ttclid:n,twclid:n,igshid:n,sclid:n};return Object.entries(N(r,t)).forEach(([t,r])=>{const i=e.searchParams.get(t);i&&(r===n&&(r=t,o[n]=t),o[r]=i)}),o}function ne(e,t=1e3,n=!1){let o,r=null,i=!1;return(...s)=>new Promise(a=>{const c=n&&!i;r&&clearTimeout(r),r=setTimeout(()=>{r=null,n&&!i||(o=e(...s),a(o))},t),c&&(i=!0,o=e(...s),a(o))})}function oe(e,t=1e3){let n=null;return function(...o){if(null===n)return n=setTimeout(()=>{n=null},t),e(...o)}}function re(e){return{message:e.message,name:e.name,stack:e.stack,cause:e.cause}}function ie(e,t){let n,o={};return e instanceof Error?(n=e.message,o.error=re(e)):n=e,void 0!==t&&(t instanceof Error?o.error=re(t):"object"==typeof t&&null!==t?(o={...o,...t},"error"in o&&o.error instanceof Error&&(o.error=re(o.error))):o.value=t),{message:n,context:o}}var se=(e,t,n,o)=>{const r=`${m[e]}${o.length>0?` [${o.join(":")}]`:""}`,i=Object.keys(n).length>0;0===e?i?console.error(r,t,n):console.error(r,t):i?console.log(r,t,n):console.log(r,t)};function ae(e={}){return ce({level:void 0!==e.level?function(e){return"string"==typeof e?m[e]:e}(e.level):0,handler:e.handler,scope:[]})}function ce(e){const{level:t,handler:n,scope:o}=e,r=(e,r,i)=>{if(e<=t){const t=ie(r,i);n?n(e,t.message,t.context,o,se):se(e,t.message,t.context,o)}};return{error:(e,t)=>r(0,e,t),info:(e,t)=>r(1,e,t),debug:(e,t)=>r(2,e,t),throw:(e,t)=>{const r=ie(e,t);throw n?n(0,r.message,r.context,o,se):se(0,r.message,r.context,o),new Error(r.message)},scope:e=>ce({level:t,handler:n,scope:[...o,e]})}}function ue(e){return I(e)||H(e)||B(e)||!R(e)||V(e)&&e.every(ue)||K(e)&&Object.values(e).every(ue)}function le(e){return I(e)||H(e)||B(e)?e:D(e)?le(Array.from(e)):V(e)?e.map(e=>le(e)).filter(e=>void 0!==e):K(e)?Object.entries(e).reduce((e,[t,n])=>{const o=le(n);return void 0!==o&&(e[t]=o),e},{}):void 0}function fe(e){return ue(e)?e:void 0}function pe(e,t,n){return function(...o){try{return e(...o)}catch(e){if(!t)return;return t(e)}finally{n?.()}}}function de(e,t,n){return async function(...o){try{return await e(...o)}catch(e){if(!t)return;return await t(e)}finally{await(n?.())}}}async function ge(e,t){const[n,o]=(e.name||"").split(" ");if(!t||!n||!o)return{};let r,i="",s=n,a=o;const c=t=>{if(t)return(t=V(t)?t:[t]).find(t=>!t.condition||t.condition(e))};t[s]||(s="*");const u=t[s];return u&&(u[a]||(a="*"),r=c(u[a])),r||(s="*",a="*",r=c(t[s]?.[a])),r&&(i=`${s} ${a}`),{eventMapping:r,mappingKey:i}}async function me(e,t={},n={}){if(!R(e))return;const o=K(e)&&e.consent||n.consent||n.collector?.consent,r=V(t)?t:[t];for(const t of r){const r=await de(ye)(e,t,{...n,consent:o});if(R(r))return r}}async function ye(e,t,n={}){const{collector:o,consent:r}=n;return(V(t)?t:[t]).reduce(async(t,i)=>{const s=await t;if(s)return s;const a=H(i)?{key:i}:i;if(!Object.keys(a).length)return;const{condition:c,consent:u,fn:l,key:f,loop:p,map:d,set:g,validate:m,value:y}=a;if(c&&!await de(c)(e,i,o))return;if(u&&!J(u,r))return y;let b=R(y)?y:e;if(l&&(b=await de(l)(e,i,n)),f&&(b=W(e,f,y)),p){const[t,o]=p,r="this"===t?[e]:await me(e,t,n);V(r)&&(b=(await Promise.all(r.map(e=>me(e,o,n)))).filter(R))}else d?b=await Object.entries(d).reduce(async(t,[o,r])=>{const i=await t,s=await me(e,r,n);return R(s)&&(i[o]=s),i},Promise.resolve({})):g&&(b=await Promise.all(g.map(t=>ye(e,t,n))));m&&!await de(m)(b)&&(b=void 0);const v=fe(b);return R(v)?v:fe(y)},Promise.resolve(void 0))}async function be(e,t,n){t.policy&&await Promise.all(Object.entries(t.policy).map(async([t,o])=>{const r=await me(e,o,{collector:n});e=Z(e,t,r)}));const{eventMapping:o,mappingKey:r}=await ge(e,t.mapping);o?.policy&&await Promise.all(Object.entries(o.policy).map(async([t,o])=>{const r=await me(e,o,{collector:n});e=Z(e,t,r)}));let i=t.data&&await me(e,t.data,{collector:n});if(o){if(o.ignore)return{event:e,data:i,mapping:o,mappingKey:r,ignore:!0};if(o.name&&(e.name=o.name),o.data){const t=o.data&&await me(e,o.data,{collector:n});i=K(i)&&K(t)?N(i,t):t}}return{event:e,data:i,mapping:o,mappingKey:r,ignore:!1}}function ve(e,t){const n=(e,o=[])=>new Proxy(e,{get(e,r){const i=e[r],s=[...o,r];return"function"==typeof i?(...e)=>t(s,e,i):i&&"object"==typeof i?n(i,s):i}});return n(e)}function he(e,t){const n=(e,o=[])=>{if(!e||"object"!=typeof e)return e;const r=Array.isArray(e)?[]:{};for(const[i,s]of Object.entries(e)){const e=[...o,i];Array.isArray(r)?r[Number(i)]=t(s,e):r[i]=t(s,e),s&&"object"==typeof s&&"function"!=typeof s&&(Array.isArray(r)?r[Number(i)]=n(s,e):r[i]=n(s,e))}return r};return n(e)}function we(){const e=[],t=jest.fn(e=>{const t=e instanceof Error?e.message:e;throw new Error(t)}),n=jest.fn(t=>{const n=we();return e.push(n),n});return{error:jest.fn(),info:jest.fn(),debug:jest.fn(),throw:t,scope:n,scopedLoggers:e}}function je(e){const t=String(e),n=t.split("?")[1]||t;return pe(()=>{const e=new URLSearchParams(n),t={};return e.forEach((e,n)=>{const o=n.split(/[[\]]+/).filter(Boolean);let r=t;o.forEach((t,n)=>{const i=n===o.length-1;if(V(r)){const s=parseInt(t,10);i?r[s]=G(e):(r[s]=r[s]||(isNaN(parseInt(o[n+1],10))?{}:[]),r=r[s])}else K(r)&&(i?r[t]=G(e):(r[t]=r[t]||(isNaN(parseInt(o[n+1],10))?{}:[]),r=r[t]))})}),t})()}function Oe(e){if(!e)return"";const t=[],n=encodeURIComponent;function o(e,r){null!=r&&(V(r)?r.forEach((t,n)=>o(`${e}[${n}]`,t)):K(r)?Object.entries(r).forEach(([t,n])=>o(`${e}[${t}]`,n)):t.push(`${n(e)}=${n(String(r))}`))}return"object"!=typeof e?n(e):(Object.entries(e).forEach(([e,t])=>o(e,t)),t.join("&"))}function xe(e){return void 0===e||U(e,"")?e:JSON.stringify(e)}function ke(e={}){return N({"Content-Type":"application/json; charset=utf-8"},e)}function Ee(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function Se(e,t,n){return function(...o){let r;const i="post"+t,s=n["pre"+t],a=n[i];return r=s?s({fn:e},...o):e(...o),a&&(r=a({fn:e,result:r},...o)),r}}function Ae(e){return e?{userAgent:e,browser:Pe(e),browserVersion:$e(e),os:Me(e),osVersion:Te(e),deviceType:_e(e)}:{}}function Pe(e){const t=[{name:"Edge",substr:"Edg"},{name:"Chrome",substr:"Chrome"},{name:"Safari",substr:"Safari",exclude:"Chrome"},{name:"Firefox",substr:"Firefox"},{name:"IE",substr:"MSIE"},{name:"IE",substr:"Trident"}];for(const n of t)if(e.includes(n.substr)&&(!n.exclude||!e.includes(n.exclude)))return n.name}function $e(e){const t=[/Edg\/([0-9]+)/,/Chrome\/([0-9]+)/,/Version\/([0-9]+).*Safari/,/Firefox\/([0-9]+)/,/MSIE ([0-9]+)/,/rv:([0-9]+).*Trident/];for(const n of t){const t=e.match(n);if(t)return t[1]}}function Me(e){const t=[{name:"Windows",substr:"Windows NT"},{name:"macOS",substr:"Mac OS X"},{name:"Android",substr:"Android"},{name:"iOS",substr:"iPhone OS"},{name:"Linux",substr:"Linux"}];for(const n of t)if(e.includes(n.substr))return n.name}function Te(e){const t=e.match(/(?:Windows NT|Mac OS X|Android|iPhone OS) ([0-9._]+)/);return t?t[1].replace(/_/g,"."):void 0}function _e(e){let t="Desktop";return/Tablet|iPad/i.test(e)?t="Tablet":/Mobi|Android|iPhone|iPod|BlackBerry|Opera Mini|IEMobile|WPDesktop/i.test(e)&&(t="Mobile"),t}function Ce(e,t=[]){let n,o,r;U(e,{})||E("Invalid object"),U(e.name,"")?(n=e.name,[o,r]=n.split(" "),o&&r||E("Invalid event name")):U(e.entity,"")&&U(e.action,"")?(o=e.entity,r=e.action,n=`${o} ${r}`):E("Missing or invalid name, entity, or action");const i={name:n,data:{},context:{},custom:{},globals:{},user:{},nested:[],consent:{},id:"",trigger:"",entity:o,action:r,timestamp:0,timing:0,group:"",count:0,version:{source:"",tagging:0},source:{type:"",id:"",previous_id:""}};return[{"*":{"*":{name:{maxLength:255},user:{allowedKeys:["id","device","session"]},consent:{allowedValues:[!0,!1]},timestamp:{min:0},timing:{min:0},count:{min:0},version:{allowedKeys:["source","tagging"]},source:{allowedKeys:["type","id","previous_id"]}}}}].concat(t).reduce((e,t)=>["*",o].reduce((e,n)=>["*",r].reduce((e,o)=>{const r=t[n]?.[o];return r?e.concat([r]):e},e),e),[]).reduce((t,n)=>{const o=Object.keys(n).filter(e=>{const t=n[e];return!0===t?.required});return[...Object.keys(e),...o].reduce((t,o)=>{const r=n[o];let i=e[o];return r&&(i=pe(Ne,e=>{E(String(e))})(t,o,i,r)),U(i,t[o])&&(t[o]=i),t},t)},i)}function Ne(e,t,n,o){if(o.validate&&(n=pe(o.validate,e=>{E(String(e))})(n,t,e)),o.required&&void 0===n&&E("Missing required property"),U(n,""))o.maxLength&&n.length>o.maxLength&&(o.strict&&E("Value exceeds maxLength"),n=n.substring(0,o.maxLength));else if(U(n,1))U(o.min,1)&&n<o.min?(o.strict&&E("Value below min"),n=o.min):U(o.max,1)&&n>o.max&&(o.strict&&E("Value exceeds max"),n=o.max);else if(U(n,{})){if(o.schema){const e=o.schema;Object.keys(e).reduce((t,n)=>{const o=e[n];let r=t[n];return o&&(o.type&&typeof r!==o.type&&E(`Type doesn't match (${n})`),r=pe(Ne,e=>{E(String(e))})(t,n,r,o)),r},n)}for(const e of Object.keys(n))o.allowedKeys&&!o.allowedKeys.includes(e)&&(o.strict&&E("Key not allowed"),delete n[e])}return n}function De(e){return function(e){return/\breturn\b/.test(e)}(e)?e:`return ${e}`}function Ve(e){const t=De(e);return new Function("value","mapping","collector",t)}function Ie(e){const t=De(e);return new Function("value","mapping","options",t)}function Le(e){const t=De(e);return new Function("value",t)}//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i=(e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})},s={};i(s,{Collector:()=>a,Const:()=>x,Context:()=>c,Data:()=>u,Destination:()=>l,Elb:()=>f,Flow:()=>p,Hooks:()=>d,Level:()=>m,Logger:()=>g,Mapping:()=>y,On:()=>b,Request:()=>h,Schema:()=>w,Source:()=>j,Transformer:()=>v,WalkerOS:()=>O,anonymizeIP:()=>k,assign:()=>N,castToProperty:()=>fe,castValue:()=>G,clone:()=>q,createDestination:()=>X,createEvent:()=>Q,createLogger:()=>ae,createMockLogger:()=>we,debounce:()=>ne,filterValues:()=>le,getBrowser:()=>Pe,getBrowserVersion:()=>$e,getByPath:()=>W,getDeviceType:()=>_e,getEvent:()=>Y,getFlowConfig:()=>T,getGrantedConsent:()=>J,getHeaders:()=>ke,getId:()=>ee,getMappingEvent:()=>ge,getMappingValue:()=>me,getMarketingParameters:()=>te,getOS:()=>Me,getOSVersion:()=>Te,getPlatform:()=>_,isArguments:()=>D,isArray:()=>V,isBoolean:()=>I,isCommand:()=>L,isDefined:()=>R,isElementOrDocument:()=>z,isFunction:()=>F,isNumber:()=>B,isObject:()=>K,isPropertyType:()=>ue,isSameType:()=>U,isString:()=>H,mockEnv:()=>ve,packageNameToVariable:()=>$,parseUserAgent:()=>Ae,processEventMapping:()=>be,requestToData:()=>je,requestToParameter:()=>Oe,setByPath:()=>Z,throttle:()=>oe,throwError:()=>E,transformData:()=>xe,traverseEnv:()=>he,trim:()=>Ee,tryCatch:()=>pe,tryCatchAsync:()=>de,useHooks:()=>Se,validateEvent:()=>Ce,validateProperty:()=>Ne,wrapCondition:()=>Ve,wrapFn:()=>Ie,wrapValidate:()=>Le}),module.exports=(e=s,((e,i,s,a)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of o(i))r.call(e,c)||c===s||t(e,c,{get:()=>i[c],enumerable:!(a=n(i,c))||a.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a={},c={},u={},l={},f={},p={},d={},g={};i(g,{Level:()=>m});var m=(e=>(e[e.ERROR=0]="ERROR",e[e.INFO=1]="INFO",e[e.DEBUG=2]="DEBUG",e))(m||{}),y={},b={},v={},h={},w={},j={},O={},x={Utils:{Storage:{Local:"local",Session:"session",Cookie:"cookie"}}};function k(e){return/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e)?e.replace(/\.\d+$/,".0"):""}function E(e){throw new Error(String(e))}function S(...e){const t={};for(const n of e)n&&Object.assign(t,n);return t}function A(...e){const t={};for(const n of e)n&&Object.assign(t,n);return t}function P(e,t,n){if("string"==typeof e){const o=e.match(/^\$def\.([a-zA-Z_][a-zA-Z0-9_]*)$/);if(o){const e=o[1];return void 0===n[e]&&E(`Definition "${e}" not found`),P(n[e],t,n)}let r=e.replace(/\$var\.([a-zA-Z_][a-zA-Z0-9_]*)/g,(e,n)=>{if(void 0!==t[n])return String(t[n]);E(`Variable "${n}" not found`)});return r=r.replace(/\$env\.([a-zA-Z_][a-zA-Z0-9_]*)(?::([^"}\s]*))?/g,(e,t,n)=>"undefined"!=typeof process&&void 0!==process.env?.[t]?process.env[t]:void 0!==n?n:void E(`Environment variable "${t}" not found and no default provided`)),r}if(Array.isArray(e))return e.map(e=>P(e,t,n));if(null!==e&&"object"==typeof e){const o={};for(const[r,i]of Object.entries(e))o[r]=P(i,t,n);return o}return e}function $(e){const t=e.startsWith("@"),n=e.replace("@","").replace(/[/-]/g,"_").split("_").filter(e=>e.length>0).map((e,t)=>0===t?e:e.charAt(0).toUpperCase()+e.slice(1)).join("");return t?"_"+n:n}function M(e,t,n){if(t)return t;if(!e||!n)return;return n[e]?$(e):void 0}function T(e,t){const n=Object.keys(e.flows);t||(1===n.length?t=n[0]:E(`Multiple flows found (${n.join(", ")}). Please specify a flow.`));const o=e.flows[t];o||E(`Flow "${t}" not found. Available: ${n.join(", ")}`);const r=JSON.parse(JSON.stringify(o));if(r.sources)for(const[t,n]of Object.entries(r.sources)){const i=S(e.variables,o.variables,n.variables),s=A(e.definitions,o.definitions,n.definitions),a=P(n.config,i,s),c=M(n.package,n.code,r.packages),u="string"==typeof n.code||"object"==typeof n.code?n.code:void 0,l=c||u;r.sources[t]={package:n.package,config:a,env:n.env,primary:n.primary,variables:n.variables,definitions:n.definitions,next:n.next,code:l}}if(r.destinations)for(const[t,n]of Object.entries(r.destinations)){const i=S(e.variables,o.variables,n.variables),s=A(e.definitions,o.definitions,n.definitions),a=P(n.config,i,s),c=M(n.package,n.code,r.packages),u="string"==typeof n.code||"object"==typeof n.code?n.code:void 0,l=c||u;r.destinations[t]={package:n.package,config:a,env:n.env,variables:n.variables,definitions:n.definitions,before:n.before,code:l}}if(r.collector){const t=S(e.variables,o.variables),n=A(e.definitions,o.definitions),i=P(r.collector,t,n);r.collector=i}return r}function _(e){return void 0!==e.web?"web":void 0!==e.server?"server":void E("Config must have web or server key")}var C={merge:!0,shallow:!0,extend:!0};function N(e,t={},n={}){n={...C,...n};const o=Object.entries(t).reduce((t,[o,r])=>{const i=e[o];return n.merge&&Array.isArray(i)&&Array.isArray(r)?t[o]=r.reduce((e,t)=>e.includes(t)?e:[...e,t],[...i]):(n.extend||o in e)&&(t[o]=r),t},{});return n.shallow?{...e,...o}:(Object.assign(e,o),e)}function D(e){return"[object Arguments]"===Object.prototype.toString.call(e)}function V(e){return Array.isArray(e)}function I(e){return"boolean"==typeof e}function L(e){return"walker"===e}function R(e){return void 0!==e}function z(e){return e===document||e instanceof Element}function F(e){return"function"==typeof e}function B(e){return"number"==typeof e&&!Number.isNaN(e)}function K(e){return"object"==typeof e&&null!==e&&!V(e)&&"[object Object]"===Object.prototype.toString.call(e)}function U(e,t){return typeof e==typeof t}function H(e){return"string"==typeof e}function q(e,t=new WeakMap){if("object"!=typeof e||null===e)return e;if(t.has(e))return t.get(e);const n=Object.prototype.toString.call(e);if("[object Object]"===n){const n={};t.set(e,n);for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=q(e[o],t));return n}if("[object Array]"===n){const n=[];return t.set(e,n),e.forEach(e=>{n.push(q(e,t))}),n}if("[object Date]"===n)return new Date(e.getTime());if("[object RegExp]"===n){const t=e;return new RegExp(t.source,t.flags)}return e}function W(e,t="",n){const o=t.split(".");let r=e;for(let e=0;e<o.length;e++){const t=o[e];if("*"===t&&V(r)){const t=o.slice(e+1).join("."),i=[];for(const e of r){const o=W(e,t,n);i.push(o)}return i}if(r=r instanceof Object?r[t]:void 0,!r)break}return R(r)?r:n}function Z(e,t,n){if(!K(e))return e;const o=q(e),r=t.split(".");let i=o;for(let e=0;e<r.length;e++){const t=r[e];e===r.length-1?i[t]=n:(t in i&&"object"==typeof i[t]&&null!==i[t]||(i[t]={}),i=i[t])}return o}function G(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}function J(e,t={},n={}){const o={...t,...n},r={};let i=void 0===e;return Object.keys(o).forEach(t=>{o[t]&&(r[t]=!0,e&&e[t]&&(i=!0))}),!!i&&r}function X(e,t){const n={...e};return n.config=N(e.config,t,{shallow:!0,merge:!0,extend:!0}),e.config.settings&&t.settings&&(n.config.settings=N(e.config.settings,t.settings,{shallow:!0,merge:!0,extend:!0})),e.config.mapping&&t.mapping&&(n.config.mapping=N(e.config.mapping,t.mapping,{shallow:!0,merge:!0,extend:!0})),n}function Q(e={}){const t=e.timestamp||(new Date).setHours(0,13,37,0),n=e.group||"gr0up",o=e.count||1,r=N({name:"entity action",data:{string:"foo",number:1,boolean:!0,array:[0,"text",!1],not:void 0},context:{dev:["test",1]},globals:{lang:"elb"},custom:{completely:"random"},user:{id:"us3r",device:"c00k13",session:"s3ss10n"},nested:[{entity:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${t}-${n}-${o}`,trigger:"test",entity:"entity",action:"action",timestamp:t,timing:3.14,group:n,count:o,version:{source:"1.2.1",tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.name){const[t,n]=e.name.split(" ")??[];t&&n&&(r.entity=t,r.action=n)}return r}function Y(e="entity action",t={}){const n=t.timestamp||(new Date).setHours(0,13,37,0),o={data:{id:"ers",name:"Everyday Ruck Snack",color:"black",size:"l",price:420}},r={data:{id:"cc",name:"Cool Cap",size:"one size",price:42}};return Q({...{"cart view":{data:{currency:"EUR",value:2*o.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:{...o.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:o.data.price+r.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...o,context:{shopping:["checkout",0]},nested:[]},{entity:"product",...r,context:{shopping:["checkout",0]},nested:[]}],trigger:"load"},"order complete":{data:{id:"0rd3r1d",currency:"EUR",shipping:5.22,taxes:73.76,total:555},context:{shopping:["complete",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...o,context:{shopping:["complete",0]},nested:[]},{entity:"product",...r,context:{shopping:["complete",0]},nested:[]},{entity:"gift",data:{name:"Surprise"},context:{shopping:["complete",0]},nested:[]}],trigger:"load"},"page view":{data:{domain:"www.example.com",title:"walkerOS documentation",referrer:"https://www.walkeros.io/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...o,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...o,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...o.data,position:3,promo:!0},context:{shopping:["discover",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"promotion visible":{data:{name:"Setting up tracking easily",position:"hero"},context:{ab_test:["engagement",0]},globals:{pagegroup:"homepage"},trigger:"visible"},"session start":{data:{id:"s3ss10n",start:n,isNew:!0,count:1,runs:1,isStart:!0,storage:!0,referrer:"",device:"c00k13"},user:{id:"us3r",device:"c00k13",session:"s3ss10n",hash:"h4sh",address:"street number",email:"user@example.com",phone:"+49 123 456 789",userAgent:"Mozilla...",browser:"Chrome",browserVersion:"90",deviceType:"desktop",language:"de-DE",country:"DE",region:"HH",city:"Hamburg",zip:"20354",timezone:"Berlin",os:"walkerOS",osVersion:"1.0",screenSize:"1337x420",ip:"127.0.0.0",internal:!0,custom:"value"}}}[e],...t,name:e})}function ee(e=6){let t="";for(let n=36;t.length<e;)t+=(Math.random()*n|0).toString(n);return t}function te(e,t={}){const n="clickId",o={},r={utm_campaign:"campaign",utm_content:"content",utm_medium:"medium",utm_source:"source",utm_term:"term",dclid:n,fbclid:n,gclid:n,msclkid:n,ttclid:n,twclid:n,igshid:n,sclid:n};return Object.entries(N(r,t)).forEach(([t,r])=>{const i=e.searchParams.get(t);i&&(r===n&&(r=t,o[n]=t),o[r]=i)}),o}function ne(e,t=1e3,n=!1){let o,r=null,i=!1;return(...s)=>new Promise(a=>{const c=n&&!i;r&&clearTimeout(r),r=setTimeout(()=>{r=null,n&&!i||(o=e(...s),a(o))},t),c&&(i=!0,o=e(...s),a(o))})}function oe(e,t=1e3){let n=null;return function(...o){if(null===n)return n=setTimeout(()=>{n=null},t),e(...o)}}function re(e){return{message:e.message,name:e.name,stack:e.stack,cause:e.cause}}function ie(e,t){let n,o={};return e instanceof Error?(n=e.message,o.error=re(e)):n=e,void 0!==t&&(t instanceof Error?o.error=re(t):"object"==typeof t&&null!==t?(o={...o,...t},"error"in o&&o.error instanceof Error&&(o.error=re(o.error))):o.value=t),{message:n,context:o}}var se=(e,t,n,o)=>{const r=`${m[e]}${o.length>0?` [${o.join(":")}]`:""}`,i=Object.keys(n).length>0;0===e?i?console.error(r,t,n):console.error(r,t):i?console.log(r,t,n):console.log(r,t)};function ae(e={}){return ce({level:void 0!==e.level?function(e){return"string"==typeof e?m[e]:e}(e.level):0,handler:e.handler,scope:[]})}function ce(e){const{level:t,handler:n,scope:o}=e,r=(e,r,i)=>{if(e<=t){const t=ie(r,i);n?n(e,t.message,t.context,o,se):se(e,t.message,t.context,o)}};return{error:(e,t)=>r(0,e,t),info:(e,t)=>r(1,e,t),debug:(e,t)=>r(2,e,t),throw:(e,t)=>{const r=ie(e,t);throw n?n(0,r.message,r.context,o,se):se(0,r.message,r.context,o),new Error(r.message)},scope:e=>ce({level:t,handler:n,scope:[...o,e]})}}function ue(e){return I(e)||H(e)||B(e)||!R(e)||V(e)&&e.every(ue)||K(e)&&Object.values(e).every(ue)}function le(e){return I(e)||H(e)||B(e)?e:D(e)?le(Array.from(e)):V(e)?e.map(e=>le(e)).filter(e=>void 0!==e):K(e)?Object.entries(e).reduce((e,[t,n])=>{const o=le(n);return void 0!==o&&(e[t]=o),e},{}):void 0}function fe(e){return ue(e)?e:void 0}function pe(e,t,n){return function(...o){try{return e(...o)}catch(e){if(!t)return;return t(e)}finally{n?.()}}}function de(e,t,n){return async function(...o){try{return await e(...o)}catch(e){if(!t)return;return await t(e)}finally{await(n?.())}}}async function ge(e,t){const[n,o]=(e.name||"").split(" ");if(!t||!n||!o)return{};let r,i="",s=n,a=o;const c=t=>{if(t)return(t=V(t)?t:[t]).find(t=>!t.condition||t.condition(e))};t[s]||(s="*");const u=t[s];return u&&(u[a]||(a="*"),r=c(u[a])),r||(s="*",a="*",r=c(t[s]?.[a])),r&&(i=`${s} ${a}`),{eventMapping:r,mappingKey:i}}async function me(e,t={},n={}){if(!R(e))return;const o=K(e)&&e.consent||n.consent||n.collector?.consent,r=V(t)?t:[t];for(const t of r){const r=await de(ye)(e,t,{...n,consent:o});if(R(r))return r}}async function ye(e,t,n={}){const{collector:o,consent:r}=n;return(V(t)?t:[t]).reduce(async(t,i)=>{const s=await t;if(s)return s;const a=H(i)?{key:i}:i;if(!Object.keys(a).length)return;const{condition:c,consent:u,fn:l,key:f,loop:p,map:d,set:g,validate:m,value:y}=a;if(c&&!await de(c)(e,i,o))return;if(u&&!J(u,r))return y;let b=R(y)?y:e;if(l&&(b=await de(l)(e,i,n)),f&&(b=W(e,f,y)),p){const[t,o]=p,r="this"===t?[e]:await me(e,t,n);V(r)&&(b=(await Promise.all(r.map(e=>me(e,o,n)))).filter(R))}else d?b=await Object.entries(d).reduce(async(t,[o,r])=>{const i=await t,s=await me(e,r,n);return R(s)&&(i[o]=s),i},Promise.resolve({})):g&&(b=await Promise.all(g.map(t=>ye(e,t,n))));m&&!await de(m)(b)&&(b=void 0);const v=fe(b);return R(v)?v:fe(y)},Promise.resolve(void 0))}async function be(e,t,n){t.policy&&await Promise.all(Object.entries(t.policy).map(async([t,o])=>{const r=await me(e,o,{collector:n});e=Z(e,t,r)}));const{eventMapping:o,mappingKey:r}=await ge(e,t.mapping);o?.policy&&await Promise.all(Object.entries(o.policy).map(async([t,o])=>{const r=await me(e,o,{collector:n});e=Z(e,t,r)}));let i=t.data&&await me(e,t.data,{collector:n});if(o){if(o.ignore)return{event:e,data:i,mapping:o,mappingKey:r,ignore:!0};if(o.name&&(e.name=o.name),o.data){const t=o.data&&await me(e,o.data,{collector:n});i=K(i)&&K(t)?N(i,t):t}}return{event:e,data:i,mapping:o,mappingKey:r,ignore:!1}}function ve(e,t){const n=(e,o=[])=>new Proxy(e,{get(e,r){const i=e[r],s=[...o,r];return"function"==typeof i?(...e)=>t(s,e,i):i&&"object"==typeof i?n(i,s):i}});return n(e)}function he(e,t){const n=(e,o=[])=>{if(!e||"object"!=typeof e)return e;const r=Array.isArray(e)?[]:{};for(const[i,s]of Object.entries(e)){const e=[...o,i];Array.isArray(r)?r[Number(i)]=t(s,e):r[i]=t(s,e),s&&"object"==typeof s&&"function"!=typeof s&&(Array.isArray(r)?r[Number(i)]=n(s,e):r[i]=n(s,e))}return r};return n(e)}function we(){const e=[],t=jest.fn(e=>{const t=e instanceof Error?e.message:e;throw new Error(t)}),n=jest.fn(t=>{const n=we();return e.push(n),n});return{error:jest.fn(),info:jest.fn(),debug:jest.fn(),throw:t,scope:n,scopedLoggers:e}}function je(e){const t=String(e),n=t.split("?")[1]||t;return pe(()=>{const e=new URLSearchParams(n),t={};return e.forEach((e,n)=>{const o=n.split(/[[\]]+/).filter(Boolean);let r=t;o.forEach((t,n)=>{const i=n===o.length-1;if(V(r)){const s=parseInt(t,10);i?r[s]=G(e):(r[s]=r[s]||(isNaN(parseInt(o[n+1],10))?{}:[]),r=r[s])}else K(r)&&(i?r[t]=G(e):(r[t]=r[t]||(isNaN(parseInt(o[n+1],10))?{}:[]),r=r[t]))})}),t})()}function Oe(e){if(!e)return"";const t=[],n=encodeURIComponent;function o(e,r){null!=r&&(V(r)?r.forEach((t,n)=>o(`${e}[${n}]`,t)):K(r)?Object.entries(r).forEach(([t,n])=>o(`${e}[${t}]`,n)):t.push(`${n(e)}=${n(String(r))}`))}return"object"!=typeof e?n(e):(Object.entries(e).forEach(([e,t])=>o(e,t)),t.join("&"))}function xe(e){return void 0===e||U(e,"")?e:JSON.stringify(e)}function ke(e={}){return N({"Content-Type":"application/json; charset=utf-8"},e)}function Ee(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function Se(e,t,n){return function(...o){let r;const i="post"+t,s=n["pre"+t],a=n[i];return r=s?s({fn:e},...o):e(...o),a&&(r=a({fn:e,result:r},...o)),r}}function Ae(e){return e?{userAgent:e,browser:Pe(e),browserVersion:$e(e),os:Me(e),osVersion:Te(e),deviceType:_e(e)}:{}}function Pe(e){const t=[{name:"Edge",substr:"Edg"},{name:"Chrome",substr:"Chrome"},{name:"Safari",substr:"Safari",exclude:"Chrome"},{name:"Firefox",substr:"Firefox"},{name:"IE",substr:"MSIE"},{name:"IE",substr:"Trident"}];for(const n of t)if(e.includes(n.substr)&&(!n.exclude||!e.includes(n.exclude)))return n.name}function $e(e){const t=[/Edg\/([0-9]+)/,/Chrome\/([0-9]+)/,/Version\/([0-9]+).*Safari/,/Firefox\/([0-9]+)/,/MSIE ([0-9]+)/,/rv:([0-9]+).*Trident/];for(const n of t){const t=e.match(n);if(t)return t[1]}}function Me(e){const t=[{name:"Windows",substr:"Windows NT"},{name:"macOS",substr:"Mac OS X"},{name:"Android",substr:"Android"},{name:"iOS",substr:"iPhone OS"},{name:"Linux",substr:"Linux"}];for(const n of t)if(e.includes(n.substr))return n.name}function Te(e){const t=e.match(/(?:Windows NT|Mac OS X|Android|iPhone OS) ([0-9._]+)/);return t?t[1].replace(/_/g,"."):void 0}function _e(e){let t="Desktop";return/Tablet|iPad/i.test(e)?t="Tablet":/Mobi|Android|iPhone|iPod|BlackBerry|Opera Mini|IEMobile|WPDesktop/i.test(e)&&(t="Mobile"),t}function Ce(e,t=[]){let n,o,r;U(e,{})||E("Invalid object"),U(e.name,"")?(n=e.name,[o,r]=n.split(" "),o&&r||E("Invalid event name")):U(e.entity,"")&&U(e.action,"")?(o=e.entity,r=e.action,n=`${o} ${r}`):E("Missing or invalid name, entity, or action");const i={name:n,data:{},context:{},custom:{},globals:{},user:{},nested:[],consent:{},id:"",trigger:"",entity:o,action:r,timestamp:0,timing:0,group:"",count:0,version:{source:"",tagging:0},source:{type:"",id:"",previous_id:""}};return[{"*":{"*":{name:{maxLength:255},user:{allowedKeys:["id","device","session"]},consent:{allowedValues:[!0,!1]},timestamp:{min:0},timing:{min:0},count:{min:0},version:{allowedKeys:["source","tagging"]},source:{allowedKeys:["type","id","previous_id"]}}}}].concat(t).reduce((e,t)=>["*",o].reduce((e,n)=>["*",r].reduce((e,o)=>{const r=t[n]?.[o];return r?e.concat([r]):e},e),e),[]).reduce((t,n)=>{const o=Object.keys(n).filter(e=>{const t=n[e];return!0===t?.required});return[...Object.keys(e),...o].reduce((t,o)=>{const r=n[o];let i=e[o];return r&&(i=pe(Ne,e=>{E(String(e))})(t,o,i,r)),U(i,t[o])&&(t[o]=i),t},t)},i)}function Ne(e,t,n,o){if(o.validate&&(n=pe(o.validate,e=>{E(String(e))})(n,t,e)),o.required&&void 0===n&&E("Missing required property"),U(n,""))o.maxLength&&n.length>o.maxLength&&(o.strict&&E("Value exceeds maxLength"),n=n.substring(0,o.maxLength));else if(U(n,1))U(o.min,1)&&n<o.min?(o.strict&&E("Value below min"),n=o.min):U(o.max,1)&&n>o.max&&(o.strict&&E("Value exceeds max"),n=o.max);else if(U(n,{})){if(o.schema){const e=o.schema;Object.keys(e).reduce((t,n)=>{const o=e[n];let r=t[n];return o&&(o.type&&typeof r!==o.type&&E(`Type doesn't match (${n})`),r=pe(Ne,e=>{E(String(e))})(t,n,r,o)),r},n)}for(const e of Object.keys(n))o.allowedKeys&&!o.allowedKeys.includes(e)&&(o.strict&&E("Key not allowed"),delete n[e])}return n}function De(e){return function(e){return/\breturn\b/.test(e)}(e)?e:`return ${e}`}function Ve(e){const t=De(e);return new Function("value","mapping","collector",t)}function Ie(e){const t=De(e);return new Function("value","mapping","options",t)}function Le(e){const t=De(e);return new Function("value",t)}//# sourceMappingURL=index.js.map
|