@walkeros/core 2.0.0 → 2.1.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/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:()=>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:"2.0.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
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:()=>c,Const:()=>$,Context:()=>a,Data:()=>u,Destination:()=>f,ENV_MARKER_PREFIX:()=>M,Elb:()=>l,Flow:()=>p,Hooks:()=>g,Level:()=>m,Lifecycle:()=>j,Logger:()=>d,Mapping:()=>y,On:()=>b,Request:()=>v,Simulation:()=>O,Source:()=>w,Transformer:()=>h,WalkerOS:()=>k,anonymizeIP:()=>S,assign:()=>B,branch:()=>E,castToProperty:()=>je,castValue:()=>ie,clone:()=>ne,createDestination:()=>ce,createEvent:()=>ae,createLogger:()=>be,createMockLogger:()=>Te,createRespond:()=>Ye,debounce:()=>pe,fetchPackageMeta:()=>Ge,fetchPackageSchema:()=>qe,filterValues:()=>we,getBrowser:()=>Ie,getBrowserVersion:()=>Ve,getByPath:()=>oe,getDeviceType:()=>Le,getEvent:()=>ue,getFlowConfig:()=>I,getGrantedConsent:()=>se,getHeaders:()=>Me,getId:()=>fe,getMappingEvent:()=>$e,getMappingValue:()=>Ee,getMarketingParameters:()=>le,getOS:()=>ze,getOSVersion:()=>Fe,getPlatform:()=>L,isArguments:()=>U,isArray:()=>J,isBoolean:()=>K,isCommand:()=>Z,isDefined:()=>q,isElementOrDocument:()=>G,isFunction:()=>X,isNumber:()=>Q,isObject:()=>Y,isPropertyType:()=>ve,isSameType:()=>ee,isString:()=>te,mcpError:()=>Qe,mcpResult:()=>Xe,mergeContractSchemas:()=>x,mockEnv:()=>Ae,packageNameToVariable:()=>D,parseUserAgent:()=>He,processEventMapping:()=>xe,requestToData:()=>Ne,requestToParameter:()=>_e,resolveContract:()=>A,setByPath:()=>re,throttle:()=>ge,throwError:()=>N,transformData:()=>Ce,traverseEnv:()=>Pe,trim:()=>Re,tryCatch:()=>ke,tryCatchAsync:()=>Oe,useHooks:()=>De,wrapCondition:()=>Be,wrapFn:()=>Ue,wrapValidate:()=>Je}),module.exports=(e=s,((e,i,s,c)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let a of o(i))r.call(e,a)||a===s||t(e,a,{get:()=>i[a],enumerable:!(c=n(i,a))||c.enumerable});return e})(t({},"__esModule",{value:!0}),e));var c={},a={},u={},f={},l={},p={},g={},d={};i(d,{Level:()=>m});var m=(e=>(e[e.ERROR=0]="ERROR",e[e.WARN=1]="WARN",e[e.INFO=2]="INFO",e[e.DEBUG=3]="DEBUG",e))(m||{}),y={},b={},h={},v={},w={},j={},k={},O={},$={Utils:{Storage:{Local:"local",Session:"session",Cookie:"cookie"}}};function E(e,t){return{__branch:!0,event:e,next:t}}function S(e){return/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e)?e.replace(/\.\d+$/,".0"):""}function x(e,t){const n={...e};for(const o of Object.keys(t)){const r=e[o],i=t[o];"required"===o&&Array.isArray(r)&&Array.isArray(i)?n[o]=[...new Set([...r,...i])]:T(r)&&T(i)?n[o]=x(r,i):n[o]=i}return n}function A(e,t,n,o){let r={};for(const i of[e,o]){if(!i)continue;const e=[P(i,"*","*"),P(i,"*",n),P(i,t,"*"),P(i,t,n)];for(const t of e)t&&(r=x(r,t))}return r}function P(e,t,n){const o=e[t];if(!o||"object"!=typeof o)return;const r=o[n];return r&&"object"==typeof r?r:void 0}function T(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function N(e){throw new Error(String(e))}function _(...e){const t={};for(const n of e)n&&Object.assign(t,n);return t}function C(...e){const t={};for(const n of e)n&&Object.assign(t,n);return t}var M="__WALKEROS_ENV:";function R(e,t,n,o){if("string"==typeof e){const r=e.match(/^\$def\.([a-zA-Z_][a-zA-Z0-9_]*)$/);if(r){const e=r[1];return void 0===n[e]&&N(`Definition "${e}" not found`),R(n[e],t,n,o)}let i=e.replace(/\$var\.([a-zA-Z_][a-zA-Z0-9_]*)/g,(e,n)=>{if(void 0!==t[n])return String(t[n]);N(`Variable "${n}" not found`)});return i=i.replace(/\$env\.([a-zA-Z_][a-zA-Z0-9_]*)(?::([^"}\s]*))?/g,(e,t,n)=>o?.deferred?void 0!==n?`${M}${t}:${n}`:`${M}${t}`:"undefined"!=typeof process&&void 0!==process.env?.[t]?process.env[t]:void 0!==n?n:void N(`Environment variable "${t}" not found and no default provided`)),i}if(Array.isArray(e))return e.map(e=>R(e,t,n,o));if(null!==e&&"object"==typeof e){const r={};for(const[i,s]of Object.entries(e))r[i]=R(s,t,n,o);return r}return e}function D(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 H(e,t,n){if(t)return t;if(!e||!n)return;return n[e]?D(e):void 0}function I(e,t,n){const o=Object.keys(e.flows);t||(1===o.length?t=o[0]:N(`Multiple flows found (${o.join(", ")}). Please specify a flow.`));const r=e.flows[t];r||N(`Flow "${t}" not found. Available: ${o.join(", ")}`);const i=JSON.parse(JSON.stringify(r));if(i.sources)for(const[t,o]of Object.entries(i.sources)){const s=_(e.variables,r.variables,o.variables),c=C(e.definitions,r.definitions,o.definitions),a=R(o.config,s,c,n),u=H(o.package,o.code,i.packages),f="string"==typeof o.code||"object"==typeof o.code?o.code:void 0,l=u||f;i.sources[t]={package:o.package,config:a,env:o.env,primary:o.primary,variables:o.variables,definitions:o.definitions,next:o.next,code:l}}if(i.destinations)for(const[t,o]of Object.entries(i.destinations)){const s=_(e.variables,r.variables,o.variables),c=C(e.definitions,r.definitions,o.definitions),a=R(o.config,s,c,n),u=H(o.package,o.code,i.packages),f="string"==typeof o.code||"object"==typeof o.code?o.code:void 0,l=u||f;i.destinations[t]={package:o.package,config:a,env:o.env,variables:o.variables,definitions:o.definitions,before:o.before,code:l}}if(i.collector){const t=_(e.variables,r.variables),o=C(e.definitions,r.definitions),s=R(i.collector,t,o,n);i.collector=s}const s=e.contract,c=r.contract;if(s||c){const e=function(...e){const t=new Set;for(const n of e)if(n)for(const e of Object.keys(n)){if(e.startsWith("$"))continue;const o=n[e];if(o&&"object"==typeof o)for(const n of Object.keys(o))"*"!==n&&t.add(`${e}\0${n}`)}const n=new Set,o=new Set;for(const t of e)if(t)for(const e of Object.keys(t)){if(e.startsWith("$")||"*"===e)continue;n.add(e);const r=t[e];if(r&&"object"==typeof r)for(const e of Object.keys(r))"*"!==e&&o.add(e)}for(const e of n)for(const n of o)t.add(`${e}\0${n}`);return[...t].map(e=>e.split("\0"))}(s,c),t={};for(const[n,o]of e){const e=A(s||{},n,o,c);Object.keys(e).length>0&&(t[n]||(t[n]={}),t[n][o]={schema:z(e)})}if(i.transformers)for(const[,e]of Object.entries(i.transformers))F(e.config,t);const n=s?.$tagging??c?.$tagging;if("number"==typeof n){const e=i.collector||{};void 0===e.tagging&&(e.tagging=n),i.collector=e}}return i}var V=new Set(["description","examples","title","$comment"]);function z(e){const t={};for(const[n,o]of Object.entries(e))V.has(n)||(null===o||"object"!=typeof o||Array.isArray(o)?t[n]=o:t[n]=z(o));return t}function F(e,t){if(!e||"object"!=typeof e)return;const n=e;for(const e of Object.keys(n))"$contract"===n[e]?n[e]=t:"object"==typeof n[e]&&null!==n[e]&&F(n[e],t)}function L(e){return void 0!==e.web?"web":void 0!==e.server?"server":void N("Config must have web or server key")}var W={merge:!0,shallow:!0,extend:!0};function B(e,t={},n={}){n={...W,...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 U(e){return"[object Arguments]"===Object.prototype.toString.call(e)}function J(e){return Array.isArray(e)}function K(e){return"boolean"==typeof e}function Z(e){return"walker"===e}function q(e){return void 0!==e}function G(e){return e===document||e instanceof Element}function X(e){return"function"==typeof e}function Q(e){return"number"==typeof e&&!Number.isNaN(e)}function Y(e){return"object"==typeof e&&null!==e&&!J(e)&&"[object Object]"===Object.prototype.toString.call(e)}function ee(e,t){return typeof e==typeof t}function te(e){return"string"==typeof e}function ne(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]=ne(e[o],t));return n}if("[object Array]"===n){const n=[];return t.set(e,n),e.forEach(e=>{n.push(ne(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 oe(e,t="",n){const o=t.split(".");let r=e;for(let e=0;e<o.length;e++){const t=o[e];if("*"===t&&J(r)){const t=o.slice(e+1).join("."),i=[];for(const e of r){const o=oe(e,t,n);i.push(o)}return i}if(r=r instanceof Object?r[t]:void 0,!r)break}return q(r)?r:n}function re(e,t,n){if(!Y(e))return e;const o=ne(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 ie(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}function se(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 ce(e,t){const n={...e};return n.config=B(e.config,t,{shallow:!0,merge:!0,extend:!0}),e.config.settings&&t.settings&&(n.config.settings=B(e.config.settings,t.settings,{shallow:!0,merge:!0,extend:!0})),e.config.mapping&&t.mapping&&(n.config.mapping=B(e.config.mapping,t.mapping,{shallow:!0,merge:!0,extend:!0})),n}function ae(e={}){const t=e.timestamp||(new Date).setHours(0,13,37,0),n=e.group||"gr0up",o=e.count||1,r=B({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:"2.0.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 ue(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 ae({...{"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 fe(e=6){let t="";for(let n=36;t.length<e;)t+=(Math.random()*n|0).toString(n);return t}function le(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(B(r,t)).forEach(([t,r])=>{const i=e.searchParams.get(t);i&&(r===n&&(r=t,o[n]=t),o[r]=i)}),o}function pe(e,t=1e3,n=!1){let o,r=null,i=!1;return(...s)=>new Promise(c=>{const a=n&&!i;r&&clearTimeout(r),r=setTimeout(()=>{r=null,n&&!i||(o=e(...s),c(o))},t),a&&(i=!0,o=e(...s),c(o))})}function ge(e,t=1e3){let n=null;return function(...o){if(null===n)return n=setTimeout(()=>{n=null},t),e(...o)}}function de(e){return{message:e.message,name:e.name,stack:e.stack,cause:e.cause}}function me(e,t){let n,o={};return e instanceof Error?(n=e.message,o.error=de(e)):n=e,void 0!==t&&(t instanceof Error?o.error=de(t):"object"==typeof t&&null!==t?(o={...o,...t},"error"in o&&o.error instanceof Error&&(o.error=de(o.error))):o.value=t),{message:n,context:o}}var ye=(e,t,n,o)=>{const r=`${m[e]}${o.length>0?` [${o.join(":")}]`:""}`,i=Object.keys(n).length>0,s=0===e?console.error:1===e?console.warn:console.log;i?s(r,t,n):s(r,t)};function be(e={}){return he({level:void 0!==e.level?function(e){return"string"==typeof e?m[e]:e}(e.level):0,handler:e.handler,jsonHandler:e.jsonHandler,scope:[]})}function he(e){const{level:t,handler:n,jsonHandler:o,scope:r}=e,i=(e,o,i)=>{if(e<=t){const t=me(o,i);n?n(e,t.message,t.context,r,ye):ye(e,t.message,t.context,r)}};return{error:(e,t)=>i(0,e,t),warn:(e,t)=>i(1,e,t),info:(e,t)=>i(2,e,t),debug:(e,t)=>i(3,e,t),throw:(e,t)=>{const o=me(e,t);throw n?n(0,o.message,o.context,r,ye):ye(0,o.message,o.context,r),new Error(o.message)},json:e=>{o?o(e):console.log(JSON.stringify(e,null,2))},scope:e=>he({level:t,handler:n,jsonHandler:o,scope:[...r,e]})}}function ve(e){return K(e)||te(e)||Q(e)||!q(e)||J(e)&&e.every(ve)||Y(e)&&Object.values(e).every(ve)}function we(e){return K(e)||te(e)||Q(e)?e:U(e)?we(Array.from(e)):J(e)?e.map(e=>we(e)).filter(e=>void 0!==e):Y(e)?Object.entries(e).reduce((e,[t,n])=>{const o=we(n);return void 0!==o&&(e[t]=o),e},{}):void 0}function je(e){return ve(e)?e:void 0}function ke(e,t,n){return function(...o){try{return e(...o)}catch(e){if(!t)return;return t(e)}finally{n?.()}}}function Oe(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 $e(e,t){const[n,o]=(e.name||"").split(" ");if(!t||!n||!o)return{};let r,i="",s=n,c=o;const a=t=>{if(t)return(t=J(t)?t:[t]).find(t=>!t.condition||t.condition(e))};t[s]||(s="*");const u=t[s];return u&&(u[c]||(c="*"),r=a(u[c])),r||(s="*",c="*",r=a(t[s]?.[c])),r&&(i=`${s} ${c}`),{eventMapping:r,mappingKey:i}}async function Ee(e,t={},n={}){if(!q(e))return;const o=Y(e)&&e.consent||n.consent||n.collector?.consent,r=J(t)?t:[t];for(const t of r){const r=await Oe(Se)(e,t,{...n,consent:o});if(q(r))return r}}async function Se(e,t,n={}){const{collector:o,consent:r}=n;return(J(t)?t:[t]).reduce(async(t,i)=>{const s=await t;if(s)return s;const c=te(i)?{key:i}:i;if(!Object.keys(c).length)return;const{condition:a,consent:u,fn:f,key:l,loop:p,map:g,set:d,validate:m,value:y}=c;if(a&&!await Oe(a)(e,i,o))return;if(u&&!se(u,r))return y;let b=q(y)?y:e;if(f&&(b=await Oe(f)(e,i,n)),l&&(b=oe(e,l,y)),p){const[t,o]=p,r="this"===t?[e]:await Ee(e,t,n);J(r)&&(b=(await Promise.all(r.map(e=>Ee(e,o,n)))).filter(q))}else g?b=await Object.entries(g).reduce(async(t,[o,r])=>{const i=await t,s=await Ee(e,r,n);return q(s)&&(i[o]=s),i},Promise.resolve({})):d&&(b=await Promise.all(d.map(t=>Se(e,t,n))));m&&!await Oe(m)(b)&&(b=void 0);const h=je(b);return q(h)?h:je(y)},Promise.resolve(void 0))}async function xe(e,t,n){t.policy&&await Promise.all(Object.entries(t.policy).map(async([t,o])=>{const r=await Ee(e,o,{collector:n});e=re(e,t,r)}));const{eventMapping:o,mappingKey:r}=await $e(e,t.mapping);o?.policy&&await Promise.all(Object.entries(o.policy).map(async([t,o])=>{const r=await Ee(e,o,{collector:n});e=re(e,t,r)}));let i=t.data&&await Ee(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 Ee(e,o.data,{collector:n});i=Y(i)&&Y(t)?B(i,t):t}}return{event:e,data:i,mapping:o,mappingKey:r,ignore:!1}}function Ae(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 Pe(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 Te(){const e=[],t=jest.fn(e=>{const t=e instanceof Error?e.message:e;throw new Error(t)}),n=jest.fn(t=>{const n=Te();return e.push(n),n});return{error:jest.fn(),warn:jest.fn(),info:jest.fn(),debug:jest.fn(),throw:t,json:jest.fn(),scope:n,scopedLoggers:e}}function Ne(e){const t=String(e),n=t.split("?")[1]||t;return ke(()=>{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(J(r)){const s=parseInt(t,10);i?r[s]=ie(e):(r[s]=r[s]||(isNaN(parseInt(o[n+1],10))?{}:[]),r=r[s])}else Y(r)&&(i?r[t]=ie(e):(r[t]=r[t]||(isNaN(parseInt(o[n+1],10))?{}:[]),r=r[t]))})}),t})()}function _e(e){if(!e)return"";const t=[],n=encodeURIComponent;function o(e,r){null!=r&&(J(r)?r.forEach((t,n)=>o(`${e}[${n}]`,t)):Y(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 Ce(e){return void 0===e||ee(e,"")?e:JSON.stringify(e)}function Me(e={}){return B({"Content-Type":"application/json; charset=utf-8"},e)}function Re(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function De(e,t,n){return function(...o){let r;const i="post"+t,s=n["pre"+t],c=n[i];return r=s?s({fn:e},...o):e(...o),c&&(r=c({fn:e,result:r},...o)),r}}function He(e){return e?{userAgent:e,browser:Ie(e),browserVersion:Ve(e),os:ze(e),osVersion:Fe(e),deviceType:Le(e)}:{}}function Ie(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 Ve(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 ze(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 Fe(e){const t=e.match(/(?:Windows NT|Mac OS X|Android|iPhone OS) ([0-9._]+)/);return t?t[1].replace(/_/g,"."):void 0}function Le(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 We(e){return function(e){return/\breturn\b/.test(e)}(e)?e:`return ${e}`}function Be(e){const t=We(e);return new Function("value","mapping","collector",t)}function Ue(e){const t=We(e);return new Function("value","mapping","options",t)}function Je(e){const t=We(e);return new Function("value",t)}var Ke="https://cdn.jsdelivr.net/npm",Ze="dist/walkerOS.json";async function qe(e,t){const n=t?.version||"latest",o=`${Ke}/${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}/${Ze}`,{signal:r.signal});if(!s.ok)throw new Error(`walkerOS.json not found at ${Ze} (HTTP ${s.status}). This package may not support the walkerOS.json convention yet.`);const c=await s.json(),a=c.$meta||{};return{packageName:e,version:i.version||n,type:a.type,platform:a.platform,schemas:c.schemas||{},examples:c.examples||{}}}finally{clearTimeout(i)}}async function Ge(e,t){const n=t?.version||"latest",o=`${Ke}/${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();let s,c;try{const e=await fetch(`${o}/${Ze}`,{signal:r.signal});if(e.ok){const t=(await e.json()).$meta||{};s=t.type,c=t.platform}}catch{}return{packageName:e,version:i.version||n,description:i.description,type:s,platform:c}}finally{clearTimeout(i)}}function Xe(e){return{content:[{type:"text",text:JSON.stringify(e,null,2)}],structuredContent:e}}function Qe(e){return{content:[{type:"text",text:JSON.stringify({error:e instanceof Error?e.message:"Unknown error"})}],isError:!0}}function Ye(e){let t=!1;return(n={})=>{t||(t=!0,e(n))}}//# sourceMappingURL=index.js.map