@walkeros/collector 0.1.2 → 0.2.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/README.md CHANGED
@@ -80,7 +80,7 @@ npm install @walkeros/collector
80
80
  ### Basic setup
81
81
 
82
82
  ```typescript
83
- import { createCollector } from '@walkeros/collector';
83
+ import { startFlow } from '@walkeros/collector';
84
84
 
85
85
  const config = {
86
86
  run: true,
@@ -91,15 +91,15 @@ const config = {
91
91
  },
92
92
  };
93
93
 
94
- const { collector, elb } = await createCollector(config);
94
+ const { collector, elb } = await startFlow(config);
95
95
  ```
96
96
 
97
97
  ### Advanced setup
98
98
 
99
99
  ```typescript
100
- import { createCollector } from '@walkeros/collector';
100
+ import { startFlow } from '@walkeros/collector';
101
101
 
102
- const { collector, elb } = await createCollector({
102
+ const { collector, elb } = await startFlow({
103
103
  run: true,
104
104
  consent: { functional: true },
105
105
  sources: [
package/dist/index.d.mts CHANGED
@@ -10,6 +10,10 @@ interface CreateCollector {
10
10
  collector: Collector.Instance;
11
11
  elb: WalkerOS.Elb;
12
12
  }
13
+ interface StartFlow<ElbPush extends WalkerOS.Elb = WalkerOS.Elb> {
14
+ collector: Collector.Instance;
15
+ elb: ElbPush;
16
+ }
13
17
 
14
18
  type CommandTypes = 'Action' | 'Actions' | 'Config' | 'Consent' | 'Context' | 'Custom' | 'Destination' | 'Elb' | 'Globals' | 'Hook' | 'Init' | 'Link' | 'On' | 'Prefix' | 'Ready' | 'Run' | 'Session' | 'User' | 'Walker';
15
19
  declare const Commands: Record<CommandTypes, Collector.CommandType>;
@@ -32,7 +36,7 @@ declare const Const: {
32
36
  */
33
37
  declare function setConsent(collector: Collector.Instance, data: WalkerOS.Consent): Promise<Elb.PushResult>;
34
38
 
35
- declare function createCollector<TConfig extends Partial<Collector.Config> = Partial<Collector.Config>>(initConfig?: TConfig): Promise<CreateCollector>;
39
+ declare function startFlow<ElbPush extends Elb.Fn = Elb.Fn>(initConfig?: Collector.InitConfig): Promise<StartFlow<ElbPush>>;
36
40
 
37
41
  type HandleCommandFn<T extends Collector.Instance> = (collector: T, action: string, data?: Elb.PushData, options?: unknown) => Promise<Elb.PushResult>;
38
42
  /**
@@ -157,4 +161,4 @@ declare function onApply(collector: Collector.Instance, type: On.Types, options?
157
161
  */
158
162
  declare function initSources(collector: Collector.Instance, sources?: Source.InitSources): Promise<Collector.Sources>;
159
163
 
160
- export { type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type RunState, type StorageType, addDestination, commonHandleCommand, createCollector, createEventOrCommand, createPush, createPushResult, destinationInit, destinationPush, initDestinations, initSources, on, onApply, pushToDestinations, runCollector, setConsent };
164
+ export { type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type RunState, type StartFlow, type StorageType, addDestination, commonHandleCommand, createEventOrCommand, createPush, createPushResult, destinationInit, destinationPush, initDestinations, initSources, on, onApply, pushToDestinations, runCollector, setConsent, startFlow };
package/dist/index.d.ts CHANGED
@@ -10,6 +10,10 @@ interface CreateCollector {
10
10
  collector: Collector.Instance;
11
11
  elb: WalkerOS.Elb;
12
12
  }
13
+ interface StartFlow<ElbPush extends WalkerOS.Elb = WalkerOS.Elb> {
14
+ collector: Collector.Instance;
15
+ elb: ElbPush;
16
+ }
13
17
 
14
18
  type CommandTypes = 'Action' | 'Actions' | 'Config' | 'Consent' | 'Context' | 'Custom' | 'Destination' | 'Elb' | 'Globals' | 'Hook' | 'Init' | 'Link' | 'On' | 'Prefix' | 'Ready' | 'Run' | 'Session' | 'User' | 'Walker';
15
19
  declare const Commands: Record<CommandTypes, Collector.CommandType>;
@@ -32,7 +36,7 @@ declare const Const: {
32
36
  */
33
37
  declare function setConsent(collector: Collector.Instance, data: WalkerOS.Consent): Promise<Elb.PushResult>;
34
38
 
35
- declare function createCollector<TConfig extends Partial<Collector.Config> = Partial<Collector.Config>>(initConfig?: TConfig): Promise<CreateCollector>;
39
+ declare function startFlow<ElbPush extends Elb.Fn = Elb.Fn>(initConfig?: Collector.InitConfig): Promise<StartFlow<ElbPush>>;
36
40
 
37
41
  type HandleCommandFn<T extends Collector.Instance> = (collector: T, action: string, data?: Elb.PushData, options?: unknown) => Promise<Elb.PushResult>;
38
42
  /**
@@ -157,4 +161,4 @@ declare function onApply(collector: Collector.Instance, type: On.Types, options?
157
161
  */
158
162
  declare function initSources(collector: Collector.Instance, sources?: Source.InitSources): Promise<Collector.Sources>;
159
163
 
160
- export { type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type RunState, type StorageType, addDestination, commonHandleCommand, createCollector, createEventOrCommand, createPush, createPushResult, destinationInit, destinationPush, initDestinations, initSources, on, onApply, pushToDestinations, runCollector, setConsent };
164
+ export { type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type RunState, type StartFlow, type StorageType, addDestination, commonHandleCommand, createEventOrCommand, createPush, createPushResult, destinationInit, destinationPush, initDestinations, initSources, on, onApply, pushToDestinations, runCollector, setConsent, startFlow };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,n,t=Object.defineProperty,s=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,i=(e={"package.json"(e,n){n.exports={name:"@walkeros/collector",description:"Unified platform-agnostic collector for walkerOS",version:"0.1.2",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{"@walkeros/core":"0.1.2"},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/collector"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","collector","event processing"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return n||(0,e[o(e)[0]])((n={exports:{}}).exports,n),n.exports}),c={};((e,n)=>{for(var s in n)t(e,s,{get:n[s],enumerable:!0})})(c,{Commands:()=>r,Const:()=>u,addDestination:()=>C,commonHandleCommand:()=>w,createCollector:()=>M,createEventOrCommand:()=>k,createPush:()=>v,createPushResult:()=>S,destinationInit:()=>q,destinationPush:()=>j,initDestinations:()=>E,initSources:()=>R,on:()=>b,onApply:()=>h,pushToDestinations:()=>O,runCollector:()=>y,setConsent:()=>D}),module.exports=(e=>((e,n,i,c)=>{if(n&&"object"==typeof n||"function"==typeof n)for(let r of o(n))a.call(e,r)||r===i||t(e,r,{get:()=>n[r],enumerable:!(c=s(n,r))||c.enumerable});return e})(t({},"__esModule",{value:!0}),e))(c);var r={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"},u={Commands:r,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},l=require("@walkeros/core"),d=require("@walkeros/core"),g=require("@walkeros/core"),m=require("@walkeros/core"),f=require("@walkeros/core"),p=require("@walkeros/core");function b(e,n,t){const s=e.on,o=s[n]||[],a=(0,f.isArray)(t)?t:[t];a.forEach(e=>{o.push(e)}),s[n]=o,h(e,n,a)}function h(e,n,t,s){let o,a=t||[];switch(t||(a=e.on[n]||[]),n){case u.Commands.Consent:o=s||e.consent;break;case u.Commands.Session:o=e.session;break;case u.Commands.Ready:case u.Commands.Run:default:o=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,p.tryCatch)(e.on)(n,o)}),Object.values(e.destinations).forEach(e=>{e.on&&(0,p.tryCatch)(e.on)(n,o)}),a.length)switch(n){case u.Commands.Consent:!function(e,n,t){const s=t||e.consent;n.forEach(n=>{Object.keys(s).filter(e=>e in n).forEach(t=>{(0,p.tryCatch)(n[t])(e,s)})})}(e,a,s);break;case u.Commands.Ready:case u.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,p.tryCatch)(n)(e)})}(e,a);break;case u.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,p.tryCatch)(n)(e,e.session)})}(e,a)}}async function w(e,n,t,s){let o;switch(n){case u.Commands.Config:(0,m.isObject)(t)&&(0,g.assign)(e.config,t,{shallow:!1});break;case u.Commands.Consent:(0,m.isObject)(t)&&(o=await D(e,t));break;case u.Commands.Custom:(0,m.isObject)(t)&&(e.custom=(0,g.assign)(e.custom,t));break;case u.Commands.Destination:(0,m.isObject)(t)&&(0,g.isFunction)(t.push)&&(o=await C(e,{code:t},s));break;case u.Commands.Globals:(0,m.isObject)(t)&&(e.globals=(0,g.assign)(e.globals,t));break;case u.Commands.On:(0,g.isString)(t)&&b(e,t,s);break;case u.Commands.Ready:h(e,"ready");break;case u.Commands.Run:o=await y(e,t);break;case u.Commands.Session:h(e,"session");break;case u.Commands.User:(0,m.isObject)(t)&&(0,g.assign)(e.user,t,{shallow:!1})}return o||{ok:!0,successful:[],queued:[],failed:[]}}function k(e,n,t={}){const s=(0,m.isSameType)(n,"")?{name:n,...t}:{...t,...n||{}};if(!s.name)throw new Error("Event name is required");const[o,a]=s.name.split(" ");if(!o||!a)throw new Error("Event name is invalid");if(o===r.Walker)return{command:a};++e.count;const{timestamp:i=Date.now(),group:c=e.group,count:u=e.count}=s,{name:l=`${o} ${a}`,data:d={},context:g={},globals:f=e.globals,custom:p={},user:b=e.user,nested:h=[],consent:w=e.consent,id:k=`${i}-${c}-${u}`,trigger:y="",entity:v=o,action:C=a,timing:O=0,version:q={source:e.version,tagging:e.config.tagging||0},source:j={type:"collector",id:"",previous_id:""}}=s;return{event:{name:l,data:d,context:g,globals:f,custom:p,user:b,nested:h,consent:w,id:k,trigger:y,entity:v,action:C,timestamp:i,timing:O,group:c,count:u,version:q,source:j}}}async function y(e,n){e.allowed=!0,e.count=0,e.group=(0,g.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,g.assign)(e.consent,n.consent)),n.user&&(e.user=(0,g.assign)(e.user,n.user)),n.globals&&(e.globals=(0,g.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,g.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await O(e);return h(e,"run"),t}function v(e,n,t){return(0,d.useHooks)(async(s,o,a)=>await(0,d.tryCatchAsync)(async()=>{if("string"==typeof s&&s.startsWith("walker ")){const t=s.replace("walker ","");return await n(e,t,o,a)}{const i=t("string"==typeof s?{name:s}:s),{event:c,command:r}=k(e,i.name,i);return r?await n(e,r,o,a):await O(e,c)}},()=>S({ok:!1}))(),"Push",e.hooks)}async function C(e,n,t){const{code:s,config:o={},env:a={}}=n,i=t||o||{init:!1},c={...s,config:i,env:x(s.env,a)};let r=c.config.id;if(!r)do{r=(0,d.getId)(4)}while(e.destinations[r]);return e.destinations[r]=c,!1!==c.config.queue&&(c.queue=[...e.queue]),O(e,void 0,{[r]:c})}async function O(e,n,t){const{allowed:s,consent:o,globals:a,user:i}=e;if(!s)return S({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const c=await Promise.all(Object.entries(t||{}).map(async([t,s])=>{let c=(s.queue||[]).map(e=>({...e,consent:o}));if(s.queue=[],n){let t=(0,d.clone)(n);await Promise.all(Object.entries(s.config.policy||[]).map(async([s,o])=>{const a=await(0,d.getMappingValue)(n,o,{collector:e});t=(0,d.setByPath)(t,s,a)})),c.push(t)}if(!c.length)return{id:t,destination:s,skipped:!0};const r=[],u=c.filter(e=>{const n=(0,d.getGrantedConsent)(s.config.consent,o,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(s.queue.concat(u),!r.length)return{id:t,destination:s,queue:c};if(!await(0,d.tryCatchAsync)(q)(e,s))return{id:t,destination:s,queue:c};let l=!1;return s.dlq||(s.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,d.assign)(a,n.globals),n.user=(0,d.assign)(i,n.user),await(0,d.tryCatchAsync)(j,t=>(e.config.onError&&e.config.onError(t,e),l=!0,s.dlq.push([n,t]),!1))(e,s,n),n))),{id:t,destination:s,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 S({ok:!l.length,event:n,successful:r,queued:u,failed:l})}async function q(e,n){if(n.init&&!n.config.init){const t={collector:e,config:n.config,env:x(n.env,n.config.env)},s=await(0,d.useHooks)(n.init,"DestinationInit",e.hooks)(t);if(!1===s)return s;n.config={...s||n.config,init:!0}}return!0}async function j(e,n,t){const{config:s}=n,{eventMapping:o,mappingKey:a}=await(0,d.getMappingEvent)(t,s.mapping);let i=s.data&&await(0,d.getMappingValue)(t,s.data,{collector:e});if(o){if(o.ignore)return!1;if(o.name&&(t.name=o.name),o.data){const n=o.data&&await(0,d.getMappingValue)(t,o.data,{collector:e});i=(0,d.isObject)(i)&&(0,d.isObject)(n)?(0,d.assign)(i,n):n}}const c={collector:e,config:s,data:i,mapping:o,env:x(n.env,s.env)};if(o?.batch&&n.pushBatch){const c=o.batched||{key:a||"",events:[],data:[]};c.events.push(t),(0,d.isDefined)(i)&&c.data.push(i),o.batchFn=o.batchFn||(0,d.debounce)((e,n)=>{const t={collector:n,config:s,data:i,mapping:o,env:x(e.env,s.env)};(0,d.useHooks)(e.pushBatch,"DestinationPushBatch",n.hooks)(c,t),c.events=[],c.data=[]},o.batch),o.batched=c,o.batchFn?.(n,e)}else await(0,d.useHooks)(n.push,"DestinationPush",e.hooks)(t,c);return!0}function S(e){return(0,d.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function E(e,n={}){const t={};for(const[e,s]of Object.entries(n)){const{code:n,config:o={},env:a={}}=s,i={...n.config,...o},c=x(n.env,a);t[e]={...n,config:i,env:c}}return t}function x(e,n){return e||n?n?e&&(0,d.isObject)(e)&&(0,d.isObject)(n)?{...e,...n}:n:e:{}}async function D(e,n){const{consent:t}=e;let s=!1;const o={};return Object.entries(n).forEach(([e,n])=>{const t=!!n;o[e]=t,s=s||t}),e.consent=(0,l.assign)(t,o),h(e,"consent",void 0,o),s?O(e):S({ok:!0})}var P=require("@walkeros/core"),A=require("@walkeros/core");async function R(e,n={}){const t={};for(const[s,o]of Object.entries(n)){const{code:n,config:a={},env:i={}}=o,c={elb:(...n)=>e.push(...n),...i},r=await(0,A.tryCatchAsync)(n)(a,c);r&&(t[s]=r)}return t}async function M(e={}){const n=await async function(e){const{version:n}=i(),t={globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0,sources:{},destinations:{},consent:{},user:{},globals:{},custom:{}},s=(0,P.assign)(t,e,{merge:!1,extend:!1});function o(e,n){(0,P.onLog)({message:e},n||s.verbose)}s.onLog=o;const a={...s.globalsStatic,...s.globals},c={allowed:!1,config:s,consent:s.consent||{},count:0,custom:s.custom||{},destinations:{},globals:a,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:s.user||{},version:n,sources:{},push:void 0};return c.push=v(c,w,e=>({timing:Math.round((Date.now()-c.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),c.sources=await R(c,s.sources),c.destinations=await E(0,s.destinations),c}(e),{consent:t,user:s,globals:o,custom:a}=e;return t&&await n.push("walker consent",t),s&&await n.push("walker user",s),o&&Object.assign(n.globals,o),a&&Object.assign(n.custom,a),n.config.run&&await n.push("walker run"),{collector:n,elb:n.push}}//# sourceMappingURL=index.js.map
1
+ "use strict";var e,n=Object.defineProperty,t=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,a={};((e,t)=>{for(var s in t)n(e,s,{get:t[s],enumerable:!0})})(a,{Commands:()=>i,Const:()=>c,addDestination:()=>k,commonHandleCommand:()=>p,createEventOrCommand:()=>b,createPush:()=>y,createPushResult:()=>O,destinationInit:()=>C,destinationPush:()=>q,initDestinations:()=>j,initSources:()=>R,on:()=>m,onApply:()=>h,pushToDestinations:()=>v,runCollector:()=>w,setConsent:()=>P,startFlow:()=>A}),module.exports=(e=a,((e,a,i,c)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of s(a))o.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 i={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"},c={Commands:i,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},r=require("@walkeros/core"),u=require("@walkeros/core"),l=require("@walkeros/core"),g=require("@walkeros/core"),d=require("@walkeros/core"),f=require("@walkeros/core");function m(e,n,t){const s=e.on,o=s[n]||[],a=(0,d.isArray)(t)?t:[t];a.forEach(e=>{o.push(e)}),s[n]=o,h(e,n,a)}function h(e,n,t,s){let o,a=t||[];switch(t||(a=e.on[n]||[]),n){case c.Commands.Consent:o=s||e.consent;break;case c.Commands.Session:o=e.session;break;case c.Commands.Ready:case c.Commands.Run:default:o=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,f.tryCatch)(e.on)(n,o)}),Object.values(e.destinations).forEach(e=>{if(e.on){const t=e.on;(0,f.tryCatch)(t)(n,o)}}),a.length)switch(n){case c.Commands.Consent:!function(e,n,t){const s=t||e.consent;n.forEach(n=>{Object.keys(s).filter(e=>e in n).forEach(t=>{(0,f.tryCatch)(n[t])(e,s)})})}(e,a,s);break;case c.Commands.Ready:case c.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,f.tryCatch)(n)(e)})}(e,a);break;case c.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,f.tryCatch)(n)(e,e.session)})}(e,a)}}async function p(e,n,t,s){let o;switch(n){case c.Commands.Config:(0,g.isObject)(t)&&(0,l.assign)(e.config,t,{shallow:!1});break;case c.Commands.Consent:(0,g.isObject)(t)&&(o=await P(e,t));break;case c.Commands.Custom:(0,g.isObject)(t)&&(e.custom=(0,l.assign)(e.custom,t));break;case c.Commands.Destination:(0,g.isObject)(t)&&(0,l.isFunction)(t.push)&&(o=await k(e,{code:t},s));break;case c.Commands.Globals:(0,g.isObject)(t)&&(e.globals=(0,l.assign)(e.globals,t));break;case c.Commands.On:(0,l.isString)(t)&&m(e,t,s);break;case c.Commands.Ready:h(e,"ready");break;case c.Commands.Run:o=await w(e,t);break;case c.Commands.Session:h(e,"session");break;case c.Commands.User:(0,g.isObject)(t)&&(0,l.assign)(e.user,t,{shallow:!1})}return o||{ok:!0,successful:[],queued:[],failed:[]}}function b(e,n,t={}){const s=(0,g.isSameType)(n,"")?{name:n,...t}:{...t,...n||{}};if(!s.name)throw new Error("Event name is required");const[o,a]=s.name.split(" ");if(!o||!a)throw new Error("Event name is invalid");if(o===i.Walker)return{command:a};++e.count;const{timestamp:c=Date.now(),group:r=e.group,count:u=e.count}=s,{name:l=`${o} ${a}`,data:d={},context:f={},globals:m=e.globals,custom:h={},user:p=e.user,nested:b=[],consent:w=e.consent,id:y=`${c}-${r}-${u}`,trigger:k="",entity:v=o,action:C=a,timing:q=0,version:O={source:e.version,tagging:e.config.tagging||0},source:j={type:"collector",id:"",previous_id:""}}=s;return{event:{name:l,data:d,context:f,globals:m,custom:h,user:p,nested:b,consent:w,id:y,trigger:k,entity:v,action:C,timestamp:c,timing:q,group:r,count:u,version:O,source:j}}}async function w(e,n){e.allowed=!0,e.count=0,e.group=(0,l.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,l.assign)(e.consent,n.consent)),n.user&&(e.user=(0,l.assign)(e.user,n.user)),n.globals&&(e.globals=(0,l.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,l.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await v(e);return h(e,"run"),t}function y(e,n,t){return(0,u.useHooks)(async(s,o,a)=>await(0,u.tryCatchAsync)(async()=>{if("string"==typeof s&&s.startsWith("walker ")){const t=s.replace("walker ","");return await n(e,t,o,a)}{const i=t("string"==typeof s?{name:s}:s),{event:c,command:r}=b(e,i.name,i);return r?await n(e,r,o,a):await v(e,c)}},()=>O({ok:!1}))(),"Push",e.hooks)}async function k(e,n,t){const{code:s,config:o={},env:a={}}=n,i=t||o||{init:!1},c={...s,config:i,env:E(s.env,a)};let r=c.config.id;if(!r)do{r=(0,u.getId)(4)}while(e.destinations[r]);return e.destinations[r]=c,!1!==c.config.queue&&(c.queue=[...e.queue]),v(e,void 0,{[r]:c})}async function v(e,n,t){const{allowed:s,consent:o,globals:a,user:i}=e;if(!s)return O({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const c=await Promise.all(Object.entries(t||{}).map(async([t,s])=>{let c=(s.queue||[]).map(e=>({...e,consent:o}));if(s.queue=[],n){let t=(0,u.clone)(n);await Promise.all(Object.entries(s.config.policy||[]).map(async([s,o])=>{const a=await(0,u.getMappingValue)(n,o,{collector:e});t=(0,u.setByPath)(t,s,a)})),c.push(t)}if(!c.length)return{id:t,destination:s,skipped:!0};const r=[],l=c.filter(e=>{const n=(0,u.getGrantedConsent)(s.config.consent,o,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(s.queue.concat(l),!r.length)return{id:t,destination:s,queue:c};if(!await(0,u.tryCatchAsync)(C)(e,s))return{id:t,destination:s,queue:c};let g=!1;return s.dlq||(s.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,u.assign)(a,n.globals),n.user=(0,u.assign)(i,n.user),await(0,u.tryCatchAsync)(q,t=>(e.config.onError&&e.config.onError(t,e),g=!0,s.dlq.push([n,t]),!1))(e,s,n),n))),{id:t,destination:s,error:g}})),r=[],l=[],g=[];for(const e of c){if(e.skipped)continue;const n=e.destination,t={id:e.id,destination:n};e.error?g.push(t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),l.push(t)):r.push(t)}return O({ok:!g.length,event:n,successful:r,queued:l,failed:g})}async function C(e,n){if(n.init&&!n.config.init){const t={collector:e,config:n.config,env:E(n.env,n.config.env)},s=await(0,u.useHooks)(n.init,"DestinationInit",e.hooks)(t);if(!1===s)return s;n.config={...s||n.config,init:!0}}return!0}async function q(e,n,t){const{config:s}=n,{eventMapping:o,mappingKey:a}=await(0,u.getMappingEvent)(t,s.mapping);let i=s.data&&await(0,u.getMappingValue)(t,s.data,{collector:e});if(o){if(o.ignore)return!1;if(o.name&&(t.name=o.name),o.data){const n=o.data&&await(0,u.getMappingValue)(t,o.data,{collector:e});i=(0,u.isObject)(i)&&(0,u.isObject)(n)?(0,u.assign)(i,n):n}}const c={collector:e,config:s,data:i,mapping:o,env:E(n.env,s.env)};if(o?.batch&&n.pushBatch){const c=o.batched||{key:a||"",events:[],data:[]};c.events.push(t),(0,u.isDefined)(i)&&c.data.push(i),o.batchFn=o.batchFn||(0,u.debounce)((e,n)=>{const t={collector:n,config:s,data:i,mapping:o,env:E(e.env,s.env)};(0,u.useHooks)(e.pushBatch,"DestinationPushBatch",n.hooks)(c,t),c.events=[],c.data=[]},o.batch),o.batched=c,o.batchFn?.(n,e)}else await(0,u.useHooks)(n.push,"DestinationPush",e.hooks)(t,c);return!0}function O(e){return(0,u.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function j(e,n={}){const t={};for(const[e,s]of Object.entries(n)){const{code:n,config:o={},env:a={}}=s,i={...n.config,...o},c=E(n.env,a);t[e]={...n,config:i,env:c}}return t}function E(e,n){return e||n?n?e&&(0,u.isObject)(e)&&(0,u.isObject)(n)?{...e,...n}:n:e:{}}async function P(e,n){const{consent:t}=e;let s=!1;const o={};return Object.entries(n).forEach(([e,n])=>{const t=!!n;o[e]=t,s=s||t}),e.consent=(0,r.assign)(t,o),h(e,"consent",void 0,o),s?v(e):O({ok:!0})}var D=require("@walkeros/core"),S=require("@walkeros/core");async function R(e,n={}){const t={};for(const[s,o]of Object.entries(n)){const{code:n,config:a={},env:i={},primary:c}=o,r={elb:(...n)=>e.push(...n),...i},u=await(0,S.tryCatchAsync)(n)(a,r);u&&(c&&(u.config={...u.config,primary:c}),t[s]=u)}return t}async function A(e){e=e||{};const n=await async function(e){const n={globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:s,run:!0},t=(0,D.assign)(n,e,{merge:!1,extend:!1});function s(e,n){(0,D.onLog)({message:e},n||t.verbose)}t.onLog=s;const o={...t.globalsStatic,...e.globals},a={allowed:!1,config:t,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:o,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.2.0",sources:{},push:void 0};return a.push=y(a,p,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.sources=await R(a,e.sources||{}),a.destinations=await j(0,e.destinations||{}),a}(e),{consent:t,user:s,globals:o,custom:a}=e;t&&await n.push("walker consent",t),s&&await n.push("walker user",s),o&&Object.assign(n.globals,o),a&&Object.assign(n.custom,a),n.config.run&&await n.push("walker run");let i=n.push;const c=Object.values(n.sources),r=c.find(e=>e.config.primary);return r?i=r.push:c.length>0&&(i=c[0].push),{collector:n,elb:i}}//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/index.ts","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/handle.ts","../src/on.ts","../src/collector.ts","../src/source.ts"],"sourcesContent":["{\n \"name\": \"@walkeros/collector\",\n \"description\": \"Unified platform-agnostic collector for walkerOS\",\n \"version\": \"0.1.2\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"files\": [\n \"dist/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup --silent\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist\",\n \"dev\": \"jest --watchAll --colors\",\n \"lint\": \"tsc && eslint \\\"**/*.ts*\\\"\",\n \"test\": \"jest\",\n \"update\": \"npx npm-check-updates -u && npm update\"\n },\n \"dependencies\": {\n \"@walkeros/core\": \"0.1.2\"\n },\n \"devDependencies\": {},\n \"repository\": {\n \"url\": \"git+https://github.com/elbwalker/walkerOS.git\",\n \"directory\": \"packages/collector\"\n },\n \"author\": \"elbwalker <hello@elbwalker.com>\",\n \"homepage\": \"https://github.com/elbwalker/walkerOS#readme\",\n \"bugs\": {\n \"url\": \"https://github.com/elbwalker/walkerOS/issues\"\n },\n \"keywords\": [\n \"walker\",\n \"walkerOS\",\n \"analytics\",\n \"tracking\",\n \"data collection\",\n \"measurement\",\n \"data privacy\",\n \"privacy friendly\",\n \"collector\",\n \"event processing\"\n ],\n \"funding\": [\n {\n \"type\": \"GitHub Sponsors\",\n \"url\": \"https://github.com/sponsors/elbwalker\"\n }\n ]\n}\n","export * from './types';\n\nexport * from './constants';\nexport * from './consent';\nexport * from './collector';\nexport * from './destination';\nexport * from './handle';\nexport * from './on';\nexport * from './source';\n","import type { Collector } from '@walkeros/core';\nimport type { WalkerOS } from '@walkeros/core';\n\nexport type CommandTypes =\n | 'Action'\n | 'Actions'\n | 'Config'\n | 'Consent'\n | 'Context'\n | 'Custom'\n | 'Destination'\n | 'Elb'\n | 'Globals'\n | 'Hook'\n | 'Init'\n | 'Link'\n | 'On'\n | 'Prefix'\n | 'Ready'\n | 'Run'\n | 'Session'\n | 'User'\n | 'Walker';\n\nexport const Commands: Record<CommandTypes, Collector.CommandType> = {\n Action: 'action',\n Actions: 'actions',\n Config: 'config',\n Consent: 'consent',\n Context: 'context',\n Custom: 'custom',\n Destination: 'destination',\n Elb: 'elb',\n Globals: 'globals',\n Hook: 'hook',\n Init: 'init',\n Link: 'link',\n On: 'on',\n Prefix: 'data-elb',\n Ready: 'ready',\n Run: 'run',\n Session: 'session',\n User: 'user',\n Walker: 'walker',\n} as const;\n\nexport type StorageType = 'cookie' | 'local' | 'session';\n\nconst UtilsStorage: { [key: string]: StorageType } = {\n Cookie: 'cookie',\n Local: 'local',\n Session: 'session',\n} as const;\n\nconst Utils = {\n Storage: UtilsStorage,\n};\n\nexport const Const = {\n Commands,\n Utils,\n};\n\nexport default Const;\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport { assign } from '@walkeros/core';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { onApply } from './on';\n\n/**\n * Sets the consent state and processes the queue.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The consent data to set.\n * @returns The result of the push operation.\n */\nexport async function setConsent(\n collector: Collector.Instance,\n data: WalkerOS.Consent,\n): Promise<Elb.PushResult> {\n const { consent } = collector;\n\n let runQueue = false;\n const update: WalkerOS.Consent = {};\n Object.entries(data).forEach(([name, granted]) => {\n const state = !!granted;\n\n update[name] = state;\n\n // Only run queue if state was set to true\n runQueue = runQueue || state;\n });\n\n // Update consent state\n collector.consent = assign(consent, update);\n\n // Run on consent events\n onApply(collector, 'consent', undefined, update);\n\n // Process previous events if not disabled\n return runQueue\n ? pushToDestinations(collector)\n : createPushResult({ ok: true });\n}\n","import type { Collector, WalkerOS, Elb, Destination } from '@walkeros/core';\nimport {\n assign,\n clone,\n debounce,\n getId,\n getGrantedConsent,\n getMappingEvent,\n getMappingValue,\n isDefined,\n isObject,\n setByPath,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEventOrCommand } from './handle';\n\nexport type HandleCommandFn<T extends Collector.Instance> = (\n collector: T,\n action: string,\n data?: Elb.PushData,\n options?: unknown,\n) => Promise<Elb.PushResult>;\n\n/**\n * Creates the main push function for the collector.\n *\n * @template T, F\n * @param collector - The walkerOS collector instance.\n * @param handleCommand - TBD.\n * @param prepareEvent - TBD.\n * @returns The push function.\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Elb.Fn {\n return useHooks(\n async (\n eventOrCommand: unknown,\n data?: Elb.PushData,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n // Handle simplified core collector interface\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n // Walker command format: 'walker action', data, options\n const command = eventOrCommand.replace('walker ', '');\n return await handleCommand(collector, command, data, options);\n } else {\n // Event format: event object or string\n const partialEvent =\n typeof eventOrCommand === 'string'\n ? { name: eventOrCommand }\n : (eventOrCommand as WalkerOS.DeepPartialEvent);\n\n const enrichedEvent = prepareEvent(partialEvent);\n\n const { event, command } = createEventOrCommand(\n collector,\n enrichedEvent.name,\n enrichedEvent,\n );\n\n const result = command\n ? await handleCommand(collector, command, data, options)\n : await pushToDestinations(collector, event);\n\n return result;\n }\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Elb.Fn;\n}\n\n/**\n * Adds a new destination to the collector.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The destination's init data.\n * @param options - The destination's config.\n * @returns The result of the push operation.\n */\nexport async function addDestination(\n collector: Collector.Instance,\n data: Destination.Init,\n options?: Destination.Config,\n): Promise<Elb.PushResult> {\n const { code, config: dataConfig = {}, env = {} } = data;\n const config = options || dataConfig || { init: false };\n\n const destination: Destination.Instance = {\n ...code,\n config,\n env: mergeEnvironments(code.env, env),\n };\n\n let id = destination.config.id; // Use given id\n if (!id) {\n // Generate a new id if none was given\n do {\n id = getId(4);\n } while (collector.destinations[id]);\n }\n\n // Add the destination\n collector.destinations[id] = destination;\n\n // Process previous events if not disabled\n if (destination.config.queue !== false)\n destination.queue = [...collector.queue];\n\n return pushToDestinations(collector, undefined, { [id]: destination });\n}\n\n/**\n * Pushes an event to all or a subset of destinations.\n *\n * @param collector - The walkerOS collector instance.\n * @param event - The event to push.\n * @param destinations - The destinations to push to.\n * @returns The result of the push operation.\n */\nexport async function pushToDestinations(\n collector: Collector.Instance,\n event?: WalkerOS.Event,\n destinations?: Collector.Destinations,\n): Promise<Elb.PushResult> {\n const { allowed, consent, globals, user } = collector;\n\n // Check if collector is allowed to push\n if (!allowed) return createPushResult({ ok: false });\n\n // Add event to the collector queue\n if (event) collector.queue.push(event);\n\n // Use given destinations or use internal destinations\n if (!destinations) destinations = collector.destinations;\n\n const results = await Promise.all(\n // Process all destinations in parallel\n Object.entries(destinations || {}).map(async ([id, destination]) => {\n // Create a queue of events to be processed\n let currentQueue = (destination.queue || []).map((event) => ({\n ...event,\n consent,\n }));\n\n // Reset original queue while processing to enable async processing\n destination.queue = [];\n\n // Add event to queue stack\n if (event) {\n // Clone the event to avoid mutating the original event\n let currentEvent = clone(event);\n\n // Policy check\n await Promise.all(\n Object.entries(destination.config.policy || []).map(\n async ([key, mapping]) => {\n const value = await getMappingValue(event, mapping, {\n collector,\n });\n currentEvent = setByPath(currentEvent, key, value);\n },\n ),\n );\n\n // Add event to queue stack\n currentQueue.push(currentEvent);\n }\n\n // Nothing to do here if the queue is empty\n if (!currentQueue.length) return { id, destination, skipped: true };\n\n const allowedEvents: WalkerOS.Events = [];\n const skippedEvents = currentQueue.filter((queuedEvent) => {\n const grantedConsent = getGrantedConsent(\n destination.config.consent, // Required\n consent, // Current collector state\n queuedEvent.consent, // Individual event state\n );\n\n if (grantedConsent) {\n queuedEvent.consent = grantedConsent; // Save granted consent states only\n\n allowedEvents.push(queuedEvent); // Add to allowed queue\n return false; // Remove from destination queue\n }\n\n return true; // Keep denied events in the queue\n });\n\n // Add skipped events back to the queue\n destination.queue.concat(skippedEvents);\n\n // Execution shall not pass if no events are allowed\n if (!allowedEvents.length) {\n return { id, destination, queue: currentQueue }; // Don't push if not allowed\n }\n\n // Initialize the destination if needed\n const isInitialized = await tryCatchAsync(destinationInit)(\n collector,\n destination,\n );\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error = false;\n if (!destination.dlq) destination.dlq = [];\n\n // Process allowed events and store failed ones in the dead letter queue (DLQ)\n await Promise.all(\n allowedEvents.map(async (event) => {\n // Merge event with collector state, prioritizing event properties\n event.globals = assign(globals, event.globals);\n event.user = assign(user, event.user);\n\n await tryCatchAsync(destinationPush, (err) => {\n // Call custom error handling if available\n if (collector.config.onError)\n collector.config.onError(err, collector);\n error = true; // oh no\n\n // Add failed event to destinations DLQ\n destination.dlq!.push([event, err]);\n\n return false;\n })(collector, destination, event);\n\n return event;\n }),\n );\n\n return { id, destination, error };\n }),\n );\n\n const successful = [];\n const queued = [];\n const failed = [];\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n\n const ref = { id: result.id, destination };\n\n if (result.error) {\n failed.push(ref);\n } else if (result.queue && result.queue.length) {\n // Merge queue with existing queue\n destination.queue = (destination.queue || []).concat(result.queue);\n queued.push(ref);\n } else {\n successful.push(ref);\n }\n }\n\n return createPushResult({\n ok: !failed.length,\n event,\n successful,\n queued,\n failed,\n });\n}\n\n/**\n * Initializes a destination.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to initialize.\n * @returns Whether the destination was initialized successfully.\n */\nexport async function destinationInit<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n const context: Destination.Context = {\n collector,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n const configResult = await useHooks(\n destination.init,\n 'DestinationInit',\n collector.hooks,\n )(context);\n\n // Actively check for errors (when false)\n if (configResult === false) return configResult; // don't push if init is false\n\n // Update the destination config if it was returned\n destination.config = {\n ...(configResult || destination.config),\n init: true, // Remember that the destination was initialized\n };\n }\n\n return true; // Destination is ready to push\n}\n\n/**\n * Pushes an event to a single destination.\n * Handles mapping, batching, and consent checks.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to push to.\n * @param event - The event to push.\n * @returns Whether the event was pushed successfully.\n */\nexport async function destinationPush<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n event: WalkerOS.Event,\n): Promise<boolean> {\n const { config } = destination;\n const { eventMapping, mappingKey } = await getMappingEvent(\n event,\n config.mapping,\n );\n\n let data =\n config.data && (await getMappingValue(event, config.data, { collector }));\n\n if (eventMapping) {\n // Check if event should be processed or ignored\n if (eventMapping.ignore) return false;\n\n // Check to use specific event names\n if (eventMapping.name) event.name = eventMapping.name;\n\n // Transform event to a custom data\n if (eventMapping.data) {\n const dataEvent =\n eventMapping.data &&\n (await getMappingValue(event, eventMapping.data, { collector }));\n data =\n isObject(data) && isObject(dataEvent) // Only merge objects\n ? assign(data, dataEvent)\n : dataEvent;\n }\n }\n\n const context: Destination.PushContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n if (eventMapping?.batch && destination.pushBatch) {\n const batched = eventMapping.batched || {\n key: mappingKey || '',\n events: [],\n data: [],\n };\n batched.events.push(event);\n if (isDefined(data)) batched.data.push(data);\n\n eventMapping.batchFn =\n eventMapping.batchFn ||\n debounce((destination, collector) => {\n const batchContext: Destination.PushBatchContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n (collector as Collector.Instance).hooks,\n )(batched, batchContext);\n\n // Reset the batched queues\n batched.events = [];\n batched.data = [];\n }, eventMapping.batch);\n\n eventMapping.batched = batched;\n eventMapping.batchFn?.(destination, collector);\n } else {\n // It's time to go to the destination's side now\n await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(event, context);\n }\n\n return true;\n}\n\n/**\n * Creates a standardized result object for push operations.\n *\n * @param partialResult - A partial result to merge with the default result.\n * @returns The push result.\n */\nexport function createPushResult(\n partialResult?: Partial<Elb.PushResult>,\n): Elb.PushResult {\n return assign(\n {\n ok: !partialResult?.failed?.length,\n successful: [],\n queued: [],\n failed: [],\n },\n partialResult,\n );\n}\n\n/**\n * Initializes a map of destinations using ONLY the unified code/config/env pattern.\n * Does NOT call destination.init() - that happens later during push with proper consent checks.\n *\n * @param destinations - The destinations to initialize.\n * @param collector - The collector instance for destination init context.\n * @returns The initialized destinations.\n */\nexport async function initDestinations(\n _collector: Collector.Instance,\n destinations: Destination.InitDestinations = {},\n): Promise<Collector.Destinations> {\n const result: Collector.Destinations = {};\n\n for (const [name, destinationDef] of Object.entries(destinations)) {\n const { code, config = {}, env = {} } = destinationDef;\n\n // Merge config: destination default + provided config\n const mergedConfig = {\n ...code.config,\n ...config,\n };\n\n // Merge environment: destination default + provided env\n const mergedEnv = mergeEnvironments(code.env, env);\n\n // Create destination instance by spreading code and overriding config/env\n result[name] = {\n ...code,\n config: mergedConfig,\n env: mergedEnv,\n };\n }\n\n return result;\n}\n\n/**\n * Merges destination environment with config environment\n * Config env takes precedence over destination env for overrides\n */\nfunction mergeEnvironments(\n destinationEnv?: Destination.Environment,\n configEnv?: Destination.Environment,\n): Destination.Environment {\n // If neither environment exists, return empty object\n if (!destinationEnv && !configEnv) return {};\n\n // If only one exists, return it\n if (!configEnv) return destinationEnv!;\n if (!destinationEnv) return configEnv;\n\n // Both exist - merge objects with configEnv taking precedence\n if (isObject(destinationEnv) && isObject(configEnv)) {\n return { ...destinationEnv, ...configEnv };\n }\n\n // If they're not both objects, config env overrides destination env\n return configEnv;\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Commands, Const } from './constants';\nimport { addDestination, pushToDestinations } from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject, isSameType } from '@walkeros/core';\nimport { setConsent } from './consent';\nimport { on, onApply } from './on';\nimport type { RunState } from './types/collector';\n\n/**\n * Handles common commands.\n *\n * @param collector The walkerOS collector instance.\n * @param action The action to handle.\n * @param data The data to handle.\n * @param options The options to handle.\n * @returns A promise that resolves with the push result or undefined.\n */\nexport async function commonHandleCommand(\n collector: Collector.Instance,\n action: string,\n data?: unknown,\n options?: unknown,\n): Promise<Elb.PushResult> {\n let result: Elb.PushResult | undefined;\n switch (action) {\n case Const.Commands.Config:\n if (isObject(data)) {\n assign(collector.config, data as Partial<Collector.Config>, {\n shallow: false,\n });\n }\n break;\n\n case Const.Commands.Consent:\n if (isObject(data)) {\n result = await setConsent(collector, data as WalkerOS.Consent);\n }\n break;\n\n case Const.Commands.Custom:\n if (isObject(data)) {\n collector.custom = assign(\n collector.custom,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.Destination:\n if (isObject(data) && isFunction(data.push)) {\n result = await addDestination(\n collector,\n { code: data as unknown as Destination.Instance },\n options as Destination.Config,\n );\n }\n break;\n\n case Const.Commands.Globals:\n if (isObject(data)) {\n collector.globals = assign(\n collector.globals,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.On:\n if (isString(data)) {\n on(\n collector,\n data as On.Types,\n options as WalkerOS.SingleOrArray<On.Options>,\n );\n }\n break;\n\n case Const.Commands.Ready:\n onApply(collector, 'ready');\n break;\n\n case Const.Commands.Run:\n result = await runCollector(collector, data as RunState);\n break;\n\n case Const.Commands.Session:\n onApply(collector, 'session');\n break;\n\n case Const.Commands.User:\n if (isObject(data)) {\n assign(collector.user, data as WalkerOS.User, { shallow: false });\n }\n break;\n }\n\n return (\n result || {\n ok: true,\n successful: [],\n queued: [],\n failed: [],\n }\n );\n}\n\n/**\n * Creates an event or a command from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param nameOrEvent The name of the event or a partial event.\n * @param defaults The default values for the event.\n * @returns An object with the event or the command.\n */\nexport function createEventOrCommand(\n collector: Collector.Instance,\n nameOrEvent: unknown,\n defaults: WalkerOS.PartialEvent = {},\n): { event?: WalkerOS.Event; command?: string } {\n // Determine the partial event\n const partialEvent: WalkerOS.PartialEvent = isSameType(\n nameOrEvent,\n '' as string,\n )\n ? { name: nameOrEvent, ...defaults }\n : { ...defaults, ...(nameOrEvent || {}) };\n\n if (!partialEvent.name) throw new Error('Event name is required');\n\n // Check for valid entity and action event format\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n // It's a walker command\n if (entityValue === Commands.Walker) {\n return { command: actionValue };\n }\n\n // Regular event\n ++collector.count;\n\n // Values that are eventually used by other properties\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\n // Extract properties with default fallbacks\n const {\n name = `${entityValue} ${actionValue}`,\n data = {},\n context = {},\n globals = collector.globals,\n custom = {},\n user = collector.user,\n nested = [],\n consent = collector.consent,\n id = `${timestamp}-${group}-${count}`,\n trigger = '',\n entity = entityValue,\n action = actionValue,\n timing = 0,\n version = {\n source: collector.version,\n tagging: collector.config.tagging || 0,\n },\n source = { type: 'collector', id: '', previous_id: '' },\n } = partialEvent;\n\n const fullEvent: WalkerOS.Event = {\n name,\n data,\n context,\n globals,\n custom,\n user,\n nested,\n consent,\n id,\n trigger,\n entity,\n action,\n timestamp,\n timing,\n group,\n count,\n version,\n source,\n };\n\n return { event: fullEvent };\n}\n\n/**\n * Runs the collector by setting it to allowed state and processing queued events.\n *\n * @param collector The walkerOS collector instance.\n * @param state Optional state to merge with the collector (user, globals, consent, custom).\n * @returns A promise that resolves with the push result.\n */\nexport async function runCollector(\n collector: Collector.Instance,\n state?: RunState,\n): Promise<Elb.PushResult> {\n // Set the collector to allowed state\n collector.allowed = true;\n\n // Reset count and generate new group ID\n collector.count = 0;\n collector.group = getId();\n\n // Update timing for this run\n collector.timing = Date.now();\n\n // Update collector state if provided\n if (state) {\n // Update consent if provided\n if (state.consent) {\n collector.consent = assign(collector.consent, state.consent);\n }\n\n // Update user if provided\n if (state.user) {\n collector.user = assign(collector.user, state.user);\n }\n\n // Update globals if provided\n if (state.globals) {\n collector.globals = assign(\n collector.config.globalsStatic || {},\n state.globals,\n );\n }\n\n // Update custom if provided\n if (state.custom) {\n collector.custom = assign(collector.custom, state.custom);\n }\n }\n\n // Reset destination queues\n Object.values(collector.destinations).forEach((destination) => {\n destination.queue = [];\n });\n\n // Reset collector queue for this run\n collector.queue = [];\n\n // Increase round counter\n collector.round++;\n\n // Process any queued events now that the collector is allowed\n const result = await pushToDestinations(collector);\n\n // Call the predefined run events\n onApply(collector, 'run');\n\n return result;\n}\n","import type { Collector, On, WalkerOS } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\n\n/**\n * Registers a callback for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to listen for.\n * @param option The callback function or an array of callback functions.\n */\nexport function on(\n collector: Collector.Instance,\n type: On.Types,\n option: WalkerOS.SingleOrArray<On.Options>,\n) {\n const on = collector.on;\n const onType: Array<On.Options> = on[type] || [];\n const options = isArray(option) ? option : [option];\n\n options.forEach((option) => {\n onType.push(option);\n });\n\n // Update collector on state\n (on[type] as typeof onType) = onType;\n\n // Execute the on function directly\n onApply(collector, type, options);\n}\n\n/**\n * Applies all registered callbacks for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to apply the callbacks for.\n * @param options The options for the callbacks.\n * @param config The consent configuration.\n */\nexport function onApply(\n collector: Collector.Instance,\n type: On.Types,\n options?: Array<On.Options>,\n config?: WalkerOS.Consent,\n) {\n // Use the optionally provided options\n let onConfig = options || [];\n\n if (!options) {\n // Get the collector on events\n onConfig = collector.on[type] || [];\n }\n\n // Push to sources (similar to destination pattern)\n // Calculate context data once for all sources\n let contextData: unknown;\n switch (type) {\n case Const.Commands.Consent:\n contextData = config || collector.consent;\n break;\n case Const.Commands.Session:\n contextData = collector.session;\n break;\n case Const.Commands.Ready:\n case Const.Commands.Run:\n default:\n contextData = undefined;\n break;\n }\n\n Object.values(collector.sources).forEach((source) => {\n if (source.on) {\n tryCatch(source.on)(type, contextData);\n }\n });\n\n Object.values(collector.destinations).forEach((destination) => {\n if (destination.on) {\n tryCatch(destination.on)(type, contextData);\n }\n });\n\n if (!onConfig.length) return; // No on-events registered, nothing to do\n\n switch (type) {\n case Const.Commands.Consent:\n onConsent(collector, onConfig as Array<On.ConsentConfig>, config);\n break;\n case Const.Commands.Ready:\n onReady(collector, onConfig as Array<On.ReadyConfig>);\n break;\n case Const.Commands.Run:\n onRun(collector, onConfig as Array<On.RunConfig>);\n break;\n case Const.Commands.Session:\n onSession(collector, onConfig as Array<On.SessionConfig>);\n break;\n default:\n break;\n }\n}\n\nfunction onConsent(\n collector: Collector.Instance,\n onConfig: Array<On.ConsentConfig>,\n currentConsent?: WalkerOS.Consent,\n): void {\n const consentState = currentConsent || collector.consent;\n\n onConfig.forEach((consentConfig) => {\n // Collect functions whose consent keys match the rule keys directly\n // Directly execute functions whose consent keys match the rule keys\n Object.keys(consentState) // consent keys\n .filter((consent) => consent in consentConfig) // check for matching rule keys\n .forEach((consent) => {\n // Execute the function\n tryCatch(consentConfig[consent])(collector, consentState);\n });\n });\n}\n\nfunction onReady(\n collector: Collector.Instance,\n onConfig: Array<On.ReadyConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onRun(\n collector: Collector.Instance,\n onConfig: Array<On.RunConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onSession(\n collector: Collector.Instance,\n onConfig: Array<On.SessionConfig>,\n): void {\n if (!collector.session) return;\n\n onConfig.forEach((func) => {\n tryCatch(func)(collector, collector.session);\n });\n}\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport type { CreateCollector } from './types';\nimport { assign, onLog } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations, createPush } from './destination';\nimport { initSources } from './source';\n\nexport async function createCollector<\n TConfig extends Partial<Collector.Config> = Partial<Collector.Config>,\n>(initConfig: TConfig = {} as TConfig): Promise<CreateCollector> {\n const instance = await collector(initConfig);\n const { consent, user, globals, custom } = initConfig;\n\n if (consent) await instance.push('walker consent', consent);\n if (user) await instance.push('walker user', user);\n if (globals) Object.assign(instance.globals, globals);\n if (custom) Object.assign(instance.custom, custom);\n\n if (instance.config.run) await instance.push('walker run');\n\n return {\n collector: instance,\n elb: instance.push,\n };\n}\n\nasync function collector(\n initConfig: Partial<Collector.Config>,\n): Promise<Collector.Instance> {\n const { version } = require('../package.json');\n\n const defaultConfig: Collector.Config = {\n globalsStatic: {},\n sessionStatic: {},\n tagging: 0,\n verbose: false,\n onLog: log,\n run: true,\n sources: {},\n destinations: {},\n consent: {},\n user: {},\n globals: {},\n custom: {},\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n function log(message: string, verbose?: boolean) {\n onLog({ message }, verbose || config.verbose);\n }\n config.onLog = log;\n\n // Enhanced globals with static globals from config\n const finalGlobals = { ...config.globalsStatic, ...config.globals };\n\n const collector: Collector.Instance = {\n allowed: false,\n config,\n consent: config.consent || {},\n count: 0,\n custom: config.custom || {},\n destinations: {},\n globals: finalGlobals,\n group: '',\n hooks: {},\n on: {},\n queue: [],\n round: 0,\n session: undefined,\n timing: Date.now(),\n user: config.user || {},\n version,\n sources: {},\n push: undefined as unknown as Elb.Fn, // Placeholder, will be set below\n };\n\n // Set the push function with the collector reference\n collector.push = createPush(\n collector,\n commonHandleCommand,\n (event: WalkerOS.DeepPartialEvent): WalkerOS.PartialEvent =>\n ({\n timing: Math.round((Date.now() - collector.timing) / 10) / 100,\n source: { type: 'collector', id: '', previous_id: '' },\n ...event,\n }) as WalkerOS.PartialEvent,\n );\n\n // Initialize sources and destinations after collector is fully created\n collector.sources = await initSources(collector, config.sources);\n collector.destinations = await initDestinations(\n collector,\n config.destinations,\n );\n\n return collector;\n}\n","import type { Collector, Source, WalkerOS } from '@walkeros/core';\nimport { tryCatchAsync } from '@walkeros/core';\n\n/**\n * Initialize sources using the code/config/env pattern\n *\n * @param collector - The WalkerOS collector instance\n * @param sources - Map of source definitions with code/config/env\n */\nexport async function initSources(\n collector: Collector.Instance,\n sources: Source.InitSources = {},\n): Promise<Collector.Sources> {\n const result: Collector.Sources = {};\n\n for (const [sourceId, sourceDefinition] of Object.entries(sources)) {\n const { code, config = {}, env = {} } = sourceDefinition;\n\n const cleanEnv: Source.Environment = {\n elb: ((...args: Parameters<typeof collector.push>) =>\n collector.push(...args)) as typeof collector.push, // Dynamic reference to collector.push\n ...env,\n };\n\n // Call source function with config and environment separately\n const sourceInstance = await tryCatchAsync(code)(config, cleanEnv);\n\n if (!sourceInstance) continue; // Skip failed source initialization\n\n result[sourceId] = sourceInstance;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,iBAAAA,UAAAC,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,MAAQ;AAAA,MACR,aAAe;AAAA,MACf,SAAW;AAAA,MACX,MAAQ;AAAA,MACR,QAAU;AAAA,MACV,OAAS;AAAA,MACT,SAAW;AAAA,MACX,OAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA,SAAW;AAAA,QACT,OAAS;AAAA,QACT,OAAS;AAAA,QACT,KAAO;AAAA,QACP,MAAQ;AAAA,QACR,MAAQ;AAAA,QACR,QAAU;AAAA,MACZ;AAAA,MACA,cAAgB;AAAA,QACd,kBAAkB;AAAA,MACpB;AAAA,MACA,iBAAmB,CAAC;AAAA,MACpB,YAAc;AAAA,QACZ,KAAO;AAAA,QACP,WAAa;AAAA,MACf;AAAA,MACA,QAAU;AAAA,MACV,UAAY;AAAA,MACZ,MAAQ;AAAA,QACN,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,QACV;AAAA,QACA;AAA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AU,EAAE,IAAI;AAAA,MAC3D,QAAQ,EAAE,MAAM,aAAa,IAAI,IAAI,aAAa,GAAG;AAAA,MACrD,GAAG;AAAA,IACL;AAAA,EACJ;AAGA,EAAAA,WAAU,UAAU,MAAM,YAAYA,YAAW,OAAO,OAAO;AAC/D,EAAAA,WAAU,eAAe,MAAM;AAAA,IAC7BA;AAAA,IACA,OAAO;AAAA,EACT;AAEA,SAAOA;AACT;","names":["exports","module","import_core","import_core","import_core","import_core","collector","on","option","collector","collector","event","destination","collector","import_core","import_core","collector","collector"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/handle.ts","../src/on.ts","../src/collector.ts","../src/source.ts","../src/flow.ts"],"sourcesContent":["export * from './types';\n\nexport * from './constants';\nexport * from './consent';\nexport * from './flow';\nexport * from './destination';\nexport * from './handle';\nexport * from './on';\nexport * from './source';\n","import type { Collector } from '@walkeros/core';\nimport type { WalkerOS } from '@walkeros/core';\n\nexport type CommandTypes =\n | 'Action'\n | 'Actions'\n | 'Config'\n | 'Consent'\n | 'Context'\n | 'Custom'\n | 'Destination'\n | 'Elb'\n | 'Globals'\n | 'Hook'\n | 'Init'\n | 'Link'\n | 'On'\n | 'Prefix'\n | 'Ready'\n | 'Run'\n | 'Session'\n | 'User'\n | 'Walker';\n\nexport const Commands: Record<CommandTypes, Collector.CommandType> = {\n Action: 'action',\n Actions: 'actions',\n Config: 'config',\n Consent: 'consent',\n Context: 'context',\n Custom: 'custom',\n Destination: 'destination',\n Elb: 'elb',\n Globals: 'globals',\n Hook: 'hook',\n Init: 'init',\n Link: 'link',\n On: 'on',\n Prefix: 'data-elb',\n Ready: 'ready',\n Run: 'run',\n Session: 'session',\n User: 'user',\n Walker: 'walker',\n} as const;\n\nexport type StorageType = 'cookie' | 'local' | 'session';\n\nconst UtilsStorage: { [key: string]: StorageType } = {\n Cookie: 'cookie',\n Local: 'local',\n Session: 'session',\n} as const;\n\nconst Utils = {\n Storage: UtilsStorage,\n};\n\nexport const Const = {\n Commands,\n Utils,\n};\n\nexport default Const;\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport { assign } from '@walkeros/core';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { onApply } from './on';\n\n/**\n * Sets the consent state and processes the queue.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The consent data to set.\n * @returns The result of the push operation.\n */\nexport async function setConsent(\n collector: Collector.Instance,\n data: WalkerOS.Consent,\n): Promise<Elb.PushResult> {\n const { consent } = collector;\n\n let runQueue = false;\n const update: WalkerOS.Consent = {};\n Object.entries(data).forEach(([name, granted]) => {\n const state = !!granted;\n\n update[name] = state;\n\n // Only run queue if state was set to true\n runQueue = runQueue || state;\n });\n\n // Update consent state\n collector.consent = assign(consent, update);\n\n // Run on consent events\n onApply(collector, 'consent', undefined, update);\n\n // Process previous events if not disabled\n return runQueue\n ? pushToDestinations(collector)\n : createPushResult({ ok: true });\n}\n","import type { Collector, WalkerOS, Elb, Destination } from '@walkeros/core';\nimport {\n assign,\n clone,\n debounce,\n getId,\n getGrantedConsent,\n getMappingEvent,\n getMappingValue,\n isDefined,\n isObject,\n setByPath,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEventOrCommand } from './handle';\n\nexport type HandleCommandFn<T extends Collector.Instance> = (\n collector: T,\n action: string,\n data?: Elb.PushData,\n options?: unknown,\n) => Promise<Elb.PushResult>;\n\n/**\n * Creates the main push function for the collector.\n *\n * @template T, F\n * @param collector - The walkerOS collector instance.\n * @param handleCommand - TBD.\n * @param prepareEvent - TBD.\n * @returns The push function.\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Elb.Fn {\n return useHooks(\n async (\n eventOrCommand: unknown,\n data?: Elb.PushData,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n // Handle simplified core collector interface\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n // Walker command format: 'walker action', data, options\n const command = eventOrCommand.replace('walker ', '');\n return await handleCommand(collector, command, data, options);\n } else {\n // Event format: event object or string\n const partialEvent =\n typeof eventOrCommand === 'string'\n ? { name: eventOrCommand }\n : (eventOrCommand as WalkerOS.DeepPartialEvent);\n\n const enrichedEvent = prepareEvent(partialEvent);\n\n const { event, command } = createEventOrCommand(\n collector,\n enrichedEvent.name,\n enrichedEvent,\n );\n\n const result = command\n ? await handleCommand(collector, command, data, options)\n : await pushToDestinations(collector, event);\n\n return result;\n }\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Elb.Fn;\n}\n\n/**\n * Adds a new destination to the collector.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The destination's init data.\n * @param options - The destination's config.\n * @returns The result of the push operation.\n */\nexport async function addDestination(\n collector: Collector.Instance,\n data: Destination.Init,\n options?: Destination.Config,\n): Promise<Elb.PushResult> {\n const { code, config: dataConfig = {}, env = {} } = data;\n const config = options || dataConfig || { init: false };\n\n const destination: Destination.Instance = {\n ...code,\n config,\n env: mergeEnvironments(code.env, env),\n };\n\n let id = destination.config.id; // Use given id\n if (!id) {\n // Generate a new id if none was given\n do {\n id = getId(4);\n } while (collector.destinations[id]);\n }\n\n // Add the destination\n collector.destinations[id] = destination;\n\n // Process previous events if not disabled\n if (destination.config.queue !== false)\n destination.queue = [...collector.queue];\n\n return pushToDestinations(collector, undefined, { [id]: destination });\n}\n\n/**\n * Pushes an event to all or a subset of destinations.\n *\n * @param collector - The walkerOS collector instance.\n * @param event - The event to push.\n * @param destinations - The destinations to push to.\n * @returns The result of the push operation.\n */\nexport async function pushToDestinations(\n collector: Collector.Instance,\n event?: WalkerOS.Event,\n destinations?: Collector.Destinations,\n): Promise<Elb.PushResult> {\n const { allowed, consent, globals, user } = collector;\n\n // Check if collector is allowed to push\n if (!allowed) return createPushResult({ ok: false });\n\n // Add event to the collector queue\n if (event) collector.queue.push(event);\n\n // Use given destinations or use internal destinations\n if (!destinations) destinations = collector.destinations;\n\n const results = await Promise.all(\n // Process all destinations in parallel\n Object.entries(destinations || {}).map(async ([id, destination]) => {\n // Create a queue of events to be processed\n let currentQueue = (destination.queue || []).map((event) => ({\n ...event,\n consent,\n }));\n\n // Reset original queue while processing to enable async processing\n destination.queue = [];\n\n // Add event to queue stack\n if (event) {\n // Clone the event to avoid mutating the original event\n let currentEvent = clone(event);\n\n // Policy check\n await Promise.all(\n Object.entries(destination.config.policy || []).map(\n async ([key, mapping]) => {\n const value = await getMappingValue(event, mapping, {\n collector,\n });\n currentEvent = setByPath(currentEvent, key, value);\n },\n ),\n );\n\n // Add event to queue stack\n currentQueue.push(currentEvent);\n }\n\n // Nothing to do here if the queue is empty\n if (!currentQueue.length) return { id, destination, skipped: true };\n\n const allowedEvents: WalkerOS.Events = [];\n const skippedEvents = currentQueue.filter((queuedEvent) => {\n const grantedConsent = getGrantedConsent(\n destination.config.consent, // Required\n consent, // Current collector state\n queuedEvent.consent, // Individual event state\n );\n\n if (grantedConsent) {\n queuedEvent.consent = grantedConsent; // Save granted consent states only\n\n allowedEvents.push(queuedEvent); // Add to allowed queue\n return false; // Remove from destination queue\n }\n\n return true; // Keep denied events in the queue\n });\n\n // Add skipped events back to the queue\n destination.queue.concat(skippedEvents);\n\n // Execution shall not pass if no events are allowed\n if (!allowedEvents.length) {\n return { id, destination, queue: currentQueue }; // Don't push if not allowed\n }\n\n // Initialize the destination if needed\n const isInitialized = await tryCatchAsync(destinationInit)(\n collector,\n destination,\n );\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error = false;\n if (!destination.dlq) destination.dlq = [];\n\n // Process allowed events and store failed ones in the dead letter queue (DLQ)\n await Promise.all(\n allowedEvents.map(async (event) => {\n // Merge event with collector state, prioritizing event properties\n event.globals = assign(globals, event.globals);\n event.user = assign(user, event.user);\n\n await tryCatchAsync(destinationPush, (err) => {\n // Call custom error handling if available\n if (collector.config.onError)\n collector.config.onError(err, collector);\n error = true; // oh no\n\n // Add failed event to destinations DLQ\n destination.dlq!.push([event, err]);\n\n return false;\n })(collector, destination, event);\n\n return event;\n }),\n );\n\n return { id, destination, error };\n }),\n );\n\n const successful = [];\n const queued = [];\n const failed = [];\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n\n const ref = { id: result.id, destination };\n\n if (result.error) {\n failed.push(ref);\n } else if (result.queue && result.queue.length) {\n // Merge queue with existing queue\n destination.queue = (destination.queue || []).concat(result.queue);\n queued.push(ref);\n } else {\n successful.push(ref);\n }\n }\n\n return createPushResult({\n ok: !failed.length,\n event,\n successful,\n queued,\n failed,\n });\n}\n\n/**\n * Initializes a destination.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to initialize.\n * @returns Whether the destination was initialized successfully.\n */\nexport async function destinationInit<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n const context: Destination.Context = {\n collector,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n const configResult = await useHooks(\n destination.init,\n 'DestinationInit',\n collector.hooks,\n )(context);\n\n // Actively check for errors (when false)\n if (configResult === false) return configResult; // don't push if init is false\n\n // Update the destination config if it was returned\n destination.config = {\n ...(configResult || destination.config),\n init: true, // Remember that the destination was initialized\n };\n }\n\n return true; // Destination is ready to push\n}\n\n/**\n * Pushes an event to a single destination.\n * Handles mapping, batching, and consent checks.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to push to.\n * @param event - The event to push.\n * @returns Whether the event was pushed successfully.\n */\nexport async function destinationPush<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n event: WalkerOS.Event,\n): Promise<boolean> {\n const { config } = destination;\n const { eventMapping, mappingKey } = await getMappingEvent(\n event,\n config.mapping,\n );\n\n let data =\n config.data && (await getMappingValue(event, config.data, { collector }));\n\n if (eventMapping) {\n // Check if event should be processed or ignored\n if (eventMapping.ignore) return false;\n\n // Check to use specific event names\n if (eventMapping.name) event.name = eventMapping.name;\n\n // Transform event to a custom data\n if (eventMapping.data) {\n const dataEvent =\n eventMapping.data &&\n (await getMappingValue(event, eventMapping.data, { collector }));\n data =\n isObject(data) && isObject(dataEvent) // Only merge objects\n ? assign(data, dataEvent)\n : dataEvent;\n }\n }\n\n const context: Destination.PushContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n if (eventMapping?.batch && destination.pushBatch) {\n const batched = eventMapping.batched || {\n key: mappingKey || '',\n events: [],\n data: [],\n };\n batched.events.push(event);\n if (isDefined(data)) batched.data.push(data);\n\n eventMapping.batchFn =\n eventMapping.batchFn ||\n debounce((destination, collector) => {\n const batchContext: Destination.PushBatchContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n (collector as Collector.Instance).hooks,\n )(batched, batchContext);\n\n // Reset the batched queues\n batched.events = [];\n batched.data = [];\n }, eventMapping.batch);\n\n eventMapping.batched = batched;\n eventMapping.batchFn?.(destination, collector);\n } else {\n // It's time to go to the destination's side now\n await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(event, context);\n }\n\n return true;\n}\n\n/**\n * Creates a standardized result object for push operations.\n *\n * @param partialResult - A partial result to merge with the default result.\n * @returns The push result.\n */\nexport function createPushResult(\n partialResult?: Partial<Elb.PushResult>,\n): Elb.PushResult {\n return assign(\n {\n ok: !partialResult?.failed?.length,\n successful: [],\n queued: [],\n failed: [],\n },\n partialResult,\n );\n}\n\n/**\n * Initializes a map of destinations using ONLY the unified code/config/env pattern.\n * Does NOT call destination.init() - that happens later during push with proper consent checks.\n *\n * @param destinations - The destinations to initialize.\n * @param collector - The collector instance for destination init context.\n * @returns The initialized destinations.\n */\nexport async function initDestinations(\n _collector: Collector.Instance,\n destinations: Destination.InitDestinations = {},\n): Promise<Collector.Destinations> {\n const result: Collector.Destinations = {};\n\n for (const [name, destinationDef] of Object.entries(destinations)) {\n const { code, config = {}, env = {} } = destinationDef;\n\n // Merge config: destination default + provided config\n const mergedConfig = {\n ...code.config,\n ...config,\n };\n\n // Merge environment: destination default + provided env\n const mergedEnv = mergeEnvironments(code.env, env);\n\n // Create destination instance by spreading code and overriding config/env\n result[name] = {\n ...code,\n config: mergedConfig,\n env: mergedEnv,\n };\n }\n\n return result;\n}\n\n/**\n * Merges destination environment with config environment\n * Config env takes precedence over destination env for overrides\n */\nfunction mergeEnvironments(\n destinationEnv?: Destination.Env,\n configEnv?: Destination.Env,\n): Destination.Env {\n // If neither environment exists, return empty object\n if (!destinationEnv && !configEnv) return {};\n\n // If only one exists, return it\n if (!configEnv) return destinationEnv!;\n if (!destinationEnv) return configEnv;\n\n // Both exist - merge objects with configEnv taking precedence\n if (isObject(destinationEnv) && isObject(configEnv)) {\n return { ...destinationEnv, ...configEnv };\n }\n\n // If they're not both objects, config env overrides destination env\n return configEnv;\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Commands, Const } from './constants';\nimport { addDestination, pushToDestinations } from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject, isSameType } from '@walkeros/core';\nimport { setConsent } from './consent';\nimport { on, onApply } from './on';\nimport type { RunState } from './types/collector';\n\n/**\n * Handles common commands.\n *\n * @param collector The walkerOS collector instance.\n * @param action The action to handle.\n * @param data The data to handle.\n * @param options The options to handle.\n * @returns A promise that resolves with the push result or undefined.\n */\nexport async function commonHandleCommand(\n collector: Collector.Instance,\n action: string,\n data?: unknown,\n options?: unknown,\n): Promise<Elb.PushResult> {\n let result: Elb.PushResult | undefined;\n switch (action) {\n case Const.Commands.Config:\n if (isObject(data)) {\n assign(collector.config, data as Partial<Collector.Config>, {\n shallow: false,\n });\n }\n break;\n\n case Const.Commands.Consent:\n if (isObject(data)) {\n result = await setConsent(collector, data as WalkerOS.Consent);\n }\n break;\n\n case Const.Commands.Custom:\n if (isObject(data)) {\n collector.custom = assign(\n collector.custom,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.Destination:\n if (isObject(data) && isFunction(data.push)) {\n result = await addDestination(\n collector,\n { code: data as unknown as Destination.Instance },\n options as Destination.Config,\n );\n }\n break;\n\n case Const.Commands.Globals:\n if (isObject(data)) {\n collector.globals = assign(\n collector.globals,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.On:\n if (isString(data)) {\n on(\n collector,\n data as On.Types,\n options as WalkerOS.SingleOrArray<On.Options>,\n );\n }\n break;\n\n case Const.Commands.Ready:\n onApply(collector, 'ready');\n break;\n\n case Const.Commands.Run:\n result = await runCollector(collector, data as RunState);\n break;\n\n case Const.Commands.Session:\n onApply(collector, 'session');\n break;\n\n case Const.Commands.User:\n if (isObject(data)) {\n assign(collector.user, data as WalkerOS.User, { shallow: false });\n }\n break;\n }\n\n return (\n result || {\n ok: true,\n successful: [],\n queued: [],\n failed: [],\n }\n );\n}\n\n/**\n * Creates an event or a command from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param nameOrEvent The name of the event or a partial event.\n * @param defaults The default values for the event.\n * @returns An object with the event or the command.\n */\nexport function createEventOrCommand(\n collector: Collector.Instance,\n nameOrEvent: unknown,\n defaults: WalkerOS.PartialEvent = {},\n): { event?: WalkerOS.Event; command?: string } {\n // Determine the partial event\n const partialEvent: WalkerOS.PartialEvent = isSameType(\n nameOrEvent,\n '' as string,\n )\n ? { name: nameOrEvent, ...defaults }\n : { ...defaults, ...(nameOrEvent || {}) };\n\n if (!partialEvent.name) throw new Error('Event name is required');\n\n // Check for valid entity and action event format\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n // It's a walker command\n if (entityValue === Commands.Walker) {\n return { command: actionValue };\n }\n\n // Regular event\n ++collector.count;\n\n // Values that are eventually used by other properties\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\n // Extract properties with default fallbacks\n const {\n name = `${entityValue} ${actionValue}`,\n data = {},\n context = {},\n globals = collector.globals,\n custom = {},\n user = collector.user,\n nested = [],\n consent = collector.consent,\n id = `${timestamp}-${group}-${count}`,\n trigger = '',\n entity = entityValue,\n action = actionValue,\n timing = 0,\n version = {\n source: collector.version,\n tagging: collector.config.tagging || 0,\n },\n source = { type: 'collector', id: '', previous_id: '' },\n } = partialEvent;\n\n const fullEvent: WalkerOS.Event = {\n name,\n data,\n context,\n globals,\n custom,\n user,\n nested,\n consent,\n id,\n trigger,\n entity,\n action,\n timestamp,\n timing,\n group,\n count,\n version,\n source,\n };\n\n return { event: fullEvent };\n}\n\n/**\n * Runs the collector by setting it to allowed state and processing queued events.\n *\n * @param collector The walkerOS collector instance.\n * @param state Optional state to merge with the collector (user, globals, consent, custom).\n * @returns A promise that resolves with the push result.\n */\nexport async function runCollector(\n collector: Collector.Instance,\n state?: RunState,\n): Promise<Elb.PushResult> {\n // Set the collector to allowed state\n collector.allowed = true;\n\n // Reset count and generate new group ID\n collector.count = 0;\n collector.group = getId();\n\n // Update timing for this run\n collector.timing = Date.now();\n\n // Update collector state if provided\n if (state) {\n // Update consent if provided\n if (state.consent) {\n collector.consent = assign(collector.consent, state.consent);\n }\n\n // Update user if provided\n if (state.user) {\n collector.user = assign(collector.user, state.user);\n }\n\n // Update globals if provided\n if (state.globals) {\n collector.globals = assign(\n collector.config.globalsStatic || {},\n state.globals,\n );\n }\n\n // Update custom if provided\n if (state.custom) {\n collector.custom = assign(collector.custom, state.custom);\n }\n }\n\n // Reset destination queues\n Object.values(collector.destinations).forEach((destination) => {\n destination.queue = [];\n });\n\n // Reset collector queue for this run\n collector.queue = [];\n\n // Increase round counter\n collector.round++;\n\n // Process any queued events now that the collector is allowed\n const result = await pushToDestinations(collector);\n\n // Call the predefined run events\n onApply(collector, 'run');\n\n return result;\n}\n","import type { Collector, On, WalkerOS } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\n\n/**\n * Registers a callback for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to listen for.\n * @param option The callback function or an array of callback functions.\n */\nexport function on(\n collector: Collector.Instance,\n type: On.Types,\n option: WalkerOS.SingleOrArray<On.Options>,\n) {\n const on = collector.on;\n const onType: Array<On.Options> = on[type] || [];\n const options = isArray(option) ? option : [option];\n\n options.forEach((option) => {\n onType.push(option);\n });\n\n // Update collector on state\n (on[type] as typeof onType) = onType;\n\n // Execute the on function directly\n onApply(collector, type, options);\n}\n\n/**\n * Applies all registered callbacks for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to apply the callbacks for.\n * @param options The options for the callbacks.\n * @param config The consent configuration.\n */\nexport function onApply(\n collector: Collector.Instance,\n type: On.Types,\n options?: Array<On.Options>,\n config?: WalkerOS.Consent,\n) {\n // Use the optionally provided options\n let onConfig = options || [];\n\n if (!options) {\n // Get the collector on events\n onConfig = collector.on[type] || [];\n }\n\n // Calculate context data once for all sources and destinations\n let contextData: unknown;\n\n switch (type) {\n case Const.Commands.Consent:\n contextData = config || collector.consent;\n break;\n case Const.Commands.Session:\n contextData = collector.session;\n break;\n case Const.Commands.Ready:\n case Const.Commands.Run:\n default:\n contextData = undefined;\n break;\n }\n\n Object.values(collector.sources).forEach((source) => {\n if (source.on) {\n tryCatch(source.on)(type, contextData);\n }\n });\n\n Object.values(collector.destinations).forEach((destination) => {\n if (destination.on) {\n // Cast to runtime-compatible version for type safety\n const onFn = destination.on as On.OnFnRuntime;\n tryCatch(onFn)(type, contextData as On.AnyEventContext);\n }\n });\n\n if (!onConfig.length) return; // No on-events registered, nothing to do\n\n switch (type) {\n case Const.Commands.Consent:\n onConsent(collector, onConfig as Array<On.ConsentConfig>, config);\n break;\n case Const.Commands.Ready:\n onReady(collector, onConfig as Array<On.ReadyConfig>);\n break;\n case Const.Commands.Run:\n onRun(collector, onConfig as Array<On.RunConfig>);\n break;\n case Const.Commands.Session:\n onSession(collector, onConfig as Array<On.SessionConfig>);\n break;\n default:\n break;\n }\n}\n\nfunction onConsent(\n collector: Collector.Instance,\n onConfig: Array<On.ConsentConfig>,\n currentConsent?: WalkerOS.Consent,\n): void {\n const consentState = currentConsent || collector.consent;\n\n onConfig.forEach((consentConfig) => {\n // Collect functions whose consent keys match the rule keys directly\n // Directly execute functions whose consent keys match the rule keys\n Object.keys(consentState) // consent keys\n .filter((consent) => consent in consentConfig) // check for matching rule keys\n .forEach((consent) => {\n // Execute the function\n tryCatch(consentConfig[consent])(collector, consentState);\n });\n });\n}\n\nfunction onReady(\n collector: Collector.Instance,\n onConfig: Array<On.ReadyConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onRun(\n collector: Collector.Instance,\n onConfig: Array<On.RunConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onSession(\n collector: Collector.Instance,\n onConfig: Array<On.SessionConfig>,\n): void {\n if (!collector.session) return;\n\n onConfig.forEach((func) => {\n tryCatch(func)(collector, collector.session);\n });\n}\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport { assign, onLog } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations, createPush } from './destination';\nimport { initSources } from './source';\n\ndeclare const __VERSION__: string;\n\nexport async function collector(\n initConfig: Collector.InitConfig,\n): Promise<Collector.Instance> {\n const version = __VERSION__;\n\n const defaultConfig: Collector.Config = {\n globalsStatic: {},\n sessionStatic: {},\n tagging: 0,\n verbose: false,\n onLog: log,\n run: true,\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n function log(message: string, verbose?: boolean) {\n onLog({ message }, verbose || config.verbose);\n }\n config.onLog = log;\n\n // Enhanced globals with static globals from config\n const finalGlobals = { ...config.globalsStatic, ...initConfig.globals };\n\n const collector: Collector.Instance = {\n allowed: false,\n config,\n consent: initConfig.consent || {},\n count: 0,\n custom: initConfig.custom || {},\n destinations: {},\n globals: finalGlobals,\n group: '',\n hooks: {},\n on: {},\n queue: [],\n round: 0,\n session: undefined,\n timing: Date.now(),\n user: initConfig.user || {},\n version,\n sources: {},\n push: undefined as unknown as Elb.Fn, // Placeholder, will be set below\n };\n\n // Set the push function with the collector reference\n collector.push = createPush(\n collector,\n commonHandleCommand,\n (event: WalkerOS.DeepPartialEvent): WalkerOS.PartialEvent =>\n ({\n timing: Math.round((Date.now() - collector.timing) / 10) / 100,\n source: { type: 'collector', id: '', previous_id: '' },\n ...event,\n }) as WalkerOS.PartialEvent,\n );\n\n // Initialize sources and destinations after collector is fully created\n collector.sources = await initSources(collector, initConfig.sources || {});\n collector.destinations = await initDestinations(\n collector,\n initConfig.destinations || {},\n );\n\n return collector;\n}\n","import type { Collector, Source, WalkerOS } from '@walkeros/core';\nimport { tryCatchAsync } from '@walkeros/core';\n\n/**\n * Initialize sources using the code/config/env pattern\n *\n * @param collector - The WalkerOS collector instance\n * @param sources - Map of source definitions with code/config/env\n */\nexport async function initSources(\n collector: Collector.Instance,\n sources: Source.InitSources = {},\n): Promise<Collector.Sources> {\n const result: Collector.Sources = {};\n\n for (const [sourceId, sourceDefinition] of Object.entries(sources)) {\n const { code, config = {}, env = {}, primary } = sourceDefinition;\n\n const cleanEnv: Source.Env = {\n elb: ((...args: Parameters<typeof collector.push>) =>\n collector.push(...args)) as typeof collector.push, // Dynamic reference to collector.push\n ...env,\n };\n\n // Call source function with config and environment separately\n const sourceInstance = await tryCatchAsync(code)(config, cleanEnv);\n\n if (!sourceInstance) continue; // Skip failed source initialization\n\n // Store the primary flag in the source config for later access\n if (primary) {\n sourceInstance.config = { ...sourceInstance.config, primary };\n }\n\n result[sourceId] = sourceInstance;\n }\n\n return result;\n}\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport type { StartFlow } from './types';\nimport { collector } from './collector';\n\nexport async function startFlow<ElbPush extends Elb.Fn = Elb.Fn>(\n initConfig?: Collector.InitConfig,\n): Promise<StartFlow<ElbPush>> {\n initConfig = initConfig || {};\n const instance = await collector(initConfig);\n const { consent, user, globals, custom } = initConfig;\n\n if (consent) await instance.push('walker consent', consent);\n if (user) await instance.push('walker user', user);\n if (globals) Object.assign(instance.globals, globals);\n if (custom) Object.assign(instance.custom, custom);\n\n if (instance.config.run) await instance.push('walker run');\n\n // Determine the primary elb:\n // 1. Use explicitly marked primary source\n // 2. Use first source if any exist\n // 3. Fallback to collector.push\n let primaryElb: Elb.Fn = instance.push;\n\n const sources = Object.values(instance.sources);\n\n // First, check for explicitly marked primary source\n const markedPrimary = sources.find(\n (source) => (source.config as { primary?: boolean }).primary,\n );\n\n if (markedPrimary) {\n primaryElb = markedPrimary.push;\n } else if (sources.length > 0) {\n // Use first source as default\n primaryElb = sources[0].push;\n }\n\n return {\n collector: instance,\n elb: primaryElb as ElbPush,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwBO,IAAM,WAAwD;AAAA,EACnE,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,KAAK;AAAA,EACL,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,KAAK;AAAA,E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O;AAAA,IACfA;AAAA,IACA;AAAA,IACA,CAAC,WACE;AAAA,MACC,QAAQ,KAAK,OAAO,KAAK,IAAI,IAAIA,WAAU,UAAU,EAAE,IAAI;AAAA,MAC3D,QAAQ,EAAE,MAAM,aAAa,IAAI,IAAI,aAAa,GAAG;AAAA,MACrD,GAAG;AAAA,IACL;AAAA,EACJ;AAGA,EAAAA,WAAU,UAAU,MAAM,YAAYA,YAAW,WAAW,WAAW,CAAC,CAAC;AACzE,EAAAA,WAAU,eAAe,MAAM;AAAA,IAC7BA;AAAA,IACA,WAAW,gBAAgB,CAAC;AAAA,EAC9B;AAEA,SAAOA;AACT;;;AExEA,eAAsB,UACpB,YAC6B;AAC7B,eAAa,cAAc,CAAC;AAC5B,QAAM,WAAW,MAAM,UAAU,UAAU;AAC3C,QAAM,EAAE,SAAS,MAAM,SAAS,OAAO,IAAI;AAE3C,MAAI,QAAS,OAAM,SAAS,KAAK,kBAAkB,OAAO;AAC1D,MAAI,KAAM,OAAM,SAAS,KAAK,eAAe,IAAI;AACjD,MAAI,QAAS,QAAO,OAAO,SAAS,SAAS,OAAO;AACpD,MAAI,OAAQ,QAAO,OAAO,SAAS,QAAQ,MAAM;AAEjD,MAAI,SAAS,OAAO,IAAK,OAAM,SAAS,KAAK,YAAY;AAMzD,MAAI,aAAqB,SAAS;AAElC,QAAM,UAAU,OAAO,OAAO,SAAS,OAAO;AAG9C,QAAM,gBAAgB,QAAQ;AAAA,IAC5B,CAAC,WAAY,OAAO,OAAiC;AAAA,EACvD;AAEA,MAAI,eAAe;AACjB,iBAAa,cAAc;AAAA,EAC7B,WAAW,QAAQ,SAAS,GAAG;AAE7B,iBAAa,QAAQ,CAAC,EAAE;AAAA,EAC1B;AAEA,SAAO;AAAA,IACL,WAAW;AAAA,IACX,KAAK;AAAA,EACP;AACF;","names":["import_core","import_core","import_core","import_core","collector","on","option","collector","collector","event","destination","collector","import_core","import_core","collector","collector"]}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var e,n,o=Object.getOwnPropertyNames,t=(e={"package.json"(e,n){n.exports={name:"@walkeros/collector",description:"Unified platform-agnostic collector for walkerOS",version:"0.1.2",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{"@walkeros/core":"0.1.2"},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/collector"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","collector","event processing"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return n||(0,e[o(e)[0]])((n={exports:{}}).exports,n),n.exports}),s={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"},a={Commands:s,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}};import{assign as i}from"@walkeros/core";import{assign as c,clone as r,debounce as u,getId as l,getGrantedConsent as d,getMappingEvent as m,getMappingValue as f,isDefined as g,isObject as p,setByPath as h,tryCatchAsync as b,useHooks as w}from"@walkeros/core";import{assign as k,getId as v,isFunction as y,isString as C}from"@walkeros/core";import{isObject as q,isSameType as O}from"@walkeros/core";import{isArray as j}from"@walkeros/core";import{tryCatch as E}from"@walkeros/core";function S(e,n,o){const t=e.on,s=t[n]||[],a=j(o)?o:[o];a.forEach(e=>{s.push(e)}),t[n]=s,x(e,n,a)}function x(e,n,o,t){let s,i=o||[];switch(o||(i=e.on[n]||[]),n){case a.Commands.Consent:s=t||e.consent;break;case a.Commands.Session:s=e.session;break;case a.Commands.Ready:case a.Commands.Run:default:s=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&E(e.on)(n,s)}),Object.values(e.destinations).forEach(e=>{e.on&&E(e.on)(n,s)}),i.length)switch(n){case a.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,t);break;case a.Commands.Ready:case a.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{E(n)(e)})}(e,i);break;case a.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{E(n)(e,e.session)})}(e,i)}}async function D(e,n,o,t){let s;switch(n){case a.Commands.Config:q(o)&&k(e.config,o,{shallow:!1});break;case a.Commands.Consent:q(o)&&(s=await M(e,o));break;case a.Commands.Custom:q(o)&&(e.custom=k(e.custom,o));break;case a.Commands.Destination:q(o)&&y(o.push)&&(s=await A(e,{code:o},t));break;case a.Commands.Globals:q(o)&&(e.globals=k(e.globals,o));break;case a.Commands.On:C(o)&&S(e,o,t);break;case a.Commands.Ready:x(e,"ready");break;case a.Commands.Run:s=await R(e,o);break;case a.Commands.Session:x(e,"session");break;case a.Commands.User:q(o)&&k(e.user,o,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function P(e,n,o={}){const t=O(n,"")?{name:n,...o}:{...o,...n||{}};if(!t.name)throw new Error("Event name is required");const[a,i]=t.name.split(" ");if(!a||!i)throw new Error("Event name is invalid");if(a===s.Walker)return{command:i};++e.count;const{timestamp:c=Date.now(),group:r=e.group,count:u=e.count}=t,{name:l=`${a} ${i}`,data:d={},context:m={},globals:f=e.globals,custom:g={},user:p=e.user,nested:h=[],consent:b=e.consent,id:w=`${c}-${r}-${u}`,trigger:k="",entity:v=a,action:y=i,timing:C=0,version:q={source:e.version,tagging:e.config.tagging||0},source:j={type:"collector",id:"",previous_id:""}}=t;return{event:{name:l,data:d,context:m,globals:f,custom:g,user:p,nested:h,consent:b,id:w,trigger:k,entity:v,action:y,timestamp:c,timing:C,group:r,count:u,version:q,source:j}}}async function R(e,n){e.allowed=!0,e.count=0,e.group=v(),e.timing=Date.now(),n&&(n.consent&&(e.consent=k(e.consent,n.consent)),n.user&&(e.user=k(e.user,n.user)),n.globals&&(e.globals=k(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=k(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const o=await I(e);return x(e,"run"),o}function $(e,n,o){return w(async(t,s,a)=>await b(async()=>{if("string"==typeof t&&t.startsWith("walker ")){const o=t.replace("walker ","");return await n(e,o,s,a)}{const i=o("string"==typeof t?{name:t}:t),{event:c,command:r}=P(e,i.name,i);return r?await n(e,r,s,a):await I(e,c)}},()=>B({ok:!1}))(),"Push",e.hooks)}async function A(e,n,o){const{code:t,config:s={},env:a={}}=n,i=o||s||{init:!1},c={...t,config:i,env:G(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]),I(e,void 0,{[r]:c})}async function I(e,n,o){const{allowed:t,consent:s,globals:a,user:i}=e;if(!t)return B({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){let o=r(n);await Promise.all(Object.entries(t.config.policy||[]).map(async([t,s])=>{const a=await f(n,s,{collector:e});o=h(o,t,a)})),u.push(o)}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 b(L)(e,t))return{id:o,destination:t,queue:u};let g=!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 b(U,o=>(e.config.onError&&e.config.onError(o,e),g=!0,t.dlq.push([n,o]),!1))(e,t,n),n))),{id:o,destination:t,error:g}})),l=[],m=[],g=[];for(const e of u){if(e.skipped)continue;const n=e.destination,o={id:e.id,destination:n};e.error?g.push(o):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),m.push(o)):l.push(o)}return B({ok:!g.length,event:n,successful:l,queued:m,failed:g})}async function L(e,n){if(n.init&&!n.config.init){const o={collector:e,config:n.config,env:G(n.env,n.config.env)},t=await w(n.init,"DestinationInit",e.hooks)(o);if(!1===t)return t;n.config={...t||n.config,init:!0}}return!0}async function U(e,n,o){const{config:t}=n,{eventMapping:s,mappingKey:a}=await m(o,t.mapping);let i=t.data&&await f(o,t.data,{collector:e});if(s){if(s.ignore)return!1;if(s.name&&(o.name=s.name),s.data){const n=s.data&&await f(o,s.data,{collector:e});i=p(i)&&p(n)?c(i,n):n}}const r={collector:e,config:t,data:i,mapping:s,env:G(n.env,t.env)};if(s?.batch&&n.pushBatch){const c=s.batched||{key:a||"",events:[],data:[]};c.events.push(o),g(i)&&c.data.push(i),s.batchFn=s.batchFn||u((e,n)=>{const o={collector:n,config:t,data:i,mapping:s,env:G(e.env,t.env)};w(e.pushBatch,"DestinationPushBatch",n.hooks)(c,o),c.events=[],c.data=[]},s.batch),s.batched=c,s.batchFn?.(n,e)}else await w(n.push,"DestinationPush",e.hooks)(o,r);return!0}function B(e){return c({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function F(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=G(n.env,a);o[e]={...n,config:i,env:c}}return o}function G(e,n){return e||n?n?e&&p(e)&&p(n)?{...e,...n}:n:e:{}}async function M(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),x(e,"consent",void 0,s),t?I(e):B({ok:!0})}import{assign as W,onLog as _}from"@walkeros/core";import{tryCatchAsync as H}from"@walkeros/core";async function K(e,n={}){const o={};for(const[t,s]of Object.entries(n)){const{code:n,config:a={},env:i={}}=s,c={elb:(...n)=>e.push(...n),...i},r=await H(n)(a,c);r&&(o[t]=r)}return o}async function N(e={}){const n=await async function(e){const{version:n}=t(),o=W({globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:s,run:!0,sources:{},destinations:{},consent:{},user:{},globals:{},custom:{}},e,{merge:!1,extend:!1});function s(e,n){_({message:e},n||o.verbose)}o.onLog=s;const a={...o.globalsStatic,...o.globals},i={allowed:!1,config:o,consent:o.consent||{},count:0,custom:o.custom||{},destinations:{},globals:a,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:o.user||{},version:n,sources:{},push:void 0};return i.push=$(i,D,e=>({timing:Math.round((Date.now()-i.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),i.sources=await K(i,o.sources),i.destinations=await F(0,o.destinations),i}(e),{consent:o,user:s,globals:a,custom:i}=e;return o&&await n.push("walker consent",o),s&&await n.push("walker user",s),a&&Object.assign(n.globals,a),i&&Object.assign(n.custom,i),n.config.run&&await n.push("walker run"),{collector:n,elb:n.push}}export{s as Commands,a as Const,A as addDestination,D as commonHandleCommand,N as createCollector,P as createEventOrCommand,$ as createPush,B as createPushResult,L as destinationInit,U as destinationPush,F as initDestinations,K as initSources,S as on,x as onApply,I as pushToDestinations,R as runCollector,M as setConsent};//# sourceMappingURL=index.mjs.map
1
+ var 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"},e={Commands:n,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}};import{assign as o}from"@walkeros/core";import{assign as t,clone as s,debounce as a,getId as i,getGrantedConsent as c,getMappingEvent as r,getMappingValue as u,isDefined as l,isObject as m,setByPath as f,tryCatchAsync as d,useHooks as g}from"@walkeros/core";import{assign as h,getId as p,isFunction as b,isString as w}from"@walkeros/core";import{isObject as k,isSameType as v}from"@walkeros/core";import{isArray as y}from"@walkeros/core";import{tryCatch as C}from"@walkeros/core";function q(n,e,o){const t=n.on,s=t[e]||[],a=y(o)?o:[o];a.forEach(n=>{s.push(n)}),t[e]=s,E(n,e,a)}function E(n,o,t,s){let a,i=t||[];switch(t||(i=n.on[o]||[]),o){case e.Commands.Consent:a=s||n.consent;break;case e.Commands.Session:a=n.session;break;case e.Commands.Ready:case e.Commands.Run:default:a=void 0}if(Object.values(n.sources).forEach(n=>{n.on&&C(n.on)(o,a)}),Object.values(n.destinations).forEach(n=>{if(n.on){const e=n.on;C(e)(o,a)}}),i.length)switch(o){case e.Commands.Consent:!function(n,e,o){const t=o||n.consent;e.forEach(e=>{Object.keys(t).filter(n=>n in e).forEach(o=>{C(e[o])(n,t)})})}(n,i,s);break;case e.Commands.Ready:case e.Commands.Run:!function(n,e){n.allowed&&e.forEach(e=>{C(e)(n)})}(n,i);break;case e.Commands.Session:!function(n,e){if(!n.session)return;e.forEach(e=>{C(e)(n,n.session)})}(n,i)}}async function O(n,o,t,s){let a;switch(o){case e.Commands.Config:k(t)&&h(n.config,t,{shallow:!1});break;case e.Commands.Consent:k(t)&&(a=await F(n,t));break;case e.Commands.Custom:k(t)&&(n.custom=h(n.custom,t));break;case e.Commands.Destination:k(t)&&b(t.push)&&(a=await R(n,{code:t},s));break;case e.Commands.Globals:k(t)&&(n.globals=h(n.globals,t));break;case e.Commands.On:w(t)&&q(n,t,s);break;case e.Commands.Ready:E(n,"ready");break;case e.Commands.Run:a=await S(n,t);break;case e.Commands.Session:E(n,"session");break;case e.Commands.User:k(t)&&h(n.user,t,{shallow:!1})}return a||{ok:!0,successful:[],queued:[],failed:[]}}function j(e,o,t={}){const s=v(o,"")?{name:o,...t}:{...t,...o||{}};if(!s.name)throw new Error("Event name is required");const[a,i]=s.name.split(" ");if(!a||!i)throw new Error("Event name is invalid");if(a===n.Walker)return{command:i};++e.count;const{timestamp:c=Date.now(),group:r=e.group,count:u=e.count}=s,{name:l=`${a} ${i}`,data:m={},context:f={},globals:d=e.globals,custom:g={},user:h=e.user,nested:p=[],consent:b=e.consent,id:w=`${c}-${r}-${u}`,trigger:k="",entity:y=a,action:C=i,timing:q=0,version:E={source:e.version,tagging:e.config.tagging||0},source:O={type:"collector",id:"",previous_id:""}}=s;return{event:{name:l,data:m,context:f,globals:d,custom:g,user:h,nested:p,consent:b,id:w,trigger:k,entity:y,action:C,timestamp:c,timing:q,group:r,count:u,version:E,source:O}}}async function S(n,e){n.allowed=!0,n.count=0,n.group=p(),n.timing=Date.now(),e&&(e.consent&&(n.consent=h(n.consent,e.consent)),e.user&&(n.user=h(n.user,e.user)),e.globals&&(n.globals=h(n.config.globalsStatic||{},e.globals)),e.custom&&(n.custom=h(n.custom,e.custom))),Object.values(n.destinations).forEach(n=>{n.queue=[]}),n.queue=[],n.round++;const o=await x(n);return E(n,"run"),o}function D(n,e,o){return g(async(t,s,a)=>await d(async()=>{if("string"==typeof t&&t.startsWith("walker ")){const o=t.replace("walker ","");return await e(n,o,s,a)}{const i=o("string"==typeof t?{name:t}:t),{event:c,command:r}=j(n,i.name,i);return r?await e(n,r,s,a):await x(n,c)}},()=>L({ok:!1}))(),"Push",n.hooks)}async function R(n,e,o){const{code:t,config:s={},env:a={}}=e,c=o||s||{init:!1},r={...t,config:c,env:B(t.env,a)};let u=r.config.id;if(!u)do{u=i(4)}while(n.destinations[u]);return n.destinations[u]=r,!1!==r.config.queue&&(r.queue=[...n.queue]),x(n,void 0,{[u]:r})}async function x(n,e,o){const{allowed:a,consent:i,globals:r,user:l}=n;if(!a)return L({ok:!1});e&&n.queue.push(e),o||(o=n.destinations);const m=await Promise.all(Object.entries(o||{}).map(async([o,a])=>{let m=(a.queue||[]).map(n=>({...n,consent:i}));if(a.queue=[],e){let o=s(e);await Promise.all(Object.entries(a.config.policy||[]).map(async([t,s])=>{const a=await u(e,s,{collector:n});o=f(o,t,a)})),m.push(o)}if(!m.length)return{id:o,destination:a,skipped:!0};const g=[],h=m.filter(n=>{const e=c(a.config.consent,i,n.consent);return!e||(n.consent=e,g.push(n),!1)});if(a.queue.concat(h),!g.length)return{id:o,destination:a,queue:m};if(!await d(P)(n,a))return{id:o,destination:a,queue:m};let p=!1;return a.dlq||(a.dlq=[]),await Promise.all(g.map(async e=>(e.globals=t(r,e.globals),e.user=t(l,e.user),await d($,o=>(n.config.onError&&n.config.onError(o,n),p=!0,a.dlq.push([e,o]),!1))(n,a,e),e))),{id:o,destination:a,error:p}})),g=[],h=[],p=[];for(const n of m){if(n.skipped)continue;const e=n.destination,o={id:n.id,destination:e};n.error?p.push(o):n.queue&&n.queue.length?(e.queue=(e.queue||[]).concat(n.queue),h.push(o)):g.push(o)}return L({ok:!p.length,event:e,successful:g,queued:h,failed:p})}async function P(n,e){if(e.init&&!e.config.init){const o={collector:n,config:e.config,env:B(e.env,e.config.env)},t=await g(e.init,"DestinationInit",n.hooks)(o);if(!1===t)return t;e.config={...t||e.config,init:!0}}return!0}async function $(n,e,o){const{config:s}=e,{eventMapping:i,mappingKey:c}=await r(o,s.mapping);let f=s.data&&await u(o,s.data,{collector:n});if(i){if(i.ignore)return!1;if(i.name&&(o.name=i.name),i.data){const e=i.data&&await u(o,i.data,{collector:n});f=m(f)&&m(e)?t(f,e):e}}const d={collector:n,config:s,data:f,mapping:i,env:B(e.env,s.env)};if(i?.batch&&e.pushBatch){const t=i.batched||{key:c||"",events:[],data:[]};t.events.push(o),l(f)&&t.data.push(f),i.batchFn=i.batchFn||a((n,e)=>{const o={collector:e,config:s,data:f,mapping:i,env:B(n.env,s.env)};g(n.pushBatch,"DestinationPushBatch",e.hooks)(t,o),t.events=[],t.data=[]},i.batch),i.batched=t,i.batchFn?.(e,n)}else await g(e.push,"DestinationPush",n.hooks)(o,d);return!0}function L(n){return t({ok:!n?.failed?.length,successful:[],queued:[],failed:[]},n)}async function A(n,e={}){const o={};for(const[n,t]of Object.entries(e)){const{code:e,config:s={},env:a={}}=t,i={...e.config,...s},c=B(e.env,a);o[n]={...e,config:i,env:c}}return o}function B(n,e){return n||e?e?n&&m(n)&&m(e)?{...n,...e}:e:n:{}}async function F(n,e){const{consent:t}=n;let s=!1;const a={};return Object.entries(e).forEach(([n,e])=>{const o=!!e;a[n]=o,s=s||o}),n.consent=o(t,a),E(n,"consent",void 0,a),s?x(n):L({ok:!0})}import{assign as I,onLog as U}from"@walkeros/core";import{tryCatchAsync as W}from"@walkeros/core";async function G(n,e={}){const o={};for(const[t,s]of Object.entries(e)){const{code:e,config:a={},env:i={},primary:c}=s,r={elb:(...e)=>n.push(...e),...i},u=await W(e)(a,r);u&&(c&&(u.config={...u.config,primary:c}),o[t]=u)}return o}async function M(n){n=n||{};const e=await async function(n){const e=I({globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0},n,{merge:!1,extend:!1});function o(n,o){U({message:n},o||e.verbose)}e.onLog=o;const t={...e.globalsStatic,...n.globals},s={allowed:!1,config:e,consent:n.consent||{},count:0,custom:n.custom||{},destinations:{},globals:t,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:n.user||{},version:"0.2.0",sources:{},push:void 0};return s.push=D(s,O,n=>({timing:Math.round((Date.now()-s.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...n})),s.sources=await G(s,n.sources||{}),s.destinations=await A(0,n.destinations||{}),s}(n),{consent:o,user:t,globals:s,custom:a}=n;o&&await e.push("walker consent",o),t&&await e.push("walker user",t),s&&Object.assign(e.globals,s),a&&Object.assign(e.custom,a),e.config.run&&await e.push("walker run");let i=e.push;const c=Object.values(e.sources),r=c.find(n=>n.config.primary);return r?i=r.push:c.length>0&&(i=c[0].push),{collector:e,elb:i}}export{n as Commands,e as Const,R as addDestination,O as commonHandleCommand,j as createEventOrCommand,D as createPush,L as createPushResult,P as destinationInit,$ as destinationPush,A as initDestinations,G as initSources,q as on,E as onApply,x as pushToDestinations,S as runCollector,F as setConsent,M as startFlow};//# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/handle.ts","../src/on.ts","../src/collector.ts","../src/source.ts"],"sourcesContent":["{\n \"name\": \"@walkeros/collector\",\n \"description\": \"Unified platform-agnostic collector for walkerOS\",\n \"version\": \"0.1.2\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"files\": [\n \"dist/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup --silent\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist\",\n \"dev\": \"jest --watchAll --colors\",\n \"lint\": \"tsc && eslint \\\"**/*.ts*\\\"\",\n \"test\": \"jest\",\n \"update\": \"npx npm-check-updates -u && npm update\"\n },\n \"dependencies\": {\n \"@walkeros/core\": \"0.1.2\"\n },\n \"devDependencies\": {},\n \"repository\": {\n \"url\": \"git+https://github.com/elbwalker/walkerOS.git\",\n \"directory\": \"packages/collector\"\n },\n \"author\": \"elbwalker <hello@elbwalker.com>\",\n \"homepage\": \"https://github.com/elbwalker/walkerOS#readme\",\n \"bugs\": {\n \"url\": \"https://github.com/elbwalker/walkerOS/issues\"\n },\n \"keywords\": [\n \"walker\",\n \"walkerOS\",\n \"analytics\",\n \"tracking\",\n \"data collection\",\n \"measurement\",\n \"data privacy\",\n \"privacy friendly\",\n \"collector\",\n \"event processing\"\n ],\n \"funding\": [\n {\n \"type\": \"GitHub Sponsors\",\n \"url\": \"https://github.com/sponsors/elbwalker\"\n }\n ]\n}\n","import type { Collector } from '@walkeros/core';\nimport type { WalkerOS } from '@walkeros/core';\n\nexport type CommandTypes =\n | 'Action'\n | 'Actions'\n | 'Config'\n | 'Consent'\n | 'Context'\n | 'Custom'\n | 'Destination'\n | 'Elb'\n | 'Globals'\n | 'Hook'\n | 'Init'\n | 'Link'\n | 'On'\n | 'Prefix'\n | 'Ready'\n | 'Run'\n | 'Session'\n | 'User'\n | 'Walker';\n\nexport const Commands: Record<CommandTypes, Collector.CommandType> = {\n Action: 'action',\n Actions: 'actions',\n Config: 'config',\n Consent: 'consent',\n Context: 'context',\n Custom: 'custom',\n Destination: 'destination',\n Elb: 'elb',\n Globals: 'globals',\n Hook: 'hook',\n Init: 'init',\n Link: 'link',\n On: 'on',\n Prefix: 'data-elb',\n Ready: 'ready',\n Run: 'run',\n Session: 'session',\n User: 'user',\n Walker: 'walker',\n} as const;\n\nexport type StorageType = 'cookie' | 'local' | 'session';\n\nconst UtilsStorage: { [key: string]: StorageType } = {\n Cookie: 'cookie',\n Local: 'local',\n Session: 'session',\n} as const;\n\nconst Utils = {\n Storage: UtilsStorage,\n};\n\nexport const Const = {\n Commands,\n Utils,\n};\n\nexport default Const;\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport { assign } from '@walkeros/core';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { onApply } from './on';\n\n/**\n * Sets the consent state and processes the queue.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The consent data to set.\n * @returns The result of the push operation.\n */\nexport async function setConsent(\n collector: Collector.Instance,\n data: WalkerOS.Consent,\n): Promise<Elb.PushResult> {\n const { consent } = collector;\n\n let runQueue = false;\n const update: WalkerOS.Consent = {};\n Object.entries(data).forEach(([name, granted]) => {\n const state = !!granted;\n\n update[name] = state;\n\n // Only run queue if state was set to true\n runQueue = runQueue || state;\n });\n\n // Update consent state\n collector.consent = assign(consent, update);\n\n // Run on consent events\n onApply(collector, 'consent', undefined, update);\n\n // Process previous events if not disabled\n return runQueue\n ? pushToDestinations(collector)\n : createPushResult({ ok: true });\n}\n","import type { Collector, WalkerOS, Elb, Destination } from '@walkeros/core';\nimport {\n assign,\n clone,\n debounce,\n getId,\n getGrantedConsent,\n getMappingEvent,\n getMappingValue,\n isDefined,\n isObject,\n setByPath,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEventOrCommand } from './handle';\n\nexport type HandleCommandFn<T extends Collector.Instance> = (\n collector: T,\n action: string,\n data?: Elb.PushData,\n options?: unknown,\n) => Promise<Elb.PushResult>;\n\n/**\n * Creates the main push function for the collector.\n *\n * @template T, F\n * @param collector - The walkerOS collector instance.\n * @param handleCommand - TBD.\n * @param prepareEvent - TBD.\n * @returns The push function.\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Elb.Fn {\n return useHooks(\n async (\n eventOrCommand: unknown,\n data?: Elb.PushData,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n // Handle simplified core collector interface\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n // Walker command format: 'walker action', data, options\n const command = eventOrCommand.replace('walker ', '');\n return await handleCommand(collector, command, data, options);\n } else {\n // Event format: event object or string\n const partialEvent =\n typeof eventOrCommand === 'string'\n ? { name: eventOrCommand }\n : (eventOrCommand as WalkerOS.DeepPartialEvent);\n\n const enrichedEvent = prepareEvent(partialEvent);\n\n const { event, command } = createEventOrCommand(\n collector,\n enrichedEvent.name,\n enrichedEvent,\n );\n\n const result = command\n ? await handleCommand(collector, command, data, options)\n : await pushToDestinations(collector, event);\n\n return result;\n }\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Elb.Fn;\n}\n\n/**\n * Adds a new destination to the collector.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The destination's init data.\n * @param options - The destination's config.\n * @returns The result of the push operation.\n */\nexport async function addDestination(\n collector: Collector.Instance,\n data: Destination.Init,\n options?: Destination.Config,\n): Promise<Elb.PushResult> {\n const { code, config: dataConfig = {}, env = {} } = data;\n const config = options || dataConfig || { init: false };\n\n const destination: Destination.Instance = {\n ...code,\n config,\n env: mergeEnvironments(code.env, env),\n };\n\n let id = destination.config.id; // Use given id\n if (!id) {\n // Generate a new id if none was given\n do {\n id = getId(4);\n } while (collector.destinations[id]);\n }\n\n // Add the destination\n collector.destinations[id] = destination;\n\n // Process previous events if not disabled\n if (destination.config.queue !== false)\n destination.queue = [...collector.queue];\n\n return pushToDestinations(collector, undefined, { [id]: destination });\n}\n\n/**\n * Pushes an event to all or a subset of destinations.\n *\n * @param collector - The walkerOS collector instance.\n * @param event - The event to push.\n * @param destinations - The destinations to push to.\n * @returns The result of the push operation.\n */\nexport async function pushToDestinations(\n collector: Collector.Instance,\n event?: WalkerOS.Event,\n destinations?: Collector.Destinations,\n): Promise<Elb.PushResult> {\n const { allowed, consent, globals, user } = collector;\n\n // Check if collector is allowed to push\n if (!allowed) return createPushResult({ ok: false });\n\n // Add event to the collector queue\n if (event) collector.queue.push(event);\n\n // Use given destinations or use internal destinations\n if (!destinations) destinations = collector.destinations;\n\n const results = await Promise.all(\n // Process all destinations in parallel\n Object.entries(destinations || {}).map(async ([id, destination]) => {\n // Create a queue of events to be processed\n let currentQueue = (destination.queue || []).map((event) => ({\n ...event,\n consent,\n }));\n\n // Reset original queue while processing to enable async processing\n destination.queue = [];\n\n // Add event to queue stack\n if (event) {\n // Clone the event to avoid mutating the original event\n let currentEvent = clone(event);\n\n // Policy check\n await Promise.all(\n Object.entries(destination.config.policy || []).map(\n async ([key, mapping]) => {\n const value = await getMappingValue(event, mapping, {\n collector,\n });\n currentEvent = setByPath(currentEvent, key, value);\n },\n ),\n );\n\n // Add event to queue stack\n currentQueue.push(currentEvent);\n }\n\n // Nothing to do here if the queue is empty\n if (!currentQueue.length) return { id, destination, skipped: true };\n\n const allowedEvents: WalkerOS.Events = [];\n const skippedEvents = currentQueue.filter((queuedEvent) => {\n const grantedConsent = getGrantedConsent(\n destination.config.consent, // Required\n consent, // Current collector state\n queuedEvent.consent, // Individual event state\n );\n\n if (grantedConsent) {\n queuedEvent.consent = grantedConsent; // Save granted consent states only\n\n allowedEvents.push(queuedEvent); // Add to allowed queue\n return false; // Remove from destination queue\n }\n\n return true; // Keep denied events in the queue\n });\n\n // Add skipped events back to the queue\n destination.queue.concat(skippedEvents);\n\n // Execution shall not pass if no events are allowed\n if (!allowedEvents.length) {\n return { id, destination, queue: currentQueue }; // Don't push if not allowed\n }\n\n // Initialize the destination if needed\n const isInitialized = await tryCatchAsync(destinationInit)(\n collector,\n destination,\n );\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error = false;\n if (!destination.dlq) destination.dlq = [];\n\n // Process allowed events and store failed ones in the dead letter queue (DLQ)\n await Promise.all(\n allowedEvents.map(async (event) => {\n // Merge event with collector state, prioritizing event properties\n event.globals = assign(globals, event.globals);\n event.user = assign(user, event.user);\n\n await tryCatchAsync(destinationPush, (err) => {\n // Call custom error handling if available\n if (collector.config.onError)\n collector.config.onError(err, collector);\n error = true; // oh no\n\n // Add failed event to destinations DLQ\n destination.dlq!.push([event, err]);\n\n return false;\n })(collector, destination, event);\n\n return event;\n }),\n );\n\n return { id, destination, error };\n }),\n );\n\n const successful = [];\n const queued = [];\n const failed = [];\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n\n const ref = { id: result.id, destination };\n\n if (result.error) {\n failed.push(ref);\n } else if (result.queue && result.queue.length) {\n // Merge queue with existing queue\n destination.queue = (destination.queue || []).concat(result.queue);\n queued.push(ref);\n } else {\n successful.push(ref);\n }\n }\n\n return createPushResult({\n ok: !failed.length,\n event,\n successful,\n queued,\n failed,\n });\n}\n\n/**\n * Initializes a destination.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to initialize.\n * @returns Whether the destination was initialized successfully.\n */\nexport async function destinationInit<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n const context: Destination.Context = {\n collector,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n const configResult = await useHooks(\n destination.init,\n 'DestinationInit',\n collector.hooks,\n )(context);\n\n // Actively check for errors (when false)\n if (configResult === false) return configResult; // don't push if init is false\n\n // Update the destination config if it was returned\n destination.config = {\n ...(configResult || destination.config),\n init: true, // Remember that the destination was initialized\n };\n }\n\n return true; // Destination is ready to push\n}\n\n/**\n * Pushes an event to a single destination.\n * Handles mapping, batching, and consent checks.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to push to.\n * @param event - The event to push.\n * @returns Whether the event was pushed successfully.\n */\nexport async function destinationPush<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n event: WalkerOS.Event,\n): Promise<boolean> {\n const { config } = destination;\n const { eventMapping, mappingKey } = await getMappingEvent(\n event,\n config.mapping,\n );\n\n let data =\n config.data && (await getMappingValue(event, config.data, { collector }));\n\n if (eventMapping) {\n // Check if event should be processed or ignored\n if (eventMapping.ignore) return false;\n\n // Check to use specific event names\n if (eventMapping.name) event.name = eventMapping.name;\n\n // Transform event to a custom data\n if (eventMapping.data) {\n const dataEvent =\n eventMapping.data &&\n (await getMappingValue(event, eventMapping.data, { collector }));\n data =\n isObject(data) && isObject(dataEvent) // Only merge objects\n ? assign(data, dataEvent)\n : dataEvent;\n }\n }\n\n const context: Destination.PushContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n if (eventMapping?.batch && destination.pushBatch) {\n const batched = eventMapping.batched || {\n key: mappingKey || '',\n events: [],\n data: [],\n };\n batched.events.push(event);\n if (isDefined(data)) batched.data.push(data);\n\n eventMapping.batchFn =\n eventMapping.batchFn ||\n debounce((destination, collector) => {\n const batchContext: Destination.PushBatchContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n (collector as Collector.Instance).hooks,\n )(batched, batchContext);\n\n // Reset the batched queues\n batched.events = [];\n batched.data = [];\n }, eventMapping.batch);\n\n eventMapping.batched = batched;\n eventMapping.batchFn?.(destination, collector);\n } else {\n // It's time to go to the destination's side now\n await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(event, context);\n }\n\n return true;\n}\n\n/**\n * Creates a standardized result object for push operations.\n *\n * @param partialResult - A partial result to merge with the default result.\n * @returns The push result.\n */\nexport function createPushResult(\n partialResult?: Partial<Elb.PushResult>,\n): Elb.PushResult {\n return assign(\n {\n ok: !partialResult?.failed?.length,\n successful: [],\n queued: [],\n failed: [],\n },\n partialResult,\n );\n}\n\n/**\n * Initializes a map of destinations using ONLY the unified code/config/env pattern.\n * Does NOT call destination.init() - that happens later during push with proper consent checks.\n *\n * @param destinations - The destinations to initialize.\n * @param collector - The collector instance for destination init context.\n * @returns The initialized destinations.\n */\nexport async function initDestinations(\n _collector: Collector.Instance,\n destinations: Destination.InitDestinations = {},\n): Promise<Collector.Destinations> {\n const result: Collector.Destinations = {};\n\n for (const [name, destinationDef] of Object.entries(destinations)) {\n const { code, config = {}, env = {} } = destinationDef;\n\n // Merge config: destination default + provided config\n const mergedConfig = {\n ...code.config,\n ...config,\n };\n\n // Merge environment: destination default + provided env\n const mergedEnv = mergeEnvironments(code.env, env);\n\n // Create destination instance by spreading code and overriding config/env\n result[name] = {\n ...code,\n config: mergedConfig,\n env: mergedEnv,\n };\n }\n\n return result;\n}\n\n/**\n * Merges destination environment with config environment\n * Config env takes precedence over destination env for overrides\n */\nfunction mergeEnvironments(\n destinationEnv?: Destination.Environment,\n configEnv?: Destination.Environment,\n): Destination.Environment {\n // If neither environment exists, return empty object\n if (!destinationEnv && !configEnv) return {};\n\n // If only one exists, return it\n if (!configEnv) return destinationEnv!;\n if (!destinationEnv) return configEnv;\n\n // Both exist - merge objects with configEnv taking precedence\n if (isObject(destinationEnv) && isObject(configEnv)) {\n return { ...destinationEnv, ...configEnv };\n }\n\n // If they're not both objects, config env overrides destination env\n return configEnv;\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Commands, Const } from './constants';\nimport { addDestination, pushToDestinations } from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject, isSameType } from '@walkeros/core';\nimport { setConsent } from './consent';\nimport { on, onApply } from './on';\nimport type { RunState } from './types/collector';\n\n/**\n * Handles common commands.\n *\n * @param collector The walkerOS collector instance.\n * @param action The action to handle.\n * @param data The data to handle.\n * @param options The options to handle.\n * @returns A promise that resolves with the push result or undefined.\n */\nexport async function commonHandleCommand(\n collector: Collector.Instance,\n action: string,\n data?: unknown,\n options?: unknown,\n): Promise<Elb.PushResult> {\n let result: Elb.PushResult | undefined;\n switch (action) {\n case Const.Commands.Config:\n if (isObject(data)) {\n assign(collector.config, data as Partial<Collector.Config>, {\n shallow: false,\n });\n }\n break;\n\n case Const.Commands.Consent:\n if (isObject(data)) {\n result = await setConsent(collector, data as WalkerOS.Consent);\n }\n break;\n\n case Const.Commands.Custom:\n if (isObject(data)) {\n collector.custom = assign(\n collector.custom,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.Destination:\n if (isObject(data) && isFunction(data.push)) {\n result = await addDestination(\n collector,\n { code: data as unknown as Destination.Instance },\n options as Destination.Config,\n );\n }\n break;\n\n case Const.Commands.Globals:\n if (isObject(data)) {\n collector.globals = assign(\n collector.globals,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.On:\n if (isString(data)) {\n on(\n collector,\n data as On.Types,\n options as WalkerOS.SingleOrArray<On.Options>,\n );\n }\n break;\n\n case Const.Commands.Ready:\n onApply(collector, 'ready');\n break;\n\n case Const.Commands.Run:\n result = await runCollector(collector, data as RunState);\n break;\n\n case Const.Commands.Session:\n onApply(collector, 'session');\n break;\n\n case Const.Commands.User:\n if (isObject(data)) {\n assign(collector.user, data as WalkerOS.User, { shallow: false });\n }\n break;\n }\n\n return (\n result || {\n ok: true,\n successful: [],\n queued: [],\n failed: [],\n }\n );\n}\n\n/**\n * Creates an event or a command from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param nameOrEvent The name of the event or a partial event.\n * @param defaults The default values for the event.\n * @returns An object with the event or the command.\n */\nexport function createEventOrCommand(\n collector: Collector.Instance,\n nameOrEvent: unknown,\n defaults: WalkerOS.PartialEvent = {},\n): { event?: WalkerOS.Event; command?: string } {\n // Determine the partial event\n const partialEvent: WalkerOS.PartialEvent = isSameType(\n nameOrEvent,\n '' as string,\n )\n ? { name: nameOrEvent, ...defaults }\n : { ...defaults, ...(nameOrEvent || {}) };\n\n if (!partialEvent.name) throw new Error('Event name is required');\n\n // Check for valid entity and action event format\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n // It's a walker command\n if (entityValue === Commands.Walker) {\n return { command: actionValue };\n }\n\n // Regular event\n ++collector.count;\n\n // Values that are eventually used by other properties\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\n // Extract properties with default fallbacks\n const {\n name = `${entityValue} ${actionValue}`,\n data = {},\n context = {},\n globals = collector.globals,\n custom = {},\n user = collector.user,\n nested = [],\n consent = collector.consent,\n id = `${timestamp}-${group}-${count}`,\n trigger = '',\n entity = entityValue,\n action = actionValue,\n timing = 0,\n version = {\n source: collector.version,\n tagging: collector.config.tagging || 0,\n },\n source = { type: 'collector', id: '', previous_id: '' },\n } = partialEvent;\n\n const fullEvent: WalkerOS.Event = {\n name,\n data,\n context,\n globals,\n custom,\n user,\n nested,\n consent,\n id,\n trigger,\n entity,\n action,\n timestamp,\n timing,\n group,\n count,\n version,\n source,\n };\n\n return { event: fullEvent };\n}\n\n/**\n * Runs the collector by setting it to allowed state and processing queued events.\n *\n * @param collector The walkerOS collector instance.\n * @param state Optional state to merge with the collector (user, globals, consent, custom).\n * @returns A promise that resolves with the push result.\n */\nexport async function runCollector(\n collector: Collector.Instance,\n state?: RunState,\n): Promise<Elb.PushResult> {\n // Set the collector to allowed state\n collector.allowed = true;\n\n // Reset count and generate new group ID\n collector.count = 0;\n collector.group = getId();\n\n // Update timing for this run\n collector.timing = Date.now();\n\n // Update collector state if provided\n if (state) {\n // Update consent if provided\n if (state.consent) {\n collector.consent = assign(collector.consent, state.consent);\n }\n\n // Update user if provided\n if (state.user) {\n collector.user = assign(collector.user, state.user);\n }\n\n // Update globals if provided\n if (state.globals) {\n collector.globals = assign(\n collector.config.globalsStatic || {},\n state.globals,\n );\n }\n\n // Update custom if provided\n if (state.custom) {\n collector.custom = assign(collector.custom, state.custom);\n }\n }\n\n // Reset destination queues\n Object.values(collector.destinations).forEach((destination) => {\n destination.queue = [];\n });\n\n // Reset collector queue for this run\n collector.queue = [];\n\n // Increase round counter\n collector.round++;\n\n // Process any queued events now that the collector is allowed\n const result = await pushToDestinations(collector);\n\n // Call the predefined run events\n onApply(collector, 'run');\n\n return result;\n}\n","import type { Collector, On, WalkerOS } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\n\n/**\n * Registers a callback for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to listen for.\n * @param option The callback function or an array of callback functions.\n */\nexport function on(\n collector: Collector.Instance,\n type: On.Types,\n option: WalkerOS.SingleOrArray<On.Options>,\n) {\n const on = collector.on;\n const onType: Array<On.Options> = on[type] || [];\n const options = isArray(option) ? option : [option];\n\n options.forEach((option) => {\n onType.push(option);\n });\n\n // Update collector on state\n (on[type] as typeof onType) = onType;\n\n // Execute the on function directly\n onApply(collector, type, options);\n}\n\n/**\n * Applies all registered callbacks for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to apply the callbacks for.\n * @param options The options for the callbacks.\n * @param config The consent configuration.\n */\nexport function onApply(\n collector: Collector.Instance,\n type: On.Types,\n options?: Array<On.Options>,\n config?: WalkerOS.Consent,\n) {\n // Use the optionally provided options\n let onConfig = options || [];\n\n if (!options) {\n // Get the collector on events\n onConfig = collector.on[type] || [];\n }\n\n // Push to sources (similar to destination pattern)\n // Calculate context data once for all sources\n let contextData: unknown;\n switch (type) {\n case Const.Commands.Consent:\n contextData = config || collector.consent;\n break;\n case Const.Commands.Session:\n contextData = collector.session;\n break;\n case Const.Commands.Ready:\n case Const.Commands.Run:\n default:\n contextData = undefined;\n break;\n }\n\n Object.values(collector.sources).forEach((source) => {\n if (source.on) {\n tryCatch(source.on)(type, contextData);\n }\n });\n\n Object.values(collector.destinations).forEach((destination) => {\n if (destination.on) {\n tryCatch(destination.on)(type, contextData);\n }\n });\n\n if (!onConfig.length) return; // No on-events registered, nothing to do\n\n switch (type) {\n case Const.Commands.Consent:\n onConsent(collector, onConfig as Array<On.ConsentConfig>, config);\n break;\n case Const.Commands.Ready:\n onReady(collector, onConfig as Array<On.ReadyConfig>);\n break;\n case Const.Commands.Run:\n onRun(collector, onConfig as Array<On.RunConfig>);\n break;\n case Const.Commands.Session:\n onSession(collector, onConfig as Array<On.SessionConfig>);\n break;\n default:\n break;\n }\n}\n\nfunction onConsent(\n collector: Collector.Instance,\n onConfig: Array<On.ConsentConfig>,\n currentConsent?: WalkerOS.Consent,\n): void {\n const consentState = currentConsent || collector.consent;\n\n onConfig.forEach((consentConfig) => {\n // Collect functions whose consent keys match the rule keys directly\n // Directly execute functions whose consent keys match the rule keys\n Object.keys(consentState) // consent keys\n .filter((consent) => consent in consentConfig) // check for matching rule keys\n .forEach((consent) => {\n // Execute the function\n tryCatch(consentConfig[consent])(collector, consentState);\n });\n });\n}\n\nfunction onReady(\n collector: Collector.Instance,\n onConfig: Array<On.ReadyConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onRun(\n collector: Collector.Instance,\n onConfig: Array<On.RunConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onSession(\n collector: Collector.Instance,\n onConfig: Array<On.SessionConfig>,\n): void {\n if (!collector.session) return;\n\n onConfig.forEach((func) => {\n tryCatch(func)(collector, collector.session);\n });\n}\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport type { CreateCollector } from './types';\nimport { assign, onLog } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations, createPush } from './destination';\nimport { initSources } from './source';\n\nexport async function createCollector<\n TConfig extends Partial<Collector.Config> = Partial<Collector.Config>,\n>(initConfig: TConfig = {} as TConfig): Promise<CreateCollector> {\n const instance = await collector(initConfig);\n const { consent, user, globals, custom } = initConfig;\n\n if (consent) await instance.push('walker consent', consent);\n if (user) await instance.push('walker user', user);\n if (globals) Object.assign(instance.globals, globals);\n if (custom) Object.assign(instance.custom, custom);\n\n if (instance.config.run) await instance.push('walker run');\n\n return {\n collector: instance,\n elb: instance.push,\n };\n}\n\nasync function collector(\n initConfig: Partial<Collector.Config>,\n): Promise<Collector.Instance> {\n const { version } = require('../package.json');\n\n const defaultConfig: Collector.Config = {\n globalsStatic: {},\n sessionStatic: {},\n tagging: 0,\n verbose: false,\n onLog: log,\n run: true,\n sources: {},\n destinations: {},\n consent: {},\n user: {},\n globals: {},\n custom: {},\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n function log(message: string, verbose?: boolean) {\n onLog({ message }, verbose || config.verbose);\n }\n config.onLog = log;\n\n // Enhanced globals with static globals from config\n const finalGlobals = { ...config.globalsStatic, ...config.globals };\n\n const collector: Collector.Instance = {\n allowed: false,\n config,\n consent: config.consent || {},\n count: 0,\n custom: config.custom || {},\n destinations: {},\n globals: finalGlobals,\n group: '',\n hooks: {},\n on: {},\n queue: [],\n round: 0,\n session: undefined,\n timing: Date.now(),\n user: config.user || {},\n version,\n sources: {},\n push: undefined as unknown as Elb.Fn, // Placeholder, will be set below\n };\n\n // Set the push function with the collector reference\n collector.push = createPush(\n collector,\n commonHandleCommand,\n (event: WalkerOS.DeepPartialEvent): WalkerOS.PartialEvent =>\n ({\n timing: Math.round((Date.now() - collector.timing) / 10) / 100,\n source: { type: 'collector', id: '', previous_id: '' },\n ...event,\n }) as WalkerOS.PartialEvent,\n );\n\n // Initialize sources and destinations after collector is fully created\n collector.sources = await initSources(collector, config.sources);\n collector.destinations = await initDestinations(\n collector,\n config.destinations,\n );\n\n return collector;\n}\n","import type { Collector, Source, WalkerOS } from '@walkeros/core';\nimport { tryCatchAsync } from '@walkeros/core';\n\n/**\n * Initialize sources using the code/config/env pattern\n *\n * @param collector - The WalkerOS collector instance\n * @param sources - Map of source definitions with code/config/env\n */\nexport async function initSources(\n collector: Collector.Instance,\n sources: Source.InitSources = {},\n): Promise<Collector.Sources> {\n const result: Collector.Sources = {};\n\n for (const [sourceId, sourceDefinition] of Object.entries(sources)) {\n const { code, config = {}, env = {} } = sourceDefinition;\n\n const cleanEnv: Source.Environment = {\n elb: ((...args: Parameters<typeof collector.push>) =>\n collector.push(...args)) as typeof collector.push, // Dynamic reference to collector.push\n ...env,\n };\n\n // Call source function with config and environment separately\n const sourceInstance = await tryCatchAsync(code)(config, cleanEnv);\n\n if (!sourceInstance) continue; // Skip failed source initialization\n\n result[sourceId] = sourceInstance;\n }\n\n return result;\n}\n"],"mappings":";;;;;;AAAA;AAAA;AAAA;AAAA,MACE,MAAQ;AAAA,MACR,aAAe;AAAA,MACf,SAAW;AAAA,MACX,MAAQ;AAAA,MACR,QAAU;AAAA,MACV,OAAS;AAAA,MACT,SAAW;AAAA,MACX,OAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA,SAAW;AAAA,QACT,OAAS;AAAA,QACT,OAAS;AAAA,QACT,KAAO;AAAA,QACP,MAAQ;AAAA,QACR,MAAQ;AAAA,QACR,QAAU;AAAA,MACZ;AAAA,MACA,cAAgB;AAAA,QACd,kBAAkB;AA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AAA,IACT,QAAQ,KAAK,IAAI;AAAA,IACjB,MAAM,OAAO,QAAQ,CAAC;AAAA,IACtB;AAAA,IACA,SAAS,CAAC;AAAA,IACV,MAAM;AAAA;AAAA,EACR;AAGA,EAAAA,WAAU,OAAO;AAAA,IACfA;AAAA,IACA;AAAA,IACA,CAAC,WACE;AAAA,MACC,QAAQ,KAAK,OAAO,KAAK,IAAI,IAAIA,WAAU,UAAU,EAAE,IAAI;AAAA,MAC3D,QAAQ,EAAE,MAAM,aAAa,IAAI,IAAI,aAAa,GAAG;AAAA,MACrD,GAAG;AAAA,IACL;AAAA,EACJ;AAGA,EAAAA,WAAU,UAAU,MAAM,YAAYA,YAAW,OAAO,OAAO;AAC/D,EAAAA,WAAU,eAAe,MAAM;AAAA,IAC7BA;AAAA,IACA,OAAO;AAAA,EACT;AAEA,SAAOA;AACT;","names":["assign","assign","getId","isObject","collector","on","option","collector","collector","getId","event","assign","isObject","destination","collector","assign","assign","tryCatchAsync","collector","assign","collector"]}
1
+ {"version":3,"sources":["../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/handle.ts","../src/on.ts","../src/collector.ts","../src/source.ts","../src/flow.ts"],"sourcesContent":["import type { Collector } from '@walkeros/core';\nimport type { WalkerOS } from '@walkeros/core';\n\nexport type CommandTypes =\n | 'Action'\n | 'Actions'\n | 'Config'\n | 'Consent'\n | 'Context'\n | 'Custom'\n | 'Destination'\n | 'Elb'\n | 'Globals'\n | 'Hook'\n | 'Init'\n | 'Link'\n | 'On'\n | 'Prefix'\n | 'Ready'\n | 'Run'\n | 'Session'\n | 'User'\n | 'Walker';\n\nexport const Commands: Record<CommandTypes, Collector.CommandType> = {\n Action: 'action',\n Actions: 'actions',\n Config: 'config',\n Consent: 'consent',\n Context: 'context',\n Custom: 'custom',\n Destination: 'destination',\n Elb: 'elb',\n Globals: 'globals',\n Hook: 'hook',\n Init: 'init',\n Link: 'link',\n On: 'on',\n Prefix: 'data-elb',\n Ready: 'ready',\n Run: 'run',\n Session: 'session',\n User: 'user',\n Walker: 'walker',\n} as const;\n\nexport type StorageType = 'cookie' | 'local' | 'session';\n\nconst UtilsStorage: { [key: string]: StorageType } = {\n Cookie: 'cookie',\n Local: 'local',\n Session: 'session',\n} as const;\n\nconst Utils = {\n Storage: UtilsStorage,\n};\n\nexport const Const = {\n Commands,\n Utils,\n};\n\nexport default Const;\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport { assign } from '@walkeros/core';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { onApply } from './on';\n\n/**\n * Sets the consent state and processes the queue.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The consent data to set.\n * @returns The result of the push operation.\n */\nexport async function setConsent(\n collector: Collector.Instance,\n data: WalkerOS.Consent,\n): Promise<Elb.PushResult> {\n const { consent } = collector;\n\n let runQueue = false;\n const update: WalkerOS.Consent = {};\n Object.entries(data).forEach(([name, granted]) => {\n const state = !!granted;\n\n update[name] = state;\n\n // Only run queue if state was set to true\n runQueue = runQueue || state;\n });\n\n // Update consent state\n collector.consent = assign(consent, update);\n\n // Run on consent events\n onApply(collector, 'consent', undefined, update);\n\n // Process previous events if not disabled\n return runQueue\n ? pushToDestinations(collector)\n : createPushResult({ ok: true });\n}\n","import type { Collector, WalkerOS, Elb, Destination } from '@walkeros/core';\nimport {\n assign,\n clone,\n debounce,\n getId,\n getGrantedConsent,\n getMappingEvent,\n getMappingValue,\n isDefined,\n isObject,\n setByPath,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEventOrCommand } from './handle';\n\nexport type HandleCommandFn<T extends Collector.Instance> = (\n collector: T,\n action: string,\n data?: Elb.PushData,\n options?: unknown,\n) => Promise<Elb.PushResult>;\n\n/**\n * Creates the main push function for the collector.\n *\n * @template T, F\n * @param collector - The walkerOS collector instance.\n * @param handleCommand - TBD.\n * @param prepareEvent - TBD.\n * @returns The push function.\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Elb.Fn {\n return useHooks(\n async (\n eventOrCommand: unknown,\n data?: Elb.PushData,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n // Handle simplified core collector interface\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n // Walker command format: 'walker action', data, options\n const command = eventOrCommand.replace('walker ', '');\n return await handleCommand(collector, command, data, options);\n } else {\n // Event format: event object or string\n const partialEvent =\n typeof eventOrCommand === 'string'\n ? { name: eventOrCommand }\n : (eventOrCommand as WalkerOS.DeepPartialEvent);\n\n const enrichedEvent = prepareEvent(partialEvent);\n\n const { event, command } = createEventOrCommand(\n collector,\n enrichedEvent.name,\n enrichedEvent,\n );\n\n const result = command\n ? await handleCommand(collector, command, data, options)\n : await pushToDestinations(collector, event);\n\n return result;\n }\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Elb.Fn;\n}\n\n/**\n * Adds a new destination to the collector.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The destination's init data.\n * @param options - The destination's config.\n * @returns The result of the push operation.\n */\nexport async function addDestination(\n collector: Collector.Instance,\n data: Destination.Init,\n options?: Destination.Config,\n): Promise<Elb.PushResult> {\n const { code, config: dataConfig = {}, env = {} } = data;\n const config = options || dataConfig || { init: false };\n\n const destination: Destination.Instance = {\n ...code,\n config,\n env: mergeEnvironments(code.env, env),\n };\n\n let id = destination.config.id; // Use given id\n if (!id) {\n // Generate a new id if none was given\n do {\n id = getId(4);\n } while (collector.destinations[id]);\n }\n\n // Add the destination\n collector.destinations[id] = destination;\n\n // Process previous events if not disabled\n if (destination.config.queue !== false)\n destination.queue = [...collector.queue];\n\n return pushToDestinations(collector, undefined, { [id]: destination });\n}\n\n/**\n * Pushes an event to all or a subset of destinations.\n *\n * @param collector - The walkerOS collector instance.\n * @param event - The event to push.\n * @param destinations - The destinations to push to.\n * @returns The result of the push operation.\n */\nexport async function pushToDestinations(\n collector: Collector.Instance,\n event?: WalkerOS.Event,\n destinations?: Collector.Destinations,\n): Promise<Elb.PushResult> {\n const { allowed, consent, globals, user } = collector;\n\n // Check if collector is allowed to push\n if (!allowed) return createPushResult({ ok: false });\n\n // Add event to the collector queue\n if (event) collector.queue.push(event);\n\n // Use given destinations or use internal destinations\n if (!destinations) destinations = collector.destinations;\n\n const results = await Promise.all(\n // Process all destinations in parallel\n Object.entries(destinations || {}).map(async ([id, destination]) => {\n // Create a queue of events to be processed\n let currentQueue = (destination.queue || []).map((event) => ({\n ...event,\n consent,\n }));\n\n // Reset original queue while processing to enable async processing\n destination.queue = [];\n\n // Add event to queue stack\n if (event) {\n // Clone the event to avoid mutating the original event\n let currentEvent = clone(event);\n\n // Policy check\n await Promise.all(\n Object.entries(destination.config.policy || []).map(\n async ([key, mapping]) => {\n const value = await getMappingValue(event, mapping, {\n collector,\n });\n currentEvent = setByPath(currentEvent, key, value);\n },\n ),\n );\n\n // Add event to queue stack\n currentQueue.push(currentEvent);\n }\n\n // Nothing to do here if the queue is empty\n if (!currentQueue.length) return { id, destination, skipped: true };\n\n const allowedEvents: WalkerOS.Events = [];\n const skippedEvents = currentQueue.filter((queuedEvent) => {\n const grantedConsent = getGrantedConsent(\n destination.config.consent, // Required\n consent, // Current collector state\n queuedEvent.consent, // Individual event state\n );\n\n if (grantedConsent) {\n queuedEvent.consent = grantedConsent; // Save granted consent states only\n\n allowedEvents.push(queuedEvent); // Add to allowed queue\n return false; // Remove from destination queue\n }\n\n return true; // Keep denied events in the queue\n });\n\n // Add skipped events back to the queue\n destination.queue.concat(skippedEvents);\n\n // Execution shall not pass if no events are allowed\n if (!allowedEvents.length) {\n return { id, destination, queue: currentQueue }; // Don't push if not allowed\n }\n\n // Initialize the destination if needed\n const isInitialized = await tryCatchAsync(destinationInit)(\n collector,\n destination,\n );\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error = false;\n if (!destination.dlq) destination.dlq = [];\n\n // Process allowed events and store failed ones in the dead letter queue (DLQ)\n await Promise.all(\n allowedEvents.map(async (event) => {\n // Merge event with collector state, prioritizing event properties\n event.globals = assign(globals, event.globals);\n event.user = assign(user, event.user);\n\n await tryCatchAsync(destinationPush, (err) => {\n // Call custom error handling if available\n if (collector.config.onError)\n collector.config.onError(err, collector);\n error = true; // oh no\n\n // Add failed event to destinations DLQ\n destination.dlq!.push([event, err]);\n\n return false;\n })(collector, destination, event);\n\n return event;\n }),\n );\n\n return { id, destination, error };\n }),\n );\n\n const successful = [];\n const queued = [];\n const failed = [];\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n\n const ref = { id: result.id, destination };\n\n if (result.error) {\n failed.push(ref);\n } else if (result.queue && result.queue.length) {\n // Merge queue with existing queue\n destination.queue = (destination.queue || []).concat(result.queue);\n queued.push(ref);\n } else {\n successful.push(ref);\n }\n }\n\n return createPushResult({\n ok: !failed.length,\n event,\n successful,\n queued,\n failed,\n });\n}\n\n/**\n * Initializes a destination.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to initialize.\n * @returns Whether the destination was initialized successfully.\n */\nexport async function destinationInit<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n const context: Destination.Context = {\n collector,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n const configResult = await useHooks(\n destination.init,\n 'DestinationInit',\n collector.hooks,\n )(context);\n\n // Actively check for errors (when false)\n if (configResult === false) return configResult; // don't push if init is false\n\n // Update the destination config if it was returned\n destination.config = {\n ...(configResult || destination.config),\n init: true, // Remember that the destination was initialized\n };\n }\n\n return true; // Destination is ready to push\n}\n\n/**\n * Pushes an event to a single destination.\n * Handles mapping, batching, and consent checks.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to push to.\n * @param event - The event to push.\n * @returns Whether the event was pushed successfully.\n */\nexport async function destinationPush<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n event: WalkerOS.Event,\n): Promise<boolean> {\n const { config } = destination;\n const { eventMapping, mappingKey } = await getMappingEvent(\n event,\n config.mapping,\n );\n\n let data =\n config.data && (await getMappingValue(event, config.data, { collector }));\n\n if (eventMapping) {\n // Check if event should be processed or ignored\n if (eventMapping.ignore) return false;\n\n // Check to use specific event names\n if (eventMapping.name) event.name = eventMapping.name;\n\n // Transform event to a custom data\n if (eventMapping.data) {\n const dataEvent =\n eventMapping.data &&\n (await getMappingValue(event, eventMapping.data, { collector }));\n data =\n isObject(data) && isObject(dataEvent) // Only merge objects\n ? assign(data, dataEvent)\n : dataEvent;\n }\n }\n\n const context: Destination.PushContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n if (eventMapping?.batch && destination.pushBatch) {\n const batched = eventMapping.batched || {\n key: mappingKey || '',\n events: [],\n data: [],\n };\n batched.events.push(event);\n if (isDefined(data)) batched.data.push(data);\n\n eventMapping.batchFn =\n eventMapping.batchFn ||\n debounce((destination, collector) => {\n const batchContext: Destination.PushBatchContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n (collector as Collector.Instance).hooks,\n )(batched, batchContext);\n\n // Reset the batched queues\n batched.events = [];\n batched.data = [];\n }, eventMapping.batch);\n\n eventMapping.batched = batched;\n eventMapping.batchFn?.(destination, collector);\n } else {\n // It's time to go to the destination's side now\n await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(event, context);\n }\n\n return true;\n}\n\n/**\n * Creates a standardized result object for push operations.\n *\n * @param partialResult - A partial result to merge with the default result.\n * @returns The push result.\n */\nexport function createPushResult(\n partialResult?: Partial<Elb.PushResult>,\n): Elb.PushResult {\n return assign(\n {\n ok: !partialResult?.failed?.length,\n successful: [],\n queued: [],\n failed: [],\n },\n partialResult,\n );\n}\n\n/**\n * Initializes a map of destinations using ONLY the unified code/config/env pattern.\n * Does NOT call destination.init() - that happens later during push with proper consent checks.\n *\n * @param destinations - The destinations to initialize.\n * @param collector - The collector instance for destination init context.\n * @returns The initialized destinations.\n */\nexport async function initDestinations(\n _collector: Collector.Instance,\n destinations: Destination.InitDestinations = {},\n): Promise<Collector.Destinations> {\n const result: Collector.Destinations = {};\n\n for (const [name, destinationDef] of Object.entries(destinations)) {\n const { code, config = {}, env = {} } = destinationDef;\n\n // Merge config: destination default + provided config\n const mergedConfig = {\n ...code.config,\n ...config,\n };\n\n // Merge environment: destination default + provided env\n const mergedEnv = mergeEnvironments(code.env, env);\n\n // Create destination instance by spreading code and overriding config/env\n result[name] = {\n ...code,\n config: mergedConfig,\n env: mergedEnv,\n };\n }\n\n return result;\n}\n\n/**\n * Merges destination environment with config environment\n * Config env takes precedence over destination env for overrides\n */\nfunction mergeEnvironments(\n destinationEnv?: Destination.Env,\n configEnv?: Destination.Env,\n): Destination.Env {\n // If neither environment exists, return empty object\n if (!destinationEnv && !configEnv) return {};\n\n // If only one exists, return it\n if (!configEnv) return destinationEnv!;\n if (!destinationEnv) return configEnv;\n\n // Both exist - merge objects with configEnv taking precedence\n if (isObject(destinationEnv) && isObject(configEnv)) {\n return { ...destinationEnv, ...configEnv };\n }\n\n // If they're not both objects, config env overrides destination env\n return configEnv;\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Commands, Const } from './constants';\nimport { addDestination, pushToDestinations } from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject, isSameType } from '@walkeros/core';\nimport { setConsent } from './consent';\nimport { on, onApply } from './on';\nimport type { RunState } from './types/collector';\n\n/**\n * Handles common commands.\n *\n * @param collector The walkerOS collector instance.\n * @param action The action to handle.\n * @param data The data to handle.\n * @param options The options to handle.\n * @returns A promise that resolves with the push result or undefined.\n */\nexport async function commonHandleCommand(\n collector: Collector.Instance,\n action: string,\n data?: unknown,\n options?: unknown,\n): Promise<Elb.PushResult> {\n let result: Elb.PushResult | undefined;\n switch (action) {\n case Const.Commands.Config:\n if (isObject(data)) {\n assign(collector.config, data as Partial<Collector.Config>, {\n shallow: false,\n });\n }\n break;\n\n case Const.Commands.Consent:\n if (isObject(data)) {\n result = await setConsent(collector, data as WalkerOS.Consent);\n }\n break;\n\n case Const.Commands.Custom:\n if (isObject(data)) {\n collector.custom = assign(\n collector.custom,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.Destination:\n if (isObject(data) && isFunction(data.push)) {\n result = await addDestination(\n collector,\n { code: data as unknown as Destination.Instance },\n options as Destination.Config,\n );\n }\n break;\n\n case Const.Commands.Globals:\n if (isObject(data)) {\n collector.globals = assign(\n collector.globals,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.On:\n if (isString(data)) {\n on(\n collector,\n data as On.Types,\n options as WalkerOS.SingleOrArray<On.Options>,\n );\n }\n break;\n\n case Const.Commands.Ready:\n onApply(collector, 'ready');\n break;\n\n case Const.Commands.Run:\n result = await runCollector(collector, data as RunState);\n break;\n\n case Const.Commands.Session:\n onApply(collector, 'session');\n break;\n\n case Const.Commands.User:\n if (isObject(data)) {\n assign(collector.user, data as WalkerOS.User, { shallow: false });\n }\n break;\n }\n\n return (\n result || {\n ok: true,\n successful: [],\n queued: [],\n failed: [],\n }\n );\n}\n\n/**\n * Creates an event or a command from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param nameOrEvent The name of the event or a partial event.\n * @param defaults The default values for the event.\n * @returns An object with the event or the command.\n */\nexport function createEventOrCommand(\n collector: Collector.Instance,\n nameOrEvent: unknown,\n defaults: WalkerOS.PartialEvent = {},\n): { event?: WalkerOS.Event; command?: string } {\n // Determine the partial event\n const partialEvent: WalkerOS.PartialEvent = isSameType(\n nameOrEvent,\n '' as string,\n )\n ? { name: nameOrEvent, ...defaults }\n : { ...defaults, ...(nameOrEvent || {}) };\n\n if (!partialEvent.name) throw new Error('Event name is required');\n\n // Check for valid entity and action event format\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n // It's a walker command\n if (entityValue === Commands.Walker) {\n return { command: actionValue };\n }\n\n // Regular event\n ++collector.count;\n\n // Values that are eventually used by other properties\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\n // Extract properties with default fallbacks\n const {\n name = `${entityValue} ${actionValue}`,\n data = {},\n context = {},\n globals = collector.globals,\n custom = {},\n user = collector.user,\n nested = [],\n consent = collector.consent,\n id = `${timestamp}-${group}-${count}`,\n trigger = '',\n entity = entityValue,\n action = actionValue,\n timing = 0,\n version = {\n source: collector.version,\n tagging: collector.config.tagging || 0,\n },\n source = { type: 'collector', id: '', previous_id: '' },\n } = partialEvent;\n\n const fullEvent: WalkerOS.Event = {\n name,\n data,\n context,\n globals,\n custom,\n user,\n nested,\n consent,\n id,\n trigger,\n entity,\n action,\n timestamp,\n timing,\n group,\n count,\n version,\n source,\n };\n\n return { event: fullEvent };\n}\n\n/**\n * Runs the collector by setting it to allowed state and processing queued events.\n *\n * @param collector The walkerOS collector instance.\n * @param state Optional state to merge with the collector (user, globals, consent, custom).\n * @returns A promise that resolves with the push result.\n */\nexport async function runCollector(\n collector: Collector.Instance,\n state?: RunState,\n): Promise<Elb.PushResult> {\n // Set the collector to allowed state\n collector.allowed = true;\n\n // Reset count and generate new group ID\n collector.count = 0;\n collector.group = getId();\n\n // Update timing for this run\n collector.timing = Date.now();\n\n // Update collector state if provided\n if (state) {\n // Update consent if provided\n if (state.consent) {\n collector.consent = assign(collector.consent, state.consent);\n }\n\n // Update user if provided\n if (state.user) {\n collector.user = assign(collector.user, state.user);\n }\n\n // Update globals if provided\n if (state.globals) {\n collector.globals = assign(\n collector.config.globalsStatic || {},\n state.globals,\n );\n }\n\n // Update custom if provided\n if (state.custom) {\n collector.custom = assign(collector.custom, state.custom);\n }\n }\n\n // Reset destination queues\n Object.values(collector.destinations).forEach((destination) => {\n destination.queue = [];\n });\n\n // Reset collector queue for this run\n collector.queue = [];\n\n // Increase round counter\n collector.round++;\n\n // Process any queued events now that the collector is allowed\n const result = await pushToDestinations(collector);\n\n // Call the predefined run events\n onApply(collector, 'run');\n\n return result;\n}\n","import type { Collector, On, WalkerOS } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\n\n/**\n * Registers a callback for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to listen for.\n * @param option The callback function or an array of callback functions.\n */\nexport function on(\n collector: Collector.Instance,\n type: On.Types,\n option: WalkerOS.SingleOrArray<On.Options>,\n) {\n const on = collector.on;\n const onType: Array<On.Options> = on[type] || [];\n const options = isArray(option) ? option : [option];\n\n options.forEach((option) => {\n onType.push(option);\n });\n\n // Update collector on state\n (on[type] as typeof onType) = onType;\n\n // Execute the on function directly\n onApply(collector, type, options);\n}\n\n/**\n * Applies all registered callbacks for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to apply the callbacks for.\n * @param options The options for the callbacks.\n * @param config The consent configuration.\n */\nexport function onApply(\n collector: Collector.Instance,\n type: On.Types,\n options?: Array<On.Options>,\n config?: WalkerOS.Consent,\n) {\n // Use the optionally provided options\n let onConfig = options || [];\n\n if (!options) {\n // Get the collector on events\n onConfig = collector.on[type] || [];\n }\n\n // Calculate context data once for all sources and destinations\n let contextData: unknown;\n\n switch (type) {\n case Const.Commands.Consent:\n contextData = config || collector.consent;\n break;\n case Const.Commands.Session:\n contextData = collector.session;\n break;\n case Const.Commands.Ready:\n case Const.Commands.Run:\n default:\n contextData = undefined;\n break;\n }\n\n Object.values(collector.sources).forEach((source) => {\n if (source.on) {\n tryCatch(source.on)(type, contextData);\n }\n });\n\n Object.values(collector.destinations).forEach((destination) => {\n if (destination.on) {\n // Cast to runtime-compatible version for type safety\n const onFn = destination.on as On.OnFnRuntime;\n tryCatch(onFn)(type, contextData as On.AnyEventContext);\n }\n });\n\n if (!onConfig.length) return; // No on-events registered, nothing to do\n\n switch (type) {\n case Const.Commands.Consent:\n onConsent(collector, onConfig as Array<On.ConsentConfig>, config);\n break;\n case Const.Commands.Ready:\n onReady(collector, onConfig as Array<On.ReadyConfig>);\n break;\n case Const.Commands.Run:\n onRun(collector, onConfig as Array<On.RunConfig>);\n break;\n case Const.Commands.Session:\n onSession(collector, onConfig as Array<On.SessionConfig>);\n break;\n default:\n break;\n }\n}\n\nfunction onConsent(\n collector: Collector.Instance,\n onConfig: Array<On.ConsentConfig>,\n currentConsent?: WalkerOS.Consent,\n): void {\n const consentState = currentConsent || collector.consent;\n\n onConfig.forEach((consentConfig) => {\n // Collect functions whose consent keys match the rule keys directly\n // Directly execute functions whose consent keys match the rule keys\n Object.keys(consentState) // consent keys\n .filter((consent) => consent in consentConfig) // check for matching rule keys\n .forEach((consent) => {\n // Execute the function\n tryCatch(consentConfig[consent])(collector, consentState);\n });\n });\n}\n\nfunction onReady(\n collector: Collector.Instance,\n onConfig: Array<On.ReadyConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onRun(\n collector: Collector.Instance,\n onConfig: Array<On.RunConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onSession(\n collector: Collector.Instance,\n onConfig: Array<On.SessionConfig>,\n): void {\n if (!collector.session) return;\n\n onConfig.forEach((func) => {\n tryCatch(func)(collector, collector.session);\n });\n}\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport { assign, onLog } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations, createPush } from './destination';\nimport { initSources } from './source';\n\ndeclare const __VERSION__: string;\n\nexport async function collector(\n initConfig: Collector.InitConfig,\n): Promise<Collector.Instance> {\n const version = __VERSION__;\n\n const defaultConfig: Collector.Config = {\n globalsStatic: {},\n sessionStatic: {},\n tagging: 0,\n verbose: false,\n onLog: log,\n run: true,\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n function log(message: string, verbose?: boolean) {\n onLog({ message }, verbose || config.verbose);\n }\n config.onLog = log;\n\n // Enhanced globals with static globals from config\n const finalGlobals = { ...config.globalsStatic, ...initConfig.globals };\n\n const collector: Collector.Instance = {\n allowed: false,\n config,\n consent: initConfig.consent || {},\n count: 0,\n custom: initConfig.custom || {},\n destinations: {},\n globals: finalGlobals,\n group: '',\n hooks: {},\n on: {},\n queue: [],\n round: 0,\n session: undefined,\n timing: Date.now(),\n user: initConfig.user || {},\n version,\n sources: {},\n push: undefined as unknown as Elb.Fn, // Placeholder, will be set below\n };\n\n // Set the push function with the collector reference\n collector.push = createPush(\n collector,\n commonHandleCommand,\n (event: WalkerOS.DeepPartialEvent): WalkerOS.PartialEvent =>\n ({\n timing: Math.round((Date.now() - collector.timing) / 10) / 100,\n source: { type: 'collector', id: '', previous_id: '' },\n ...event,\n }) as WalkerOS.PartialEvent,\n );\n\n // Initialize sources and destinations after collector is fully created\n collector.sources = await initSources(collector, initConfig.sources || {});\n collector.destinations = await initDestinations(\n collector,\n initConfig.destinations || {},\n );\n\n return collector;\n}\n","import type { Collector, Source, WalkerOS } from '@walkeros/core';\nimport { tryCatchAsync } from '@walkeros/core';\n\n/**\n * Initialize sources using the code/config/env pattern\n *\n * @param collector - The WalkerOS collector instance\n * @param sources - Map of source definitions with code/config/env\n */\nexport async function initSources(\n collector: Collector.Instance,\n sources: Source.InitSources = {},\n): Promise<Collector.Sources> {\n const result: Collector.Sources = {};\n\n for (const [sourceId, sourceDefinition] of Object.entries(sources)) {\n const { code, config = {}, env = {}, primary } = sourceDefinition;\n\n const cleanEnv: Source.Env = {\n elb: ((...args: Parameters<typeof collector.push>) =>\n collector.push(...args)) as typeof collector.push, // Dynamic reference to collector.push\n ...env,\n };\n\n // Call source function with config and environment separately\n const sourceInstance = await tryCatchAsync(code)(config, cleanEnv);\n\n if (!sourceInstance) continue; // Skip failed source initialization\n\n // Store the primary flag in the source config for later access\n if (primary) {\n sourceInstance.config = { ...sourceInstance.config, primary };\n }\n\n result[sourceId] = sourceInstance;\n }\n\n return result;\n}\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport type { StartFlow } from './types';\nimport { collector } from './collector';\n\nexport async function startFlow<ElbPush extends Elb.Fn = Elb.Fn>(\n initConfig?: Collector.InitConfig,\n): Promise<StartFlow<ElbPush>> {\n initConfig = initConfig || {};\n const instance = await collector(initConfig);\n const { consent, user, globals, custom } = initConfig;\n\n if (consent) await instance.push('walker consent', consent);\n if (user) await instance.push('walker user', user);\n if (globals) Object.assign(instance.globals, globals);\n if (custom) Object.assign(instance.custom, custom);\n\n if (instance.config.run) await instance.push('walker run');\n\n // Determine the primary elb:\n // 1. Use explicitly marked primary source\n // 2. Use first source if any exist\n // 3. Fallback to collector.push\n let primaryElb: Elb.Fn = instance.push;\n\n const sources = Object.values(instance.sources);\n\n // First, check for explicitly marked primary source\n const markedPrimary = sources.find(\n (source) => (source.config as { primary?: boolean }).primary,\n );\n\n if (markedPrimary) {\n primaryElb = markedPrimary.push;\n } else if (sources.length > 0) {\n // Use first source as default\n primaryElb = sources[0].push;\n }\n\n return {\n collector: instance,\n elb: primaryElb as ElbPush,\n };\n}\n"],"mappings":";AAwBO,IAAM,WAAwD;AAAA,EACnE,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,KAAK;AAAA,EACL,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,OAAO;AAA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CAAC,EAAE;AAAA,EAC1B;AAEA,SAAO;AAAA,IACL,WAAW;AAAA,IACX,KAAK;AAAA,EACP;AACF;","names":["assign","assign","getId","isObject","collector","on","option","collector","collector","getId","event","assign","isObject","destination","collector","assign","assign","tryCatchAsync","collector","assign","collector"]}
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.1.2",
4
+ "version": "0.2.0",
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.1.2"
21
+ "@walkeros/core": "0.2.0"
22
22
  },
23
23
  "devDependencies": {},
24
24
  "repository": {