@walkeros/collector 0.3.0 → 0.3.1

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,n=Object.defineProperty,t=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,a=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},i={};a(i,{Commands:()=>c,Const:()=>r,addDestination:()=>m,commonHandleCommand:()=>P,createEvent:()=>S,createPush:()=>H,createPushResult:()=>y,destinationInit:()=>b,destinationPush:()=>h,initDestinations:()=>v,initSources:()=>$,on:()=>q,onApply:()=>j,pushToDestinations:()=>p,runCollector:()=>R,schemas:()=>u,setConsent:()=>O,startFlow:()=>G}),module.exports=(e=i,((e,a,i,c)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of o(a))s.call(e,r)||r===i||n(e,r,{get:()=>a[r],enumerable:!(c=t(a,r))||c.enumerable});return e})(n({},"__esModule",{value:!0}),e));var c={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},r={Commands:c,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},u={};a(u,{schemas:()=>d,settingsSchema:()=>l});var l={type:"object",properties:{run:{type:"boolean",description:"Automatically start the collector pipeline on initialization"},sources:{type:"object",description:"Configurations for sources providing events to the collector"},destinations:{type:"object",description:"Configurations for destinations receiving processed events"},consent:{type:"object",description:"Initial consent state to control routing of events"},verbose:{type:"boolean",description:"Enable verbose logging for debugging"},onError:{type:"string",description:"Error handler triggered when the collector encounters failures"},onLog:{type:"string",description:"Custom log handler for collector messages"}}},d={settings:l},g=require("@walkeros/core"),f=require("@walkeros/core");async function m(e,n,t){const{code:o,config:s={},env:a={}}=n,i=t||s||{init:!1},c={...o,config:i,env:w(o.env,a)};let r=c.config.id;if(!r)do{r=(0,f.getId)(4)}while(e.destinations[r]);return e.destinations[r]=c,!1!==c.config.queue&&(c.queue=[...e.queue]),p(e,void 0,{[r]:c})}async function p(e,n,t){const{allowed:o,consent:s,globals:a,user:i}=e;if(!o)return y({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const c=await Promise.all(Object.entries(t||{}).map(async([t,o])=>{let c=(o.queue||[]).map(e=>({...e,consent:s}));if(o.queue=[],n){const e=(0,f.clone)(n);c.push(e)}if(!c.length)return{id:t,destination:o,skipped:!0};const r=[],u=c.filter(e=>{const n=(0,f.getGrantedConsent)(o.config.consent,s,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(o.queue.concat(u),!r.length)return{id:t,destination:o,queue:c};if(!await(0,f.tryCatchAsync)(b)(e,o))return{id:t,destination:o,queue:c};let l=!1;return o.dlq||(o.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,f.assign)(a,n.globals),n.user=(0,f.assign)(i,n.user),await(0,f.tryCatchAsync)(h,t=>(e.config.onError&&e.config.onError(t,e),l=!0,o.dlq.push([n,t]),!1))(e,o,n),n))),{id:t,destination:o,error:l}})),r=[],u=[],l=[];for(const e of c){if(e.skipped)continue;const n=e.destination,t={id:e.id,destination:n};e.error?l.push(t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),u.push(t)):r.push(t)}return y({ok:!l.length,event:n,successful:r,queued:u,failed:l})}async function b(e,n){if(n.init&&!n.config.init){const t={collector:e,config:n.config,env:w(n.env,n.config.env)},o=await(0,f.useHooks)(n.init,"DestinationInit",e.hooks)(t);if(!1===o)return o;n.config={...o||n.config,init:!0}}return!0}async function h(e,n,t){const{config:o}=n,s=await(0,f.processEventMapping)(t,o,e);if(s.ignore)return!1;const a={collector:e,config:o,data:s.data,mapping:s.mapping,env:w(n.env,o.env)},i=s.mapping;if(i?.batch&&n.pushBatch){const t=i.batched||{key:s.mappingKey||"",events:[],data:[]};t.events.push(s.event),(0,f.isDefined)(s.data)&&t.data.push(s.data),i.batchFn=i.batchFn||(0,f.debounce)((e,n)=>{const a={collector:n,config:o,data:s.data,mapping:i,env:w(e.env,o.env)};(0,f.useHooks)(e.pushBatch,"DestinationPushBatch",n.hooks)(t,a),t.events=[],t.data=[]},i.batch),i.batched=t,i.batchFn?.(n,e)}else await(0,f.useHooks)(n.push,"DestinationPush",e.hooks)(s.event,a);return!0}function y(e){return(0,f.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function v(e,n={}){const t={};for(const[e,o]of Object.entries(n)){const{code:n,config:s={},env:a={}}=o,i={...n.config,...s},c=w(n.env,a);t[e]={...n,config:i,env:c}}return t}function w(e,n){return e||n?n?e&&(0,f.isObject)(e)&&(0,f.isObject)(n)?{...e,...n}:n:e:{}}var k=require("@walkeros/core"),C=require("@walkeros/core");function q(e,n,t){const o=e.on,s=o[n]||[],a=(0,k.isArray)(t)?t:[t];a.forEach(e=>{s.push(e)}),o[n]=s,j(e,n,a)}function j(e,n,t,o){let s,a=t||[];switch(t||(a=e.on[n]||[]),n){case r.Commands.Consent:s=o||e.consent;break;case r.Commands.Session:s=e.session;break;case r.Commands.Ready:case r.Commands.Run:default:s=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,C.tryCatch)(e.on)(n,s)}),Object.values(e.destinations).forEach(e=>{if(e.on){const t=e.on;(0,C.tryCatch)(t)(n,s)}}),a.length)switch(n){case r.Commands.Consent:!function(e,n,t){const o=t||e.consent;n.forEach(n=>{Object.keys(o).filter(e=>e in n).forEach(t=>{(0,C.tryCatch)(n[t])(e,o)})})}(e,a,o);break;case r.Commands.Ready:case r.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,C.tryCatch)(n)(e)})}(e,a);break;case r.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,C.tryCatch)(n)(e,e.session)})}(e,a)}}async function O(e,n){const{consent:t}=e;let o=!1;const s={};return Object.entries(n).forEach(([e,n])=>{const t=!!n;s[e]=t,o=o||t}),e.consent=(0,g.assign)(t,s),j(e,"consent",void 0,s),o?p(e):y({ok:!0})}var E=require("@walkeros/core"),A=require("@walkeros/core"),D=require("@walkeros/core");async function P(e,n,t,o){let s;switch(n){case r.Commands.Config:(0,D.isObject)(t)&&(0,A.assign)(e.config,t,{shallow:!1});break;case r.Commands.Consent:(0,D.isObject)(t)&&(s=await O(e,t));break;case r.Commands.Custom:(0,D.isObject)(t)&&(e.custom=(0,A.assign)(e.custom,t));break;case r.Commands.Destination:(0,D.isObject)(t)&&(0,A.isFunction)(t.push)&&(s=await m(e,{code:t},o));break;case r.Commands.Globals:(0,D.isObject)(t)&&(e.globals=(0,A.assign)(e.globals,t));break;case r.Commands.On:(0,A.isString)(t)&&q(e,t,o);break;case r.Commands.Ready:j(e,"ready");break;case r.Commands.Run:s=await R(e,t);break;case r.Commands.Session:j(e,"session");break;case r.Commands.User:(0,D.isObject)(t)&&(0,A.assign)(e.user,t,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function S(e,n){if(!n.name)throw new Error("Event name is required");const[t,o]=n.name.split(" ");if(!t||!o)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:i=e.count}=n,{name:c=`${t} ${o}`,data:r={},context:u={},globals:l=e.globals,custom:d={},user:g=e.user,nested:f=[],consent:m=e.consent,id:p=`${s}-${a}-${i}`,trigger:b="",entity:h=t,action:y=o,timing:v=0,version:w={source:e.version,tagging:e.config.tagging||0},source:k={type:"collector",id:"",previous_id:""}}=n;return{name:c,data:r,context:u,globals:l,custom:d,user:g,nested:f,consent:m,id:p,trigger:b,entity:h,action:y,timestamp:s,timing:v,group:a,count:i,version:w,source:k}}async function R(e,n){e.allowed=!0,e.count=0,e.group=(0,A.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,A.assign)(e.consent,n.consent)),n.user&&(e.user=(0,A.assign)(e.user,n.user)),n.globals&&(e.globals=(0,A.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,A.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await p(e);return j(e,"run"),t}var x=require("@walkeros/core");function H(e,n){return(0,x.useHooks)(async(t,o={})=>await(0,x.tryCatchAsync)(async()=>{let s=t;if(o.mapping){const n=await(0,x.processEventMapping)(s,o.mapping,e);if(n.ignore)return y({ok:!0});if(o.mapping.consent){if(!(0,x.getGrantedConsent)(o.mapping.consent,e.consent,n.event.consent))return y({ok:!0})}s=n.event}const a=n(s),i=S(e,a);return await p(e,i)},()=>y({ok:!1}))(),"Push",e.hooks)}var I=require("@walkeros/core");async function L(e){const n={globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0},t=(0,E.assign)(n,e,{merge:!1,extend:!1});function o(e,n){(0,E.onLog)({message:e},n||t.verbose)}t.onLog=o;const s={...t.globalsStatic,...e.globals},a={allowed:!1,config:t,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.3.0",sources:{},push:void 0,command:void 0};return a.push=H(a,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.command=function(e,n){return(0,I.useHooks)(async(t,o,s)=>await(0,I.tryCatchAsync)(async()=>await n(e,t,o,s),()=>y({ok:!1}))(),"Command",e.hooks)}(a,P),a.destinations=await v(0,e.destinations||{}),a}var F=require("@walkeros/core");async function $(e,n={}){const t={};for(const[o,s]of Object.entries(n)){const{code:n,config:a={},env:i={},primary:c}=s,r={push:(n,t={})=>e.push(n,{...t,mapping:a}),command:e.command,sources:e.sources,elb:e.sources.elb.push,...i},u=await(0,F.tryCatchAsync)(n)(a,r);u&&(c&&(u.config={...u.config,primary:c}),t[o]=u)}return t}async function G(e){e=e||{};const n=await L(e),t=(o=n,{type:"elb",config:{},push:async(e,n,t,s,a,i)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return o.command(s,n,t)}let c;if("string"==typeof e)c={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(c.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};c=e,n&&"object"==typeof n&&!Array.isArray(n)&&(c.data={...c.data||{},...n})}return s&&"object"==typeof s&&(c.context=s),a&&Array.isArray(a)&&(c.nested=a),i&&"object"==typeof i&&(c.custom=i),o.push(c)}});var o;n.sources.elb=t;const s=await $(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:i,globals:c,custom:r}=e;a&&await n.command("consent",a),i&&await n.command("user",i),c&&Object.assign(n.globals,c),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=t.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),d=l.find(e=>e.config.primary);return d?u=d.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}//# sourceMappingURL=index.js.map
1
+ "use strict";var e,n=Object.defineProperty,t=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,a=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},i={};a(i,{Commands:()=>c,Const:()=>r,addDestination:()=>m,commonHandleCommand:()=>P,createEvent:()=>S,createPush:()=>H,createPushResult:()=>y,destinationInit:()=>b,destinationPush:()=>h,initDestinations:()=>v,initSources:()=>$,on:()=>q,onApply:()=>j,pushToDestinations:()=>p,runCollector:()=>R,schemas:()=>u,setConsent:()=>O,startFlow:()=>G}),module.exports=(e=i,((e,a,i,c)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of o(a))s.call(e,r)||r===i||n(e,r,{get:()=>a[r],enumerable:!(c=t(a,r))||c.enumerable});return e})(n({},"__esModule",{value:!0}),e));var c={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},r={Commands:c,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},u={};a(u,{schemas:()=>d,settingsSchema:()=>l});var l={type:"object",properties:{run:{type:"boolean",description:"Automatically start the collector pipeline on initialization"},sources:{type:"object",description:"Configurations for sources providing events to the collector"},destinations:{type:"object",description:"Configurations for destinations receiving processed events"},consent:{type:"object",description:"Initial consent state to control routing of events"},verbose:{type:"boolean",description:"Enable verbose logging for debugging"},onError:{type:"string",description:"Error handler triggered when the collector encounters failures"},onLog:{type:"string",description:"Custom log handler for collector messages"}}},d={settings:l},g=require("@walkeros/core"),f=require("@walkeros/core");async function m(e,n,t){const{code:o,config:s={},env:a={}}=n,i=t||s||{init:!1},c={...o,config:i,env:w(o.env,a)};let r=c.config.id;if(!r)do{r=(0,f.getId)(4)}while(e.destinations[r]);return e.destinations[r]=c,!1!==c.config.queue&&(c.queue=[...e.queue]),p(e,void 0,{[r]:c})}async function p(e,n,t){const{allowed:o,consent:s,globals:a,user:i}=e;if(!o)return y({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const c=await Promise.all(Object.entries(t||{}).map(async([t,o])=>{let c=(o.queue||[]).map(e=>({...e,consent:s}));if(o.queue=[],n){const e=(0,f.clone)(n);c.push(e)}if(!c.length)return{id:t,destination:o,skipped:!0};const r=[],u=c.filter(e=>{const n=(0,f.getGrantedConsent)(o.config.consent,s,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(o.queue.concat(u),!r.length)return{id:t,destination:o,queue:c};if(!await(0,f.tryCatchAsync)(b)(e,o))return{id:t,destination:o,queue:c};let l=!1;return o.dlq||(o.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,f.assign)(a,n.globals),n.user=(0,f.assign)(i,n.user),await(0,f.tryCatchAsync)(h,t=>(e.config.onError&&e.config.onError(t,e),l=!0,o.dlq.push([n,t]),!1))(e,o,n),n))),{id:t,destination:o,error:l}})),r=[],u=[],l=[];for(const e of c){if(e.skipped)continue;const n=e.destination,t={id:e.id,destination:n};e.error?l.push(t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),u.push(t)):r.push(t)}return y({ok:!l.length,event:n,successful:r,queued:u,failed:l})}async function b(e,n){if(n.init&&!n.config.init){const t={collector:e,config:n.config,env:w(n.env,n.config.env)},o=await(0,f.useHooks)(n.init,"DestinationInit",e.hooks)(t);if(!1===o)return o;n.config={...o||n.config,init:!0}}return!0}async function h(e,n,t){const{config:o}=n,s=await(0,f.processEventMapping)(t,o,e);if(s.ignore)return!1;const a={collector:e,config:o,data:s.data,mapping:s.mapping,env:w(n.env,o.env)},i=s.mapping;if(i?.batch&&n.pushBatch){const t=i.batched||{key:s.mappingKey||"",events:[],data:[]};t.events.push(s.event),(0,f.isDefined)(s.data)&&t.data.push(s.data),i.batchFn=i.batchFn||(0,f.debounce)((e,n)=>{const a={collector:n,config:o,data:s.data,mapping:i,env:w(e.env,o.env)};(0,f.useHooks)(e.pushBatch,"DestinationPushBatch",n.hooks)(t,a),t.events=[],t.data=[]},i.batch),i.batched=t,i.batchFn?.(n,e)}else await(0,f.useHooks)(n.push,"DestinationPush",e.hooks)(s.event,a);return!0}function y(e){return(0,f.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function v(e,n={}){const t={};for(const[e,o]of Object.entries(n)){const{code:n,config:s={},env:a={}}=o,i={...n.config,...s},c=w(n.env,a);t[e]={...n,config:i,env:c}}return t}function w(e,n){return e||n?n?e&&(0,f.isObject)(e)&&(0,f.isObject)(n)?{...e,...n}:n:e:{}}var k=require("@walkeros/core"),C=require("@walkeros/core");function q(e,n,t){const o=e.on,s=o[n]||[],a=(0,k.isArray)(t)?t:[t];a.forEach(e=>{s.push(e)}),o[n]=s,j(e,n,a)}function j(e,n,t,o){let s,a=t||[];switch(t||(a=e.on[n]||[]),n){case r.Commands.Consent:s=o||e.consent;break;case r.Commands.Session:s=e.session;break;case r.Commands.Ready:case r.Commands.Run:default:s=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,C.tryCatch)(e.on)(n,s)}),Object.values(e.destinations).forEach(e=>{if(e.on){const t=e.on;(0,C.tryCatch)(t)(n,s)}}),a.length)switch(n){case r.Commands.Consent:!function(e,n,t){const o=t||e.consent;n.forEach(n=>{Object.keys(o).filter(e=>e in n).forEach(t=>{(0,C.tryCatch)(n[t])(e,o)})})}(e,a,o);break;case r.Commands.Ready:case r.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,C.tryCatch)(n)(e)})}(e,a);break;case r.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,C.tryCatch)(n)(e,e.session)})}(e,a)}}async function O(e,n){const{consent:t}=e;let o=!1;const s={};return Object.entries(n).forEach(([e,n])=>{const t=!!n;s[e]=t,o=o||t}),e.consent=(0,g.assign)(t,s),j(e,"consent",void 0,s),o?p(e):y({ok:!0})}var E=require("@walkeros/core"),A=require("@walkeros/core"),D=require("@walkeros/core");async function P(e,n,t,o){let s;switch(n){case r.Commands.Config:(0,D.isObject)(t)&&(0,A.assign)(e.config,t,{shallow:!1});break;case r.Commands.Consent:(0,D.isObject)(t)&&(s=await O(e,t));break;case r.Commands.Custom:(0,D.isObject)(t)&&(e.custom=(0,A.assign)(e.custom,t));break;case r.Commands.Destination:(0,D.isObject)(t)&&(0,A.isFunction)(t.push)&&(s=await m(e,{code:t},o));break;case r.Commands.Globals:(0,D.isObject)(t)&&(e.globals=(0,A.assign)(e.globals,t));break;case r.Commands.On:(0,A.isString)(t)&&q(e,t,o);break;case r.Commands.Ready:j(e,"ready");break;case r.Commands.Run:s=await R(e,t);break;case r.Commands.Session:j(e,"session");break;case r.Commands.User:(0,D.isObject)(t)&&(0,A.assign)(e.user,t,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function S(e,n){if(!n.name)throw new Error("Event name is required");const[t,o]=n.name.split(" ");if(!t||!o)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:i=e.count}=n,{name:c=`${t} ${o}`,data:r={},context:u={},globals:l=e.globals,custom:d={},user:g=e.user,nested:f=[],consent:m=e.consent,id:p=`${s}-${a}-${i}`,trigger:b="",entity:h=t,action:y=o,timing:v=0,version:w={source:e.version,tagging:e.config.tagging||0},source:k={type:"collector",id:"",previous_id:""}}=n;return{name:c,data:r,context:u,globals:l,custom:d,user:g,nested:f,consent:m,id:p,trigger:b,entity:h,action:y,timestamp:s,timing:v,group:a,count:i,version:w,source:k}}async function R(e,n){e.allowed=!0,e.count=0,e.group=(0,A.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,A.assign)(e.consent,n.consent)),n.user&&(e.user=(0,A.assign)(e.user,n.user)),n.globals&&(e.globals=(0,A.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,A.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await p(e);return j(e,"run"),t}var x=require("@walkeros/core");function H(e,n){return(0,x.useHooks)(async(t,o={})=>await(0,x.tryCatchAsync)(async()=>{let s=t;if(o.mapping){const n=await(0,x.processEventMapping)(s,o.mapping,e);if(n.ignore)return y({ok:!0});if(o.mapping.consent){if(!(0,x.getGrantedConsent)(o.mapping.consent,e.consent,n.event.consent))return y({ok:!0})}s=n.event}const a=n(s),i=S(e,a);return await p(e,i)},()=>y({ok:!1}))(),"Push",e.hooks)}var I=require("@walkeros/core");async function L(e){const n={globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0},t=(0,E.assign)(n,e,{merge:!1,extend:!1});function o(e,n){(0,E.onLog)({message:e},n||t.verbose)}t.onLog=o;const s={...t.globalsStatic,...e.globals},a={allowed:!1,config:t,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.3.1",sources:{},push:void 0,command:void 0};return a.push=H(a,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.command=function(e,n){return(0,I.useHooks)(async(t,o,s)=>await(0,I.tryCatchAsync)(async()=>await n(e,t,o,s),()=>y({ok:!1}))(),"Command",e.hooks)}(a,P),a.destinations=await v(0,e.destinations||{}),a}var F=require("@walkeros/core");async function $(e,n={}){const t={};for(const[o,s]of Object.entries(n)){const{code:n,config:a={},env:i={},primary:c}=s,r={push:(n,t={})=>e.push(n,{...t,mapping:a}),command:e.command,sources:e.sources,elb:e.sources.elb.push,...i},u=await(0,F.tryCatchAsync)(n)(a,r);u&&(c&&(u.config={...u.config,primary:c}),t[o]=u)}return t}async function G(e){e=e||{};const n=await L(e),t=(o=n,{type:"elb",config:{},push:async(e,n,t,s,a,i)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return o.command(s,n,t)}let c;if("string"==typeof e)c={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(c.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};c=e,n&&"object"==typeof n&&!Array.isArray(n)&&(c.data={...c.data||{},...n})}return s&&"object"==typeof s&&(c.context=s),a&&Array.isArray(a)&&(c.nested=a),i&&"object"==typeof i&&(c.custom=i),o.push(c)}});var o;n.sources.elb=t;const s=await $(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:i,globals:c,custom:r}=e;a&&await n.command("consent",a),i&&await n.command("user",i),c&&Object.assign(n.globals,c),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=t.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),d=l.find(e=>e.config.primary);return d?u=d.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}//# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var e=Object.defineProperty,n={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},o={Commands:n,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},t={};((n,o)=>{for(var t in o)e(n,t,{get:o[t],enumerable:!0})})(t,{schemas:()=>a,settingsSchema:()=>s});var s={type:"object",properties:{run:{type:"boolean",description:"Automatically start the collector pipeline on initialization"},sources:{type:"object",description:"Configurations for sources providing events to the collector"},destinations:{type:"object",description:"Configurations for destinations receiving processed events"},consent:{type:"object",description:"Initial consent state to control routing of events"},verbose:{type:"boolean",description:"Enable verbose logging for debugging"},onError:{type:"string",description:"Error handler triggered when the collector encounters failures"},onLog:{type:"string",description:"Custom log handler for collector messages"}}},a={settings:s};import{assign as i}from"@walkeros/core";import{assign as c,clone as r,debounce as u,getId as l,getGrantedConsent as d,isDefined as m,isObject as f,processEventMapping as g,tryCatchAsync as p,useHooks as b}from"@walkeros/core";async function h(e,n,o){const{code:t,config:s={},env:a={}}=n,i=o||s||{init:!1},c={...t,config:i,env:q(t.env,a)};let r=c.config.id;if(!r)do{r=l(4)}while(e.destinations[r]);return e.destinations[r]=c,!1!==c.config.queue&&(c.queue=[...e.queue]),y(e,void 0,{[r]:c})}async function y(e,n,o){const{allowed:t,consent:s,globals:a,user:i}=e;if(!t)return w({ok:!1});n&&e.queue.push(n),o||(o=e.destinations);const u=await Promise.all(Object.entries(o||{}).map(async([o,t])=>{let u=(t.queue||[]).map(e=>({...e,consent:s}));if(t.queue=[],n){const e=r(n);u.push(e)}if(!u.length)return{id:o,destination:t,skipped:!0};const l=[],m=u.filter(e=>{const n=d(t.config.consent,s,e.consent);return!n||(e.consent=n,l.push(e),!1)});if(t.queue.concat(m),!l.length)return{id:o,destination:t,queue:u};if(!await p(v)(e,t))return{id:o,destination:t,queue:u};let f=!1;return t.dlq||(t.dlq=[]),await Promise.all(l.map(async n=>(n.globals=c(a,n.globals),n.user=c(i,n.user),await p(k,o=>(e.config.onError&&e.config.onError(o,e),f=!0,t.dlq.push([n,o]),!1))(e,t,n),n))),{id:o,destination:t,error:f}})),l=[],m=[],f=[];for(const e of u){if(e.skipped)continue;const n=e.destination,o={id:e.id,destination:n};e.error?f.push(o):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),m.push(o)):l.push(o)}return w({ok:!f.length,event:n,successful:l,queued:m,failed:f})}async function v(e,n){if(n.init&&!n.config.init){const o={collector:e,config:n.config,env:q(n.env,n.config.env)},t=await b(n.init,"DestinationInit",e.hooks)(o);if(!1===t)return t;n.config={...t||n.config,init:!0}}return!0}async function k(e,n,o){const{config:t}=n,s=await g(o,t,e);if(s.ignore)return!1;const a={collector:e,config:t,data:s.data,mapping:s.mapping,env:q(n.env,t.env)},i=s.mapping;if(i?.batch&&n.pushBatch){const o=i.batched||{key:s.mappingKey||"",events:[],data:[]};o.events.push(s.event),m(s.data)&&o.data.push(s.data),i.batchFn=i.batchFn||u((e,n)=>{const a={collector:n,config:t,data:s.data,mapping:i,env:q(e.env,t.env)};b(e.pushBatch,"DestinationPushBatch",n.hooks)(o,a),o.events=[],o.data=[]},i.batch),i.batched=o,i.batchFn?.(n,e)}else await b(n.push,"DestinationPush",e.hooks)(s.event,a);return!0}function w(e){return c({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function C(e,n={}){const o={};for(const[e,t]of Object.entries(n)){const{code:n,config:s={},env:a={}}=t,i={...n.config,...s},c=q(n.env,a);o[e]={...n,config:i,env:c}}return o}function q(e,n){return e||n?n?e&&f(e)&&f(n)?{...e,...n}:n:e:{}}import{isArray as j}from"@walkeros/core";import{tryCatch as E}from"@walkeros/core";function O(e,n,o){const t=e.on,s=t[n]||[],a=j(o)?o:[o];a.forEach(e=>{s.push(e)}),t[n]=s,A(e,n,a)}function A(e,n,t,s){let a,i=t||[];switch(t||(i=e.on[n]||[]),n){case o.Commands.Consent:a=s||e.consent;break;case o.Commands.Session:a=e.session;break;case o.Commands.Ready:case o.Commands.Run:default:a=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&E(e.on)(n,a)}),Object.values(e.destinations).forEach(e=>{if(e.on){const o=e.on;E(o)(n,a)}}),i.length)switch(n){case o.Commands.Consent:!function(e,n,o){const t=o||e.consent;n.forEach(n=>{Object.keys(t).filter(e=>e in n).forEach(o=>{E(n[o])(e,t)})})}(e,i,s);break;case o.Commands.Ready:case o.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{E(n)(e)})}(e,i);break;case o.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{E(n)(e,e.session)})}(e,i)}}async function S(e,n){const{consent:o}=e;let t=!1;const s={};return Object.entries(n).forEach(([e,n])=>{const o=!!n;s[e]=o,t=t||o}),e.consent=i(o,s),A(e,"consent",void 0,s),t?y(e):w({ok:!0})}import{assign as D,onLog as x}from"@walkeros/core";import{assign as R,getId as P,isFunction as L,isString as $}from"@walkeros/core";import{isObject as I}from"@walkeros/core";async function B(e,n,t,s){let a;switch(n){case o.Commands.Config:I(t)&&R(e.config,t,{shallow:!1});break;case o.Commands.Consent:I(t)&&(a=await S(e,t));break;case o.Commands.Custom:I(t)&&(e.custom=R(e.custom,t));break;case o.Commands.Destination:I(t)&&L(t.push)&&(a=await h(e,{code:t},s));break;case o.Commands.Globals:I(t)&&(e.globals=R(e.globals,t));break;case o.Commands.On:$(t)&&O(e,t,s);break;case o.Commands.Ready:A(e,"ready");break;case o.Commands.Run:a=await G(e,t);break;case o.Commands.Session:A(e,"session");break;case o.Commands.User:I(t)&&R(e.user,t,{shallow:!1})}return a||{ok:!0,successful:[],queued:[],failed:[]}}function F(e,n){if(!n.name)throw new Error("Event name is required");const[o,t]=n.name.split(" ");if(!o||!t)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:i=e.count}=n,{name:c=`${o} ${t}`,data:r={},context:u={},globals:l=e.globals,custom:d={},user:m=e.user,nested:f=[],consent:g=e.consent,id:p=`${s}-${a}-${i}`,trigger:b="",entity:h=o,action:y=t,timing:v=0,version:k={source:e.version,tagging:e.config.tagging||0},source:w={type:"collector",id:"",previous_id:""}}=n;return{name:c,data:r,context:u,globals:l,custom:d,user:m,nested:f,consent:g,id:p,trigger:b,entity:h,action:y,timestamp:s,timing:v,group:a,count:i,version:k,source:w}}async function G(e,n){e.allowed=!0,e.count=0,e.group=P(),e.timing=Date.now(),n&&(n.consent&&(e.consent=R(e.consent,n.consent)),n.user&&(e.user=R(e.user,n.user)),n.globals&&(e.globals=R(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=R(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const o=await y(e);return A(e,"run"),o}import{getGrantedConsent as H,processEventMapping as U,tryCatchAsync as M,useHooks as W}from"@walkeros/core";function _(e,n){return W(async(o,t={})=>await M(async()=>{let s=o;if(t.mapping){const n=await U(s,t.mapping,e);if(n.ignore)return w({ok:!0});if(t.mapping.consent){if(!H(t.mapping.consent,e.consent,n.event.consent))return w({ok:!0})}s=n.event}const a=n(s),i=F(e,a);return await y(e,i)},()=>w({ok:!1}))(),"Push",e.hooks)}import{useHooks as z,tryCatchAsync as K}from"@walkeros/core";async function J(e){const n=D({globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0},e,{merge:!1,extend:!1});function o(e,o){x({message:e},o||n.verbose)}n.onLog=o;const t={...n.globalsStatic,...e.globals},s={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:t,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.3.0",sources:{},push:void 0,command:void 0};return s.push=_(s,e=>({timing:Math.round((Date.now()-s.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),s.command=function(e,n){return z(async(o,t,s)=>await K(async()=>await n(e,o,t,s),()=>w({ok:!1}))(),"Command",e.hooks)}(s,B),s.destinations=await C(0,e.destinations||{}),s}import{tryCatchAsync as N}from"@walkeros/core";async function Q(e,n={}){const o={};for(const[t,s]of Object.entries(n)){const{code:n,config:a={},env:i={},primary:c}=s,r={push:(n,o={})=>e.push(n,{...o,mapping:a}),command:e.command,sources:e.sources,elb:e.sources.elb.push,...i},u=await N(n)(a,r);u&&(c&&(u.config={...u.config,primary:c}),o[t]=u)}return o}async function T(e){e=e||{};const n=await J(e),o=(t=n,{type:"elb",config:{},push:async(e,n,o,s,a,i)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return t.command(s,n,o)}let c;if("string"==typeof e)c={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(c.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};c=e,n&&"object"==typeof n&&!Array.isArray(n)&&(c.data={...c.data||{},...n})}return s&&"object"==typeof s&&(c.context=s),a&&Array.isArray(a)&&(c.nested=a),i&&"object"==typeof i&&(c.custom=i),t.push(c)}});var t;n.sources.elb=o;const s=await Q(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:i,globals:c,custom:r}=e;a&&await n.command("consent",a),i&&await n.command("user",i),c&&Object.assign(n.globals,c),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=o.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),d=l.find(e=>e.config.primary);return d?u=d.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}export{n as Commands,o as Const,h as addDestination,B as commonHandleCommand,F as createEvent,_ as createPush,w as createPushResult,v as destinationInit,k as destinationPush,C as initDestinations,Q as initSources,O as on,A as onApply,y as pushToDestinations,G as runCollector,t as schemas,S as setConsent,T as startFlow};//# sourceMappingURL=index.mjs.map
1
+ var e=Object.defineProperty,n={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},o={Commands:n,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},t={};((n,o)=>{for(var t in o)e(n,t,{get:o[t],enumerable:!0})})(t,{schemas:()=>a,settingsSchema:()=>s});var s={type:"object",properties:{run:{type:"boolean",description:"Automatically start the collector pipeline on initialization"},sources:{type:"object",description:"Configurations for sources providing events to the collector"},destinations:{type:"object",description:"Configurations for destinations receiving processed events"},consent:{type:"object",description:"Initial consent state to control routing of events"},verbose:{type:"boolean",description:"Enable verbose logging for debugging"},onError:{type:"string",description:"Error handler triggered when the collector encounters failures"},onLog:{type:"string",description:"Custom log handler for collector messages"}}},a={settings:s};import{assign as i}from"@walkeros/core";import{assign as c,clone as r,debounce as u,getId as l,getGrantedConsent as d,isDefined as m,isObject as f,processEventMapping as g,tryCatchAsync as p,useHooks as b}from"@walkeros/core";async function h(e,n,o){const{code:t,config:s={},env:a={}}=n,i=o||s||{init:!1},c={...t,config:i,env:q(t.env,a)};let r=c.config.id;if(!r)do{r=l(4)}while(e.destinations[r]);return e.destinations[r]=c,!1!==c.config.queue&&(c.queue=[...e.queue]),y(e,void 0,{[r]:c})}async function y(e,n,o){const{allowed:t,consent:s,globals:a,user:i}=e;if(!t)return w({ok:!1});n&&e.queue.push(n),o||(o=e.destinations);const u=await Promise.all(Object.entries(o||{}).map(async([o,t])=>{let u=(t.queue||[]).map(e=>({...e,consent:s}));if(t.queue=[],n){const e=r(n);u.push(e)}if(!u.length)return{id:o,destination:t,skipped:!0};const l=[],m=u.filter(e=>{const n=d(t.config.consent,s,e.consent);return!n||(e.consent=n,l.push(e),!1)});if(t.queue.concat(m),!l.length)return{id:o,destination:t,queue:u};if(!await p(v)(e,t))return{id:o,destination:t,queue:u};let f=!1;return t.dlq||(t.dlq=[]),await Promise.all(l.map(async n=>(n.globals=c(a,n.globals),n.user=c(i,n.user),await p(k,o=>(e.config.onError&&e.config.onError(o,e),f=!0,t.dlq.push([n,o]),!1))(e,t,n),n))),{id:o,destination:t,error:f}})),l=[],m=[],f=[];for(const e of u){if(e.skipped)continue;const n=e.destination,o={id:e.id,destination:n};e.error?f.push(o):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),m.push(o)):l.push(o)}return w({ok:!f.length,event:n,successful:l,queued:m,failed:f})}async function v(e,n){if(n.init&&!n.config.init){const o={collector:e,config:n.config,env:q(n.env,n.config.env)},t=await b(n.init,"DestinationInit",e.hooks)(o);if(!1===t)return t;n.config={...t||n.config,init:!0}}return!0}async function k(e,n,o){const{config:t}=n,s=await g(o,t,e);if(s.ignore)return!1;const a={collector:e,config:t,data:s.data,mapping:s.mapping,env:q(n.env,t.env)},i=s.mapping;if(i?.batch&&n.pushBatch){const o=i.batched||{key:s.mappingKey||"",events:[],data:[]};o.events.push(s.event),m(s.data)&&o.data.push(s.data),i.batchFn=i.batchFn||u((e,n)=>{const a={collector:n,config:t,data:s.data,mapping:i,env:q(e.env,t.env)};b(e.pushBatch,"DestinationPushBatch",n.hooks)(o,a),o.events=[],o.data=[]},i.batch),i.batched=o,i.batchFn?.(n,e)}else await b(n.push,"DestinationPush",e.hooks)(s.event,a);return!0}function w(e){return c({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function C(e,n={}){const o={};for(const[e,t]of Object.entries(n)){const{code:n,config:s={},env:a={}}=t,i={...n.config,...s},c=q(n.env,a);o[e]={...n,config:i,env:c}}return o}function q(e,n){return e||n?n?e&&f(e)&&f(n)?{...e,...n}:n:e:{}}import{isArray as j}from"@walkeros/core";import{tryCatch as E}from"@walkeros/core";function O(e,n,o){const t=e.on,s=t[n]||[],a=j(o)?o:[o];a.forEach(e=>{s.push(e)}),t[n]=s,A(e,n,a)}function A(e,n,t,s){let a,i=t||[];switch(t||(i=e.on[n]||[]),n){case o.Commands.Consent:a=s||e.consent;break;case o.Commands.Session:a=e.session;break;case o.Commands.Ready:case o.Commands.Run:default:a=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&E(e.on)(n,a)}),Object.values(e.destinations).forEach(e=>{if(e.on){const o=e.on;E(o)(n,a)}}),i.length)switch(n){case o.Commands.Consent:!function(e,n,o){const t=o||e.consent;n.forEach(n=>{Object.keys(t).filter(e=>e in n).forEach(o=>{E(n[o])(e,t)})})}(e,i,s);break;case o.Commands.Ready:case o.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{E(n)(e)})}(e,i);break;case o.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{E(n)(e,e.session)})}(e,i)}}async function S(e,n){const{consent:o}=e;let t=!1;const s={};return Object.entries(n).forEach(([e,n])=>{const o=!!n;s[e]=o,t=t||o}),e.consent=i(o,s),A(e,"consent",void 0,s),t?y(e):w({ok:!0})}import{assign as D,onLog as x}from"@walkeros/core";import{assign as R,getId as P,isFunction as L,isString as $}from"@walkeros/core";import{isObject as I}from"@walkeros/core";async function B(e,n,t,s){let a;switch(n){case o.Commands.Config:I(t)&&R(e.config,t,{shallow:!1});break;case o.Commands.Consent:I(t)&&(a=await S(e,t));break;case o.Commands.Custom:I(t)&&(e.custom=R(e.custom,t));break;case o.Commands.Destination:I(t)&&L(t.push)&&(a=await h(e,{code:t},s));break;case o.Commands.Globals:I(t)&&(e.globals=R(e.globals,t));break;case o.Commands.On:$(t)&&O(e,t,s);break;case o.Commands.Ready:A(e,"ready");break;case o.Commands.Run:a=await G(e,t);break;case o.Commands.Session:A(e,"session");break;case o.Commands.User:I(t)&&R(e.user,t,{shallow:!1})}return a||{ok:!0,successful:[],queued:[],failed:[]}}function F(e,n){if(!n.name)throw new Error("Event name is required");const[o,t]=n.name.split(" ");if(!o||!t)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:i=e.count}=n,{name:c=`${o} ${t}`,data:r={},context:u={},globals:l=e.globals,custom:d={},user:m=e.user,nested:f=[],consent:g=e.consent,id:p=`${s}-${a}-${i}`,trigger:b="",entity:h=o,action:y=t,timing:v=0,version:k={source:e.version,tagging:e.config.tagging||0},source:w={type:"collector",id:"",previous_id:""}}=n;return{name:c,data:r,context:u,globals:l,custom:d,user:m,nested:f,consent:g,id:p,trigger:b,entity:h,action:y,timestamp:s,timing:v,group:a,count:i,version:k,source:w}}async function G(e,n){e.allowed=!0,e.count=0,e.group=P(),e.timing=Date.now(),n&&(n.consent&&(e.consent=R(e.consent,n.consent)),n.user&&(e.user=R(e.user,n.user)),n.globals&&(e.globals=R(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=R(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const o=await y(e);return A(e,"run"),o}import{getGrantedConsent as H,processEventMapping as U,tryCatchAsync as M,useHooks as W}from"@walkeros/core";function _(e,n){return W(async(o,t={})=>await M(async()=>{let s=o;if(t.mapping){const n=await U(s,t.mapping,e);if(n.ignore)return w({ok:!0});if(t.mapping.consent){if(!H(t.mapping.consent,e.consent,n.event.consent))return w({ok:!0})}s=n.event}const a=n(s),i=F(e,a);return await y(e,i)},()=>w({ok:!1}))(),"Push",e.hooks)}import{useHooks as z,tryCatchAsync as K}from"@walkeros/core";async function J(e){const n=D({globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0},e,{merge:!1,extend:!1});function o(e,o){x({message:e},o||n.verbose)}n.onLog=o;const t={...n.globalsStatic,...e.globals},s={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:t,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.3.1",sources:{},push:void 0,command:void 0};return s.push=_(s,e=>({timing:Math.round((Date.now()-s.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),s.command=function(e,n){return z(async(o,t,s)=>await K(async()=>await n(e,o,t,s),()=>w({ok:!1}))(),"Command",e.hooks)}(s,B),s.destinations=await C(0,e.destinations||{}),s}import{tryCatchAsync as N}from"@walkeros/core";async function Q(e,n={}){const o={};for(const[t,s]of Object.entries(n)){const{code:n,config:a={},env:i={},primary:c}=s,r={push:(n,o={})=>e.push(n,{...o,mapping:a}),command:e.command,sources:e.sources,elb:e.sources.elb.push,...i},u=await N(n)(a,r);u&&(c&&(u.config={...u.config,primary:c}),o[t]=u)}return o}async function T(e){e=e||{};const n=await J(e),o=(t=n,{type:"elb",config:{},push:async(e,n,o,s,a,i)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return t.command(s,n,o)}let c;if("string"==typeof e)c={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(c.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};c=e,n&&"object"==typeof n&&!Array.isArray(n)&&(c.data={...c.data||{},...n})}return s&&"object"==typeof s&&(c.context=s),a&&Array.isArray(a)&&(c.nested=a),i&&"object"==typeof i&&(c.custom=i),t.push(c)}});var t;n.sources.elb=o;const s=await Q(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:i,globals:c,custom:r}=e;a&&await n.command("consent",a),i&&await n.command("user",i),c&&Object.assign(n.globals,c),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=o.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),d=l.find(e=>e.config.primary);return d?u=d.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}export{n as Commands,o as Const,h as addDestination,B as commonHandleCommand,F as createEvent,_ as createPush,w as createPushResult,v as destinationInit,k as destinationPush,C as initDestinations,Q as initSources,O as on,A as onApply,y as pushToDestinations,G as runCollector,t as schemas,S as setConsent,T as startFlow};//# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@walkeros/collector",
3
3
  "description": "Unified platform-agnostic collector for walkerOS",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "update": "npx npm-check-updates -u && npm update"
19
19
  },
20
20
  "dependencies": {
21
- "@walkeros/core": "0.3.0"
21
+ "@walkeros/core": "0.3.1"
22
22
  },
23
23
  "devDependencies": {},
24
24
  "repository": {