@walkeros/core 1.2.2 → 1.4.0-next-1771252576264

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/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.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
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:()=>O,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:()=>k,anonymizeIP:()=>E,assign:()=>D,branch:()=>x,castToProperty:()=>pe,castValue:()=>J,clone:()=>W,createDestination:()=>Q,createEvent:()=>Y,createLogger:()=>ce,createMockLogger:()=>je,debounce:()=>oe,fetchPackageSchema:()=>Be,filterValues:()=>fe,getBrowser:()=>Pe,getBrowserVersion:()=>Te,getByPath:()=>Z,getDeviceType:()=>Ce,getEvent:()=>ee,getFlowConfig:()=>M,getGrantedConsent:()=>X,getHeaders:()=>Ee,getId:()=>te,getMappingEvent:()=>me,getMappingValue:()=>ye,getMarketingParameters:()=>ne,getOS:()=>_e,getOSVersion:()=>Me,getPlatform:()=>C,isArguments:()=>V,isArray:()=>I,isBoolean:()=>L,isCommand:()=>R,isDefined:()=>z,isElementOrDocument:()=>F,isFunction:()=>B,isNumber:()=>H,isObject:()=>K,isPropertyType:()=>le,isSameType:()=>U,isString:()=>q,mockEnv:()=>he,packageNameToVariable:()=>T,parseUserAgent:()=>Ae,processEventMapping:()=>ve,requestToData:()=>ke,requestToParameter:()=>Oe,setByPath:()=>G,throttle:()=>re,throwError:()=>S,transformData:()=>xe,traverseEnv:()=>we,trim:()=>Se,tryCatch:()=>de,tryCatchAsync:()=>ge,useHooks:()=>$e,validateEvent:()=>Ne,validateProperty:()=>De,wrapCondition:()=>Ie,wrapFn:()=>Le,wrapValidate:()=>Re}),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={},k={},O={Utils:{Storage:{Local:"local",Session:"session",Cookie:"cookie"}}};function x(e,t){return{__branch:!0,event:e,next:t}}function E(e){return/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e)?e.replace(/\.\d+$/,".0"):""}function S(e){throw new Error(String(e))}function $(...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]&&S(`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]);S(`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 S(`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 T(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 _(e,t,n){if(t)return t;if(!e||!n)return;return n[e]?T(e):void 0}function M(e,t){const n=Object.keys(e.flows);t||(1===n.length?t=n[0]:S(`Multiple flows found (${n.join(", ")}). Please specify a flow.`));const o=e.flows[t];o||S(`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=$(e.variables,o.variables,n.variables),s=A(e.definitions,o.definitions,n.definitions),a=P(n.config,i,s),c=_(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=$(e.variables,o.variables,n.variables),s=A(e.definitions,o.definitions,n.definitions),a=P(n.config,i,s),c=_(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=$(e.variables,o.variables),n=A(e.definitions,o.definitions),i=P(r.collector,t,n);r.collector=i}return r}function C(e){return void 0!==e.web?"web":void 0!==e.server?"server":void S("Config must have web or server key")}var N={merge:!0,shallow:!0,extend:!0};function D(e,t={},n={}){n={...N,...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 V(e){return"[object Arguments]"===Object.prototype.toString.call(e)}function I(e){return Array.isArray(e)}function L(e){return"boolean"==typeof e}function R(e){return"walker"===e}function z(e){return void 0!==e}function F(e){return e===document||e instanceof Element}function B(e){return"function"==typeof e}function H(e){return"number"==typeof e&&!Number.isNaN(e)}function K(e){return"object"==typeof e&&null!==e&&!I(e)&&"[object Object]"===Object.prototype.toString.call(e)}function U(e,t){return typeof e==typeof t}function q(e){return"string"==typeof e}function W(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]=W(e[o],t));return n}if("[object Array]"===n){const n=[];return t.set(e,n),e.forEach(e=>{n.push(W(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 Z(e,t="",n){const o=t.split(".");let r=e;for(let e=0;e<o.length;e++){const t=o[e];if("*"===t&&I(r)){const t=o.slice(e+1).join("."),i=[];for(const e of r){const o=Z(e,t,n);i.push(o)}return i}if(r=r instanceof Object?r[t]:void 0,!r)break}return z(r)?r:n}function G(e,t,n){if(!K(e))return e;const o=W(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 J(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}function X(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 Q(e,t){const n={...e};return n.config=D(e.config,t,{shallow:!0,merge:!0,extend:!0}),e.config.settings&&t.settings&&(n.config.settings=D(e.config.settings,t.settings,{shallow:!0,merge:!0,extend:!0})),e.config.mapping&&t.mapping&&(n.config.mapping=D(e.config.mapping,t.mapping,{shallow:!0,merge:!0,extend:!0})),n}function Y(e={}){const t=e.timestamp||(new Date).setHours(0,13,37,0),n=e.group||"gr0up",o=e.count||1,r=D({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.3.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 ee(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 Y({...{"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 te(e=6){let t="";for(let n=36;t.length<e;)t+=(Math.random()*n|0).toString(n);return t}function ne(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(D(r,t)).forEach(([t,r])=>{const i=e.searchParams.get(t);i&&(r===n&&(r=t,o[n]=t),o[r]=i)}),o}function oe(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 re(e,t=1e3){let n=null;return function(...o){if(null===n)return n=setTimeout(()=>{n=null},t),e(...o)}}function ie(e){return{message:e.message,name:e.name,stack:e.stack,cause:e.cause}}function se(e,t){let n,o={};return e instanceof Error?(n=e.message,o.error=ie(e)):n=e,void 0!==t&&(t instanceof Error?o.error=ie(t):"object"==typeof t&&null!==t?(o={...o,...t},"error"in o&&o.error instanceof Error&&(o.error=ie(o.error))):o.value=t),{message:n,context:o}}var ae=(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 ce(e={}){return ue({level:void 0!==e.level?function(e){return"string"==typeof e?m[e]:e}(e.level):0,handler:e.handler,scope:[]})}function ue(e){const{level:t,handler:n,scope:o}=e,r=(e,r,i)=>{if(e<=t){const t=se(r,i);n?n(e,t.message,t.context,o,ae):ae(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=se(e,t);throw n?n(0,r.message,r.context,o,ae):ae(0,r.message,r.context,o),new Error(r.message)},scope:e=>ue({level:t,handler:n,scope:[...o,e]})}}function le(e){return L(e)||q(e)||H(e)||!z(e)||I(e)&&e.every(le)||K(e)&&Object.values(e).every(le)}function fe(e){return L(e)||q(e)||H(e)?e:V(e)?fe(Array.from(e)):I(e)?e.map(e=>fe(e)).filter(e=>void 0!==e):K(e)?Object.entries(e).reduce((e,[t,n])=>{const o=fe(n);return void 0!==o&&(e[t]=o),e},{}):void 0}function pe(e){return le(e)?e:void 0}function de(e,t,n){return function(...o){try{return e(...o)}catch(e){if(!t)return;return t(e)}finally{n?.()}}}function ge(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 me(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=I(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 ye(e,t={},n={}){if(!z(e))return;const o=K(e)&&e.consent||n.consent||n.collector?.consent,r=I(t)?t:[t];for(const t of r){const r=await ge(be)(e,t,{...n,consent:o});if(z(r))return r}}async function be(e,t,n={}){const{collector:o,consent:r}=n;return(I(t)?t:[t]).reduce(async(t,i)=>{const s=await t;if(s)return s;const a=q(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 ge(c)(e,i,o))return;if(u&&!X(u,r))return y;let b=z(y)?y:e;if(l&&(b=await ge(l)(e,i,n)),f&&(b=Z(e,f,y)),p){const[t,o]=p,r="this"===t?[e]:await ye(e,t,n);I(r)&&(b=(await Promise.all(r.map(e=>ye(e,o,n)))).filter(z))}else d?b=await Object.entries(d).reduce(async(t,[o,r])=>{const i=await t,s=await ye(e,r,n);return z(s)&&(i[o]=s),i},Promise.resolve({})):g&&(b=await Promise.all(g.map(t=>be(e,t,n))));m&&!await ge(m)(b)&&(b=void 0);const v=pe(b);return z(v)?v:pe(y)},Promise.resolve(void 0))}async function ve(e,t,n){t.policy&&await Promise.all(Object.entries(t.policy).map(async([t,o])=>{const r=await ye(e,o,{collector:n});e=G(e,t,r)}));const{eventMapping:o,mappingKey:r}=await me(e,t.mapping);o?.policy&&await Promise.all(Object.entries(o.policy).map(async([t,o])=>{const r=await ye(e,o,{collector:n});e=G(e,t,r)}));let i=t.data&&await ye(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 ye(e,o.data,{collector:n});i=K(i)&&K(t)?D(i,t):t}}return{event:e,data:i,mapping:o,mappingKey:r,ignore:!1}}function he(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 we(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 je(){const e=[],t=jest.fn(e=>{const t=e instanceof Error?e.message:e;throw new Error(t)}),n=jest.fn(t=>{const n=je();return e.push(n),n});return{error:jest.fn(),info:jest.fn(),debug:jest.fn(),throw:t,scope:n,scopedLoggers:e}}function ke(e){const t=String(e),n=t.split("?")[1]||t;return de(()=>{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(I(r)){const s=parseInt(t,10);i?r[s]=J(e):(r[s]=r[s]||(isNaN(parseInt(o[n+1],10))?{}:[]),r=r[s])}else K(r)&&(i?r[t]=J(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&&(I(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 Ee(e={}){return D({"Content-Type":"application/json; charset=utf-8"},e)}function Se(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function $e(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:Te(e),os:_e(e),osVersion:Me(e),deviceType:Ce(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 Te(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 _e(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 Me(e){const t=e.match(/(?:Windows NT|Mac OS X|Android|iPhone OS) ([0-9._]+)/);return t?t[1].replace(/_/g,"."):void 0}function Ce(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 Ne(e,t=[]){let n,o,r;U(e,{})||S("Invalid object"),U(e.name,"")?(n=e.name,[o,r]=n.split(" "),o&&r||S("Invalid event name")):U(e.entity,"")&&U(e.action,"")?(o=e.entity,r=e.action,n=`${o} ${r}`):S("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=de(De,e=>{S(String(e))})(t,o,i,r)),U(i,t[o])&&(t[o]=i),t},t)},i)}function De(e,t,n,o){if(o.validate&&(n=de(o.validate,e=>{S(String(e))})(n,t,e)),o.required&&void 0===n&&S("Missing required property"),U(n,""))o.maxLength&&n.length>o.maxLength&&(o.strict&&S("Value exceeds maxLength"),n=n.substring(0,o.maxLength));else if(U(n,1))U(o.min,1)&&n<o.min?(o.strict&&S("Value below min"),n=o.min):U(o.max,1)&&n>o.max&&(o.strict&&S("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&&S(`Type doesn't match (${n})`),r=de(De,e=>{S(String(e))})(t,n,r,o)),r},n)}for(const e of Object.keys(n))o.allowedKeys&&!o.allowedKeys.includes(e)&&(o.strict&&S("Key not allowed"),delete n[e])}return n}function Ve(e){return function(e){return/\breturn\b/.test(e)}(e)?e:`return ${e}`}function Ie(e){const t=Ve(e);return new Function("value","mapping","collector",t)}function Le(e){const t=Ve(e);return new Function("value","mapping","options",t)}function Re(e){const t=Ve(e);return new Function("value",t)}var ze="https://cdn.jsdelivr.net/npm",Fe="dist/walkerOS.json";async function Be(e,t){const n=t?.version||"latest",o=`${ze}/${e}@${n}`,r=new AbortController,i=setTimeout(()=>r.abort(),t?.timeout||1e4);try{const t=await fetch(`${o}/package.json`,{signal:r.signal});if(!t.ok)throw new Error(`Package "${e}" not found on npm (HTTP ${t.status})`);const i=await t.json(),s=await fetch(`${o}/${Fe}`,{signal:r.signal});if(!s.ok)throw new Error(`walkerOS.json not found at ${Fe} (HTTP ${s.status}). This package may not support the walkerOS.json convention yet.`);const a=await s.json(),c=a.$meta||{};return{packageName:e,version:i.version||n,type:c.type,platform:c.platform,schemas:a.schemas||{},examples:a.examples||{}}}finally{clearTimeout(i)}}//# sourceMappingURL=index.js.map