@walkeros/collector 0.5.1-next.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -32,10 +32,9 @@ interface CodeMapping extends Mapping.Rule<CodeMapping> {
32
32
  type Types = Destination.Types<Settings, CodeMapping>;
33
33
  type Config = Destination.Config<Types>;
34
34
  type Context = Destination.Context<Types>;
35
- type InitContext = Destination.InitContext<Types>;
36
35
  type PushContext = Destination.PushContext<Types>;
37
36
  type PushBatchContext = Destination.PushBatchContext<Types>;
38
- type InitFn = (context: InitContext) => void;
37
+ type InitFn = (context: Context) => void;
39
38
  type OnFn = (type: On.Types, context: Context) => void;
40
39
  type PushFn = (event: WalkerOS.Event, context: PushContext) => void;
41
40
  type PushBatchFn = (batch: Destination.Batch<CodeMapping>, context: PushBatchContext) => void;
@@ -43,7 +42,6 @@ type PushBatchFn = (batch: Destination.Batch<CodeMapping>, context: PushBatchCon
43
42
  type code_CodeMapping = CodeMapping;
44
43
  type code_Config = Config;
45
44
  type code_Context = Context;
46
- type code_InitContext = InitContext;
47
45
  type code_InitFn = InitFn;
48
46
  type code_OnFn = OnFn;
49
47
  type code_PushBatchContext = PushBatchContext;
@@ -53,7 +51,7 @@ type code_PushFn = PushFn;
53
51
  type code_Settings = Settings;
54
52
  type code_Types = Types;
55
53
  declare namespace code {
56
- export type { code_CodeMapping as CodeMapping, code_Config as Config, code_Context as Context, code_InitContext as InitContext, code_InitFn as InitFn, code_OnFn as OnFn, code_PushBatchContext as PushBatchContext, code_PushBatchFn as PushBatchFn, code_PushContext as PushContext, code_PushFn as PushFn, code_Settings as Settings, code_Types as Types };
54
+ export type { code_CodeMapping as CodeMapping, code_Config as Config, code_Context as Context, code_InitFn as InitFn, code_OnFn as OnFn, code_PushBatchContext as PushBatchContext, code_PushBatchFn as PushBatchFn, code_PushContext as PushContext, code_PushFn as PushFn, code_Settings as Settings, code_Types as Types };
57
55
  }
58
56
 
59
57
  declare const Commands: Record<CommandTypes, Collector.CommandType>;
@@ -101,19 +99,24 @@ declare function addDestination(collector: Collector.Instance, data: Destination
101
99
  *
102
100
  * @param collector - The walkerOS collector instance.
103
101
  * @param event - The event to push.
102
+ * @param meta - Optional metadata with id and ingest.
104
103
  * @param destinations - The destinations to push to.
105
104
  * @returns The result of the push operation.
106
105
  */
107
- declare function pushToDestinations(collector: Collector.Instance, event?: WalkerOS.Event, destinations?: Collector.Destinations): Promise<Elb.PushResult>;
106
+ declare function pushToDestinations(collector: Collector.Instance, event?: WalkerOS.Event, meta?: {
107
+ id?: string;
108
+ ingest?: unknown;
109
+ }, destinations?: Collector.Destinations): Promise<Elb.PushResult>;
108
110
  /**
109
111
  * Initializes a destination.
110
112
  *
111
113
  * @template Destination
112
114
  * @param collector - The walkerOS collector instance.
113
115
  * @param destination - The destination to initialize.
116
+ * @param destId - The destination ID.
114
117
  * @returns Whether the destination was initialized successfully.
115
118
  */
116
- declare function destinationInit<Destination extends Destination.Instance>(collector: Collector.Instance, destination: Destination): Promise<boolean>;
119
+ declare function destinationInit<Destination extends Destination.Instance>(collector: Collector.Instance, destination: Destination, destId: string): Promise<boolean>;
117
120
  /**
118
121
  * Pushes an event to a single destination.
119
122
  * Handles mapping, batching, and consent checks.
@@ -121,10 +124,12 @@ declare function destinationInit<Destination extends Destination.Instance>(colle
121
124
  * @template Destination
122
125
  * @param collector - The walkerOS collector instance.
123
126
  * @param destination - The destination to push to.
127
+ * @param destId - The destination ID.
124
128
  * @param event - The event to push.
129
+ * @param ingest - Optional ingest metadata (frozen, same reference).
125
130
  * @returns Whether the event was pushed successfully.
126
131
  */
127
- declare function destinationPush<Destination extends Destination.Instance>(collector: Collector.Instance, destination: Destination, event: WalkerOS.Event): Promise<boolean>;
132
+ declare function destinationPush<Destination extends Destination.Instance>(collector: Collector.Instance, destination: Destination, destId: string, event: WalkerOS.Event, ingest?: unknown): Promise<unknown>;
128
133
  /**
129
134
  * Creates a standardized result object for push operations.
130
135
  *
package/dist/index.d.ts CHANGED
@@ -32,10 +32,9 @@ interface CodeMapping extends Mapping.Rule<CodeMapping> {
32
32
  type Types = Destination.Types<Settings, CodeMapping>;
33
33
  type Config = Destination.Config<Types>;
34
34
  type Context = Destination.Context<Types>;
35
- type InitContext = Destination.InitContext<Types>;
36
35
  type PushContext = Destination.PushContext<Types>;
37
36
  type PushBatchContext = Destination.PushBatchContext<Types>;
38
- type InitFn = (context: InitContext) => void;
37
+ type InitFn = (context: Context) => void;
39
38
  type OnFn = (type: On.Types, context: Context) => void;
40
39
  type PushFn = (event: WalkerOS.Event, context: PushContext) => void;
41
40
  type PushBatchFn = (batch: Destination.Batch<CodeMapping>, context: PushBatchContext) => void;
@@ -43,7 +42,6 @@ type PushBatchFn = (batch: Destination.Batch<CodeMapping>, context: PushBatchCon
43
42
  type code_CodeMapping = CodeMapping;
44
43
  type code_Config = Config;
45
44
  type code_Context = Context;
46
- type code_InitContext = InitContext;
47
45
  type code_InitFn = InitFn;
48
46
  type code_OnFn = OnFn;
49
47
  type code_PushBatchContext = PushBatchContext;
@@ -53,7 +51,7 @@ type code_PushFn = PushFn;
53
51
  type code_Settings = Settings;
54
52
  type code_Types = Types;
55
53
  declare namespace code {
56
- export type { code_CodeMapping as CodeMapping, code_Config as Config, code_Context as Context, code_InitContext as InitContext, code_InitFn as InitFn, code_OnFn as OnFn, code_PushBatchContext as PushBatchContext, code_PushBatchFn as PushBatchFn, code_PushContext as PushContext, code_PushFn as PushFn, code_Settings as Settings, code_Types as Types };
54
+ export type { code_CodeMapping as CodeMapping, code_Config as Config, code_Context as Context, code_InitFn as InitFn, code_OnFn as OnFn, code_PushBatchContext as PushBatchContext, code_PushBatchFn as PushBatchFn, code_PushContext as PushContext, code_PushFn as PushFn, code_Settings as Settings, code_Types as Types };
57
55
  }
58
56
 
59
57
  declare const Commands: Record<CommandTypes, Collector.CommandType>;
@@ -101,19 +99,24 @@ declare function addDestination(collector: Collector.Instance, data: Destination
101
99
  *
102
100
  * @param collector - The walkerOS collector instance.
103
101
  * @param event - The event to push.
102
+ * @param meta - Optional metadata with id and ingest.
104
103
  * @param destinations - The destinations to push to.
105
104
  * @returns The result of the push operation.
106
105
  */
107
- declare function pushToDestinations(collector: Collector.Instance, event?: WalkerOS.Event, destinations?: Collector.Destinations): Promise<Elb.PushResult>;
106
+ declare function pushToDestinations(collector: Collector.Instance, event?: WalkerOS.Event, meta?: {
107
+ id?: string;
108
+ ingest?: unknown;
109
+ }, destinations?: Collector.Destinations): Promise<Elb.PushResult>;
108
110
  /**
109
111
  * Initializes a destination.
110
112
  *
111
113
  * @template Destination
112
114
  * @param collector - The walkerOS collector instance.
113
115
  * @param destination - The destination to initialize.
116
+ * @param destId - The destination ID.
114
117
  * @returns Whether the destination was initialized successfully.
115
118
  */
116
- declare function destinationInit<Destination extends Destination.Instance>(collector: Collector.Instance, destination: Destination): Promise<boolean>;
119
+ declare function destinationInit<Destination extends Destination.Instance>(collector: Collector.Instance, destination: Destination, destId: string): Promise<boolean>;
117
120
  /**
118
121
  * Pushes an event to a single destination.
119
122
  * Handles mapping, batching, and consent checks.
@@ -121,10 +124,12 @@ declare function destinationInit<Destination extends Destination.Instance>(colle
121
124
  * @template Destination
122
125
  * @param collector - The walkerOS collector instance.
123
126
  * @param destination - The destination to push to.
127
+ * @param destId - The destination ID.
124
128
  * @param event - The event to push.
129
+ * @param ingest - Optional ingest metadata (frozen, same reference).
125
130
  * @returns Whether the event was pushed successfully.
126
131
  */
127
- declare function destinationPush<Destination extends Destination.Instance>(collector: Collector.Instance, destination: Destination, event: WalkerOS.Event): Promise<boolean>;
132
+ declare function destinationPush<Destination extends Destination.Instance>(collector: Collector.Instance, destination: Destination, destId: string, event: WalkerOS.Event, ingest?: unknown): Promise<unknown>;
128
133
  /**
129
134
  * Creates a standardized result object for push operations.
130
135
  *
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,n=Object.defineProperty,t=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,a={};((e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})})(a,{Code:()=>c,Commands:()=>i,Const:()=>r,addDestination:()=>f,commonHandleCommand:()=>D,createEvent:()=>P,createPush:()=>R,createPushResult:()=>b,destinationCode:()=>g,destinationInit:()=>m,destinationPush:()=>h,initDestinations:()=>y,initSources:()=>I,mergeEnvironments:()=>v,on:()=>C,onApply:()=>q,pushToDestinations:()=>p,runCollector:()=>x,setConsent:()=>j,startFlow:()=>$}),module.exports=(e=a,((e,a,c,i)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of o(a))s.call(e,r)||r===c||n(e,r,{get:()=>a[r],enumerable:!(i=t(a,r))||i.enumerable});return e})(n({},"__esModule",{value:!0}),e));var c={},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"},r={Commands:i,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},u=require("@walkeros/core"),l=require("@walkeros/core"),g={type:"code",config:{},init(e){const{config:n,logger:t}=e,o=n.settings,s=o?.scripts;if(s&&"undefined"!=typeof document)for(const e of s){const n=document.createElement("script");n.src=e,n.async=!0,document.head.appendChild(n)}const a=o?.init;if(a)try{new Function("context",a)(e)}catch(e){t.error("Code destination init error:",e)}},push(e,n){const{mapping:t,config:o,logger:s}=n,a=t?.push??o.settings?.push;if(a)try{new Function("event","context",a)(e,n)}catch(e){s.error("Code destination push error:",e)}},pushBatch(e,n){const{mapping:t,config:o,logger:s}=n,a=t?.pushBatch??o.settings?.pushBatch;if(a)try{new Function("batch","context",a)(e,n)}catch(e){s.error("Code destination pushBatch error:",e)}},on(e,n){const{config:t,logger:o}=n,s=t.settings?.on;if(s)try{new Function("type","context",s)(e,n)}catch(e){o.error("Code destination on error:",e)}}};function d(e){return!0===e?g:e}async function f(e,n,t){const{code:o,config:s={},env:a={}}=n,c=t||s||{init:!1},i=d(o),r={...i,config:c,env:v(i.env,a)};let u=r.config.id;if(!u)do{u=(0,l.getId)(4)}while(e.destinations[u]);return e.destinations[u]=r,!1!==r.config.queue&&(r.queue=[...e.queue]),p(e,void 0,{[u]:r})}async function p(e,n,t){const{allowed:o,consent:s,globals:a,user:c}=e;if(!o)return b({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const i=await Promise.all(Object.entries(t||{}).map(async([t,o])=>{let i=(o.queue||[]).map(e=>({...e,consent:s}));if(o.queue=[],n){const e=(0,l.clone)(n);i.push(e)}if(!i.length)return{id:t,destination:o,skipped:!0};const r=[],u=i.filter(e=>{const n=(0,l.getGrantedConsent)(o.config.consent,s,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(o.queue.concat(u),!r.length)return{id:t,destination:o,queue:i};if(!await(0,l.tryCatchAsync)(m)(e,o))return{id:t,destination:o,queue:i};let g=!1;return o.dlq||(o.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,l.assign)(a,n.globals),n.user=(0,l.assign)(c,n.user),await(0,l.tryCatchAsync)(h,t=>{const s=o.type||"unknown";return e.logger.scope(s).error("Push failed",{error:t,event:n.name}),g=!0,o.dlq.push([n,t]),!1})(e,o,n),n))),{id:t,destination:o,error:g}})),r=[],u=[],g=[];for(const e of i){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),u.push(t)):r.push(t)}return b({ok:!g.length,event:n,successful:r,queued:u,failed:g})}async function m(e,n){if(n.init&&!n.config.init){const t=n.type||"unknown",o=e.logger.scope(t),s={collector:e,config:n.config,env:v(n.env,n.config.env),logger:o};o.debug("init");const a=await(0,l.useHooks)(n.init,"DestinationInit",e.hooks)(s);if(!1===a)return a;n.config={...a||n.config,init:!0},o.debug("init done")}return!0}async function h(e,n,t){const{config:o}=n,s=await(0,l.processEventMapping)(t,o,e);if(s.ignore)return!1;const a=n.type||"unknown",c=e.logger.scope(a),i={collector:e,config:o,data:s.data,mapping:s.mapping,env:v(n.env,o.env),logger:c},r=s.mapping,u=s.mappingKey||"* *";if(r?.batch&&n.pushBatch){if(n.batches=n.batches||{},!n.batches[u]){const t={key:u,events:[],data:[]};n.batches[u]={batched:t,batchFn:(0,l.debounce)(()=>{const t=n.batches[u].batched,s={collector:e,config:o,data:void 0,mapping:r,env:v(n.env,o.env),logger:c};c.debug("push batch",{events:t.events.length}),(0,l.useHooks)(n.pushBatch,"DestinationPushBatch",e.hooks)(t,s),c.debug("push batch done"),t.events=[],t.data=[]},r.batch)}}const t=n.batches[u];t.batched.events.push(s.event),(0,l.isDefined)(s.data)&&t.batched.data.push(s.data),t.batchFn()}else c.debug("push",{event:s.event.name}),await(0,l.useHooks)(n.push,"DestinationPush",e.hooks)(s.event,i),c.debug("push done");return!0}function b(e){return(0,l.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function y(e,n={}){const t={};for(const[e,o]of Object.entries(n)){const{code:n,config:s={},env:a={}}=o,c=d(n),i={...c.config,...s},r=v(c.env,a);t[e]={...c,config:i,env:r}}return t}function v(e,n){return e||n?n?e&&(0,l.isObject)(e)&&(0,l.isObject)(n)?{...e,...n}:n:e:{}}var w=require("@walkeros/core"),k=require("@walkeros/core");function C(e,n,t){const o=e.on,s=o[n]||[],a=(0,w.isArray)(t)?t:[t];a.forEach(e=>{s.push(e)}),o[n]=s,q(e,n,a)}function q(e,n,t,o){let s,a=t||[];switch(t||(a=e.on[n]||[]),n){case r.Commands.Consent:s=o||e.consent;break;case r.Commands.Session:s=e.session;break;case r.Commands.Ready:case r.Commands.Run:default:s=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,k.tryCatch)(e.on)(n,s)}),Object.values(e.destinations).forEach(t=>{if(t.on){const o=t.type||"unknown",a=e.logger.scope(o).scope("on").scope(n),c={collector:e,config:t.config,data:s,env:v(t.env,t.config.env),logger:a};(0,k.tryCatch)(t.on)(n,c)}}),a.length)switch(n){case r.Commands.Consent:!function(e,n,t){const o=t||e.consent;n.forEach(n=>{Object.keys(o).filter(e=>e in n).forEach(t=>{(0,k.tryCatch)(n[t])(e,o)})})}(e,a,o);break;case r.Commands.Ready:case r.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,k.tryCatch)(n)(e)})}(e,a);break;case r.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,k.tryCatch)(n)(e,e.session)})}(e,a)}}async function j(e,n){const{consent:t}=e;let o=!1;const s={};return Object.entries(n).forEach(([e,n])=>{const t=!!n;s[e]=t,o=o||t}),e.consent=(0,u.assign)(t,s),q(e,"consent",void 0,s),o?p(e):b({ok:!0})}var O=require("@walkeros/core"),E=require("@walkeros/core"),A=require("@walkeros/core");async function D(e,n,t,o){let s;switch(n){case r.Commands.Config:(0,A.isObject)(t)&&(0,E.assign)(e.config,t,{shallow:!1});break;case r.Commands.Consent:(0,A.isObject)(t)&&(s=await j(e,t));break;case r.Commands.Custom:(0,A.isObject)(t)&&(e.custom=(0,E.assign)(e.custom,t));break;case r.Commands.Destination:(0,A.isObject)(t)&&(0,E.isFunction)(t.push)&&(s=await f(e,{code:t},o));break;case r.Commands.Globals:(0,A.isObject)(t)&&(e.globals=(0,E.assign)(e.globals,t));break;case r.Commands.On:(0,E.isString)(t)&&C(e,t,o);break;case r.Commands.Ready:q(e,"ready");break;case r.Commands.Run:s=await x(e,t);break;case r.Commands.Session:q(e,"session");break;case r.Commands.User:(0,A.isObject)(t)&&(0,E.assign)(e.user,t,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function P(e,n){if(!n.name)throw new Error("Event name is required");const[t,o]=n.name.split(" ");if(!t||!o)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:c=e.count}=n,{name:i=`${t} ${o}`,data:r={},context:u={},globals:l=e.globals,custom:g={},user:d=e.user,nested:f=[],consent:p=e.consent,id:m=`${s}-${a}-${c}`,trigger:h="",entity:b=t,action:y=o,timing:v=0,version:w={source:e.version,tagging:e.config.tagging||0},source:k={type:"collector",id:"",previous_id:""}}=n;return{name:i,data:r,context:u,globals:l,custom:g,user:d,nested:f,consent:p,id:m,trigger:h,entity:b,action:y,timestamp:s,timing:v,group:a,count:c,version:w,source:k}}async function x(e,n){e.allowed=!0,e.count=0,e.group=(0,E.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,E.assign)(e.consent,n.consent)),n.user&&(e.user=(0,E.assign)(e.user,n.user)),n.globals&&(e.globals=(0,E.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,E.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await p(e);return q(e,"run"),t}var S=require("@walkeros/core");function R(e,n){return(0,S.useHooks)(async(t,o={})=>await(0,S.tryCatchAsync)(async()=>{let s=t;if(o.mapping){const n=await(0,S.processEventMapping)(s,o.mapping,e);if(n.ignore)return b({ok:!0});if(o.mapping.consent){if(!(0,S.getGrantedConsent)(o.mapping.consent,e.consent,n.event.consent))return b({ok:!0})}s=n.event}const a=n(s),c=P(e,a);return await p(e,c)},()=>b({ok:!1}))(),"Push",e.hooks)}var F=require("@walkeros/core");async function B(e){const n=(0,O.assign)({globalsStatic:{},sessionStatic:{},tagging:0,run:!0},e,{merge:!1,extend:!1}),t={level:e.logger?.level,handler:e.logger?.handler},o=(0,O.createLogger)(t),s={...n.globalsStatic,...e.globals},a={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},logger:o,on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.5.0",sources:{},push:void 0,command:void 0};return a.push=R(a,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.command=function(e,n){return(0,F.useHooks)(async(t,o,s)=>await(0,F.tryCatchAsync)(async()=>await n(e,t,o,s),()=>b({ok:!1}))(),"Command",e.hooks)}(a,D),a.destinations=await y(0,e.destinations||{}),a}var H=require("@walkeros/core");async function I(e,n={}){const t={};for(const[o,s]of Object.entries(n)){const{code:n,config:a={},env:c={},primary:i}=s,r=(n,t={})=>e.push(n,{...t,mapping:a}),u=e.logger.scope("source").scope(o),l={push:r,command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:u,...c},g=await(0,H.tryCatchAsync)(n)(a,l);if(!g)continue;const d=g.type||"unknown",f=e.logger.scope(d).scope(o);l.logger=f,i&&(g.config={...g.config,primary:i}),t[o]=g}return t}async function $(e){e=e||{};const n=await B(e),t=(o=n,{type:"elb",config:{},push:async(e,n,t,s,a,c)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return o.command(s,n,t)}let i;if("string"==typeof e)i={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(i.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};i=e,n&&"object"==typeof n&&!Array.isArray(n)&&(i.data={...i.data||{},...n})}return s&&"object"==typeof s&&(i.context=s),a&&Array.isArray(a)&&(i.nested=a),c&&"object"==typeof c&&(i.custom=c),o.push(i)}});var o;n.sources.elb=t;const s=await I(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:c,globals:i,custom:r}=e;a&&await n.command("consent",a),c&&await n.command("user",c),i&&Object.assign(n.globals,i),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=t.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),g=l.find(e=>e.config.primary);return g?u=g.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}//# sourceMappingURL=index.js.map
1
+ "use strict";var e,n=Object.defineProperty,t=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,r={};((e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})})(r,{Code:()=>i,Commands:()=>c,Const:()=>a,addDestination:()=>w,commonHandleCommand:()=>R,createEvent:()=>F,createPush:()=>M,createPushResult:()=>j,destinationCode:()=>l,destinationInit:()=>k,destinationPush:()=>C,initDestinations:()=>O,initSources:()=>U,mergeEnvironments:()=>q,on:()=>x,onApply:()=>P,pushToDestinations:()=>v,runCollector:()=>B,setConsent:()=>D,startFlow:()=>W}),module.exports=(e=r,((e,r,i,c)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let a of o(r))s.call(e,a)||a===i||n(e,a,{get:()=>r[a],enumerable:!(c=t(r,a))||c.enumerable});return e})(n({},"__esModule",{value:!0}),e));var i={},c={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},a={Commands:c,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},u=require("@walkeros/core"),g=require("@walkeros/core"),l={type:"code",config:{},init(e){const{config:n,logger:t}=e,o=n.settings,s=o?.scripts;if(s&&"undefined"!=typeof document)for(const e of s){const n=document.createElement("script");n.src=e,n.async=!0,document.head.appendChild(n)}const r=o?.init;if(r)try{new Function("context",r)(e)}catch(e){t.error("Code destination init error:",e)}},push(e,n){const{rule:t,config:o,logger:s}=n,r=t?.push??o.settings?.push;if(r)try{new Function("event","context",r)(e,n)}catch(e){s.error("Code destination push error:",e)}},pushBatch(e,n){const{rule:t,config:o,logger:s}=n,r=t?.pushBatch??o.settings?.pushBatch;if(r)try{new Function("batch","context",r)(e,n)}catch(e){s.error("Code destination pushBatch error:",e)}},on(e,n){const{config:t,logger:o}=n,s=t.settings?.on;if(s)try{new Function("type","context",s)(e,n)}catch(e){o.error("Code destination on error:",e)}}},f=require("@walkeros/core");function d(e,n={}){if(!e)return[];const t=[],o=new Set;let s=e;for(;s&&n[s]&&!o.has(s);)o.add(s),t.push(s),s=n[s].next;return t}async function m(e,n,t){if(n.init&&!n.config.init){const o=n.type||"unknown",s=e.logger.scope(`transformer:${o}`),r={collector:e,logger:s,id:t,config:n.config,env:b(n.config.env)};s.debug("init");const i=await(0,f.useHooks)(n.init,"TransformerInit",e.hooks)(r);if(!1===i)return!1;n.config={...i||n.config,init:!0},s.debug("init done")}return!0}async function p(e,n,t,o,s){const r=n.type||"unknown",i=e.logger.scope(`transformer:${r}`),c={collector:e,logger:i,id:t,ingest:s,config:n.config,env:b(n.config.env)};i.debug("push",{event:o.name});const a=await(0,f.useHooks)(n.push,"TransformerPush",e.hooks)(o,c);return i.debug("push done"),a}async function h(e,n,t,o,s){let r=o;for(const o of t){const t=n[o];if(!t){e.logger.info(`Transformer not found: ${o}`);continue}if(!await(0,f.tryCatchAsync)(m)(e,t,o))return e.logger.info(`Transformer init failed: ${o}`),null;const i=await(0,f.tryCatchAsync)(p,n=>(e.logger.scope(`transformer:${t.type||"unknown"}`).error("Push failed",{error:n}),!1))(e,t,o,r,s);if(!1===i)return null;void 0!==i&&(r=i)}return r}function b(e){return e&&(0,f.isObject)(e)?e:{}}function y(e){return!0===e?l:e}async function w(e,n,t){const{code:o,config:s={},env:r={}}=n,i=t||s||{init:!1},c=y(o),a={...c,config:i,env:q(c.env,r)};let u=a.config.id;if(!u)do{u=(0,g.getId)(4)}while(e.destinations[u]);return e.destinations[u]=a,!1!==a.config.queue&&(a.queue=[...e.queue]),v(e,void 0,{},{[u]:a})}async function v(e,n,t={},o){const{allowed:s,consent:r,globals:i,user:c}=e;if(!s)return j({ok:!1});n&&e.queue.push(n),o||(o=e.destinations);const a=await Promise.all(Object.entries(o||{}).map(async([o,s])=>{let a=(s.queue||[]).map(e=>({...e,consent:r}));if(s.queue=[],n){const e=(0,g.clone)(n);a.push(e)}if(!a.length)return{id:o,destination:s,skipped:!0};const u=[],l=a.filter(e=>{const n=(0,g.getGrantedConsent)(s.config.consent,r,e.consent);return!n||(e.consent=n,u.push(e),!1)});if(s.queue.concat(l),!u.length)return{id:o,destination:s,queue:a};if(!await(0,g.tryCatchAsync)(k)(e,s,o))return{id:o,destination:s,queue:a};let f,d;s.dlq||(s.dlq=[]);const m=e.transformerChain?.post?.[o]||[];return await Promise.all(u.map(async n=>{n.globals=(0,g.assign)(i,n.globals),n.user=(0,g.assign)(c,n.user);let r=n;if(m.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const o=await h(e,e.transformers,m,n,t.ingest);if(null===o)return n;r=o}const a=await(0,g.tryCatchAsync)(C,n=>{const t=s.type||"unknown";e.logger.scope(t).error("Push failed",{error:n,event:r.name}),f=n,s.dlq.push([r,n])})(e,s,o,r,t.ingest);return void 0!==a&&(d=a),n})),{id:o,destination:s,error:f,response:d}})),u={},l={},f={};for(const e of a){if(e.skipped)continue;const n=e.destination,t={type:n.type||"unknown",data:e.response};e.error?(t.error=e.error,f[e.id]=t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),l[e.id]=t):u[e.id]=t}return j({event:n,...Object.keys(u).length&&{done:u},...Object.keys(l).length&&{queued:l},...Object.keys(f).length&&{failed:f}})}async function k(e,n,t){if(n.init&&!n.config.init){const o=n.type||"unknown",s=e.logger.scope(o),r={collector:e,logger:s,id:t,config:n.config,env:q(n.env,n.config.env)};s.debug("init");const i=await(0,g.useHooks)(n.init,"DestinationInit",e.hooks)(r);if(!1===i)return i;n.config={...i||n.config,init:!0},s.debug("init done")}return!0}async function C(e,n,t,o,s){const{config:r}=n,i=await(0,g.processEventMapping)(o,r,e);if(i.ignore)return!1;const c=n.type||"unknown",a=e.logger.scope(c),u={collector:e,logger:a,id:t,config:r,data:i.data,rule:i.mapping,ingest:s,env:q(n.env,r.env)},l=i.mapping,f=i.mappingKey||"* *";if(!l?.batch||!n.pushBatch){a.debug("push",{event:i.event.name});const t=await(0,g.useHooks)(n.push,"DestinationPush",e.hooks)(i.event,u);return a.debug("push done"),t}{if(n.batches=n.batches||{},!n.batches[f]){const o={key:f,events:[],data:[]};n.batches[f]={batched:o,batchFn:(0,g.debounce)(()=>{const o=n.batches[f].batched,i={collector:e,logger:a,id:t,config:r,data:void 0,rule:l,ingest:s,env:q(n.env,r.env)};a.debug("push batch",{events:o.events.length}),(0,g.useHooks)(n.pushBatch,"DestinationPushBatch",e.hooks)(o,i),a.debug("push batch done"),o.events=[],o.data=[]},l.batch)}}const o=n.batches[f];o.batched.events.push(i.event),(0,g.isDefined)(i.data)&&o.batched.data.push(i.data),o.batchFn()}return!0}function j(e){return{ok:!e?.failed,...e}}async function O(e,n={}){const t={};for(const[e,o]of Object.entries(n)){const{code:n,config:s={},env:r={}}=o,i=y(n),c={...i.config,...s},a=q(i.env,r);t[e]={...i,config:c,env:a}}return t}function q(e,n){return e||n?n?e&&(0,g.isObject)(e)&&(0,g.isObject)(n)?{...e,...n}:n:e:{}}var E=require("@walkeros/core"),A=require("@walkeros/core");function x(e,n,t){const o=e.on,s=o[n]||[],r=(0,E.isArray)(t)?t:[t];r.forEach(e=>{s.push(e)}),o[n]=s,P(e,n,r)}function P(e,n,t,o){let s,r=t||[];switch(t||(r=e.on[n]||[]),n){case a.Commands.Consent:s=o||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&&(0,A.tryCatch)(e.on)(n,s)}),Object.entries(e.destinations).forEach(([t,o])=>{if(o.on){const r=o.type||"unknown",i=e.logger.scope(r).scope("on").scope(n),c={collector:e,logger:i,id:t,config:o.config,data:s,env:q(o.env,o.config.env)};(0,A.tryCatch)(o.on)(n,c)}}),r.length)switch(n){case a.Commands.Consent:!function(e,n,t){const o=t||e.consent;n.forEach(n=>{Object.keys(o).filter(e=>e in n).forEach(t=>{(0,A.tryCatch)(n[t])(e,o)})})}(e,r,o);break;case a.Commands.Ready:case a.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,A.tryCatch)(n)(e)})}(e,r);break;case a.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,A.tryCatch)(n)(e,e.session)})}(e,r)}}async function D(e,n){const{consent:t}=e;let o=!1;const s={};return Object.entries(n).forEach(([e,n])=>{const t=!!n;s[e]=t,o=o||t}),e.consent=(0,u.assign)(t,s),P(e,"consent",void 0,s),o?v(e):j({ok:!0})}var S=require("@walkeros/core"),$=require("@walkeros/core"),H=require("@walkeros/core");async function R(e,n,t,o){let s;switch(n){case a.Commands.Config:(0,H.isObject)(t)&&(0,$.assign)(e.config,t,{shallow:!1});break;case a.Commands.Consent:(0,H.isObject)(t)&&(s=await D(e,t));break;case a.Commands.Custom:(0,H.isObject)(t)&&(e.custom=(0,$.assign)(e.custom,t));break;case a.Commands.Destination:(0,H.isObject)(t)&&(0,$.isFunction)(t.push)&&(s=await w(e,{code:t},o));break;case a.Commands.Globals:(0,H.isObject)(t)&&(e.globals=(0,$.assign)(e.globals,t));break;case a.Commands.On:(0,$.isString)(t)&&x(e,t,o);break;case a.Commands.Ready:P(e,"ready");break;case a.Commands.Run:s=await B(e,t);break;case a.Commands.Session:P(e,"session");break;case a.Commands.User:(0,H.isObject)(t)&&(0,$.assign)(e.user,t,{shallow:!1})}return s||j({ok:!0})}function F(e,n){if(!n.name)throw new Error("Event name is required");const[t,o]=n.name.split(" ");if(!t||!o)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:r=e.group,count:i=e.count}=n,{name:c=`${t} ${o}`,data:a={},context:u={},globals:g=e.globals,custom:l={},user:f=e.user,nested:d=[],consent:m=e.consent,id:p=`${s}-${r}-${i}`,trigger:h="",entity:b=t,action:y=o,timing:w=0,version:v={source:e.version,tagging:e.config.tagging||0},source:k={type:"collector",id:"",previous_id:""}}=n;return{name:c,data:a,context:u,globals:g,custom:l,user:f,nested:d,consent:m,id:p,trigger:h,entity:b,action:y,timestamp:s,timing:w,group:r,count:i,version:v,source:k}}async function B(e,n){e.allowed=!0,e.count=0,e.group=(0,$.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,$.assign)(e.consent,n.consent)),n.user&&(e.user=(0,$.assign)(e.user,n.user)),n.globals&&(e.globals=(0,$.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,$.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await v(e);return P(e,"run"),t}var I=require("@walkeros/core");function M(e,n){return(0,I.useHooks)(async(t,o={})=>await(0,I.tryCatchAsync)(async()=>{const{id:s,ingest:r,mapping:i,preChain:c}=o;let a=t;const u=r?Object.freeze(r):void 0;if(i){const n=await(0,I.processEventMapping)(a,i,e);if(n.ignore)return j({ok:!0});if(i.consent){if(!(0,I.getGrantedConsent)(i.consent,e.consent,n.event.consent))return j({ok:!0})}a=n.event}if(c?.length&&e.transformers&&Object.keys(e.transformers).length>0){const n=await h(e,e.transformers,c,a,u);if(null===n)return j({ok:!0});a=n}const g=n(a),l=F(e,g);return await v(e,l,{id:s,ingest:u})},()=>j({ok:!1}))(),"Push",e.hooks)}var T=require("@walkeros/core");async function G(e){const n=(0,S.assign)({globalsStatic:{},sessionStatic:{},tagging:0,run:!0},e,{merge:!1,extend:!1}),t={level:e.logger?.level,handler:e.logger?.handler},o=(0,S.createLogger)(t),s={...n.globalsStatic,...e.globals},r={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},transformers:{},transformerChain:{pre:[],post:{}},globals:s,group:"",hooks:{},logger:o,on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.6.0",sources:{},push:void 0,command:void 0};return r.push=M(r,e=>({timing:Math.round((Date.now()-r.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),r.command=function(e,n){return(0,T.useHooks)(async(t,o,s)=>await(0,T.tryCatchAsync)(async()=>await n(e,t,o,s),()=>j({ok:!1}))(),"Command",e.hooks)}(r,R),r.destinations=await O(0,e.destinations||{}),r.transformers=await async function(e,n={}){const t={};for(const[o,s]of Object.entries(n)){const{code:n,config:r={},env:i={}}=s,c=e.logger.scope("transformer").scope(o),a={collector:e,logger:c,id:o,config:r,env:i},u=await n(a);t[o]=u}return t}(r,e.transformers||{}),r}var _=require("@walkeros/core");function L(e){const n={};for(const[t,o]of Object.entries(e))n[t]={next:o.config.next};return n}async function U(e,n={}){const t={};for(const[o,s]of Object.entries(n)){const{code:n,config:r={},env:i={},primary:c,next:a}=s;let u;const g=d(a,L(e.transformers)),l=(n,t={})=>e.push(n,{...t,id:o,ingest:u,mapping:r,preChain:g}),f=e.logger.scope("source").scope(o),m={push:l,command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:f,...i},p={collector:e,logger:f,id:o,config:r,env:m,setIngest:async n=>{u=r.ingest?await(0,_.getMappingValue)(n,r.ingest,{collector:e}):void 0}},h=await(0,_.tryCatchAsync)(n)(p);if(!h)continue;const b=h.type||"unknown",y=e.logger.scope(b).scope(o);m.logger=y,c&&(h.config={...h.config,primary:c}),t[o]=h}return t}async function W(e){e=e||{};const n=await G(e),t=(o=n,{type:"elb",config:{},push:async(e,n,t,s,r,i)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return o.command(s,n,t)}let c;if("string"==typeof e)c={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(c.data=n);else{if(!e||"object"!=typeof e)return j({ok:!1});c=e,n&&"object"==typeof n&&!Array.isArray(n)&&(c.data={...c.data||{},...n})}return s&&"object"==typeof s&&(c.context=s),r&&Array.isArray(r)&&(c.nested=r),i&&"object"==typeof i&&(c.custom=i),o.push(c)}});var o;n.sources.elb=t;const s=await U(n,e.sources||{});Object.assign(n.sources,s);const{consent:r,user:i,globals:c,custom:a}=e;r&&await n.command("consent",r),i&&await n.command("user",i),c&&Object.assign(n.globals,c),a&&Object.assign(n.custom,a),n.config.run&&await n.command("run");let u=t.push;const g=Object.values(n.sources).filter(e=>"elb"!==e.type),l=g.find(e=>e.config.primary);return l?u=l.push:g.length>0&&(u=g[0].push),{collector:n,elb:u}}//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/types/code.ts","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/destination-code.ts","../src/on.ts","../src/collector.ts","../src/handle.ts","../src/push.ts","../src/command.ts","../src/elb.ts","../src/source.ts","../src/flow.ts"],"sourcesContent":["export * from './types';\n\nexport * from './constants';\n\nexport * from './consent';\nexport * from './flow';\nexport * from './push';\nexport * from './destination';\nexport * from './destination-code';\nexport * from './handle';\nexport * from './on';\nexport * from './source';\n","import type { Destination, Mapping, On, WalkerOS } from '@walkeros/core';\n\nexport interface Settings {\n scripts?: string[];\n init?: string;\n on?: string;\n push?: string;\n pushBatch?: string;\n}\n\nexport interface CodeMapping extends Mapping.Rule<CodeMapping> {\n push?: string;\n pushBatch?: string;\n}\n\nexport type Types = Destination.Types<Settings, CodeMapping>;\nexport type Config = Destination.Config<Types>;\nexport type Context = Destination.Context<Types>;\nexport type InitContext = Destination.InitContext<Types>;\nexport type PushContext = Destination.PushContext<Types>;\nexport type PushBatchContext = Destination.PushBatchContext<Types>;\n\nexport type InitFn = (context: InitContext) => void;\nexport type OnFn = (type: On.Types, context: Context) => void;\nexport type PushFn = (event: WalkerOS.Event, context: PushContext) => void;\nexport type PushBatchFn = (\n batch: Destination.Batch<CodeMapping>,\n context: PushBatchContext,\n) => void;\n","import type { Collector } from '@walkeros/core';\nimport type { CommandTypes, StorageType } from './types/collector';\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\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 isDefined,\n isObject,\n processEventMapping,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { destinationCode } from './destination-code';\n\nfunction resolveCode(code: Destination.Instance | true): Destination.Instance {\n return code === true ? destinationCode : code;\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 resolved = resolveCode(code);\n const destination: Destination.Instance = {\n ...resolved,\n config,\n env: mergeEnvironments(resolved.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 const currentEvent = clone(event);\n\n // Note: Policy is now applied in processEventMapping() within destinationPush()\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 // Log the error with destination scope\n const destType = destination.type || 'unknown';\n collector.logger.scope(destType).error('Push failed', {\n error: err,\n event: event.name,\n });\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 // Create scoped logger for this destination: [type:id] or [unknown:id]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context = {\n collector,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n logger: destLogger,\n } as Destination.InitContext;\n\n destLogger.debug('init');\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 destLogger.debug('init done');\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\n const processed = await processEventMapping(event, config, collector);\n\n if (processed.ignore) return false;\n\n // Create scoped logger for this destination: [type] or [unknown]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context: Destination.PushContext = {\n collector,\n config,\n data: processed.data,\n mapping: processed.mapping,\n env: mergeEnvironments(destination.env, config.env),\n logger: destLogger,\n };\n\n const eventMapping = processed.mapping;\n const mappingKey = processed.mappingKey || '* *';\n\n if (eventMapping?.batch && destination.pushBatch) {\n // Initialize batch registry on destination (not on shared mapping config)\n destination.batches = destination.batches || {};\n\n // Get or create batch state for this mapping key\n if (!destination.batches[mappingKey]) {\n const batched: Destination.Batch<unknown> = {\n key: mappingKey,\n events: [],\n data: [],\n };\n\n destination.batches[mappingKey] = {\n batched,\n batchFn: debounce(() => {\n const batchState = destination.batches![mappingKey];\n const currentBatched = batchState.batched;\n\n const batchContext: Destination.PushBatchContext = {\n collector,\n config,\n // Note: batch.data contains all transformed data; context.data is for single events\n data: undefined,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n logger: destLogger,\n };\n\n destLogger.debug('push batch', {\n events: currentBatched.events.length,\n });\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n collector.hooks,\n )(currentBatched, batchContext);\n\n destLogger.debug('push batch done');\n\n // Reset batch\n currentBatched.events = [];\n currentBatched.data = [];\n }, eventMapping.batch),\n };\n }\n\n // Add event to batch\n const batchState = destination.batches[mappingKey];\n batchState.batched.events.push(processed.event);\n if (isDefined(processed.data)) batchState.batched.data.push(processed.data);\n\n // Trigger debounced batch\n batchState.batchFn();\n } else {\n destLogger.debug('push', { event: processed.event.name });\n\n // It's time to go to the destination's side now\n await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(processed.event, context);\n\n destLogger.debug('push done');\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 const resolved = resolveCode(code);\n\n const mergedConfig = {\n ...resolved.config,\n ...config,\n };\n\n const mergedEnv = mergeEnvironments(resolved.env, env);\n\n result[name] = {\n ...resolved,\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 */\nexport function 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 { Destination } from '@walkeros/core';\nimport type { CodeMapping, Settings } from './types/code';\n\nexport const destinationCode: Destination.Instance = {\n type: 'code',\n config: {},\n\n init(context) {\n const { config, logger } = context;\n const settings = config.settings as Settings | undefined;\n\n // Inject scripts (fire and forget)\n const scripts = settings?.scripts;\n if (scripts && typeof document !== 'undefined') {\n for (const src of scripts) {\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n document.head.appendChild(script);\n }\n }\n\n // Execute init code\n const initCode = settings?.init;\n if (!initCode) return;\n try {\n const fn = new Function('context', initCode);\n fn(context);\n } catch (e) {\n logger.error('Code destination init error:', e);\n }\n },\n\n push(event, context) {\n const { mapping, config, logger } = context;\n const pushCode =\n (mapping as CodeMapping | undefined)?.push ??\n (config.settings as Settings | undefined)?.push;\n if (!pushCode) return;\n try {\n const fn = new Function('event', 'context', pushCode);\n fn(event, context);\n } catch (e) {\n logger.error('Code destination push error:', e);\n }\n },\n\n pushBatch(batch, context) {\n const { mapping, config, logger } = context;\n const pushBatchCode =\n (mapping as CodeMapping | undefined)?.pushBatch ??\n (config.settings as Settings | undefined)?.pushBatch;\n if (!pushBatchCode) return;\n try {\n const fn = new Function('batch', 'context', pushBatchCode);\n fn(batch, context);\n } catch (e) {\n logger.error('Code destination pushBatch error:', e);\n }\n },\n\n on(type, context) {\n const { config, logger } = context;\n const onCode = (config.settings as Settings | undefined)?.on;\n if (!onCode) return;\n try {\n const fn = new Function('type', 'context', onCode);\n fn(type, context);\n } catch (e) {\n logger.error('Code destination on error:', e);\n }\n },\n};\n\nexport default destinationCode;\n","import type { Collector, On, WalkerOS, Destination } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\nimport { mergeEnvironments } from './destination';\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 const destType = destination.type || 'unknown';\n const destLogger = collector.logger\n .scope(destType)\n .scope('on')\n .scope(type);\n\n const context: Destination.Context = {\n collector,\n config: destination.config,\n data: contextData as Destination.Data,\n env: mergeEnvironments(destination.env, destination.config.env),\n logger: destLogger,\n };\n\n tryCatch(destination.on)(type, context);\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, Logger, WalkerOS } from '@walkeros/core';\nimport { assign, createLogger } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations } from './destination';\nimport { createPush } from './push';\nimport { createCommand } from './command';\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 run: true,\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n // Create logger with config from initConfig\n const loggerConfig: Logger.Config = {\n level: initConfig.logger?.level,\n handler: initConfig.logger?.handler,\n };\n const logger = createLogger(loggerConfig);\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 logger,\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 Collector.PushFn, // Placeholder, will be set below\n command: undefined as unknown as Collector.CommandFn, // Placeholder, will be set below\n };\n\n // Set the push and command functions with the collector reference\n collector.push = createPush(\n collector,\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 collector.command = createCommand(collector, commonHandleCommand);\n\n // Initialize destinations after collector is fully created\n // Sources are initialized in startFlow after ELB source is created\n collector.destinations = await initDestinations(\n collector,\n initConfig.destinations || {},\n );\n\n return collector;\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Const } from './constants';\nimport { addDestination, pushToDestinations } from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject } 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 a full event from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param partialEvent The partial event to transform.\n * @returns The full event.\n */\nexport function createEvent(\n collector: Collector.Instance,\n partialEvent: WalkerOS.PartialEvent,\n): WalkerOS.Event {\n if (!partialEvent.name) throw new Error('Event name is required');\n\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n ++collector.count;\n\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\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 return {\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\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, WalkerOS, Elb } from '@walkeros/core';\nimport {\n getGrantedConsent,\n processEventMapping,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEvent } from './handle';\nimport { pushToDestinations, createPushResult } from './destination';\n\n/**\n * Creates the push function for the collector.\n * Handles source mapping, event creation, and routing to destinations.\n *\n * @param collector - The walkerOS collector instance\n * @param prepareEvent - Function to enrich partial events\n * @returns The push function\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Collector.PushFn {\n return useHooks(\n async (\n event: WalkerOS.DeepPartialEvent,\n context: Collector.PushContext = {},\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n let partialEvent = event;\n\n // Apply source mapping if provided in context\n if (context.mapping) {\n const processed = await processEventMapping(\n partialEvent,\n context.mapping,\n collector,\n );\n\n // Check ignore flag\n if (processed.ignore) {\n return createPushResult({ ok: true });\n }\n\n // Check consent requirements\n if (context.mapping.consent) {\n const grantedConsent = getGrantedConsent(\n context.mapping.consent,\n collector.consent,\n processed.event.consent as WalkerOS.Consent | undefined,\n );\n\n if (!grantedConsent) {\n return createPushResult({ ok: true });\n }\n }\n\n partialEvent = processed.event;\n }\n\n // Prepare event (add timing, source info)\n const enrichedEvent = prepareEvent(partialEvent);\n\n // Create full event\n const fullEvent = createEvent(collector, enrichedEvent);\n\n // Push to destinations\n return await pushToDestinations(collector, fullEvent);\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Collector.PushFn;\n}\n","import type { Collector, Elb } from '@walkeros/core';\nimport type { HandleCommandFn } from './types/collector';\nimport { useHooks, tryCatchAsync } from '@walkeros/core';\nimport { createPushResult } from './destination';\n\n/**\n * Creates the command function for the collector.\n * Handles walker commands (config, consent, destination, etc.)\n *\n * @param collector - The walkerOS collector instance\n * @param handleCommand - Command handler function\n * @returns The command function\n */\nexport function createCommand<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n): Collector.CommandFn {\n return useHooks(\n async (\n command: string,\n data?: unknown,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n return await handleCommand(collector, command, data, options);\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Command',\n collector.hooks,\n ) as Collector.CommandFn;\n}\n","import type { Collector, Source, WalkerOS, Elb } from '@walkeros/core';\n\n/**\n * Creates the default ELB source.\n * Routes between collector.push and collector.command based on input.\n * Provides backward-compatible flexible argument interface.\n *\n * @param collector - The walkerOS collector instance\n * @returns ELB source instance\n */\nexport function createElbSource(\n collector: Collector.Instance,\n): Source.Instance {\n return {\n type: 'elb',\n config: {},\n\n // The push function is the elb() interface users interact with\n push: async (\n eventOrCommand?: unknown,\n data?: unknown,\n options?: unknown,\n context?: unknown,\n nested?: WalkerOS.Entities,\n custom?: WalkerOS.Properties,\n ): Promise<Elb.PushResult> => {\n // Detect walker commands\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n const command = eventOrCommand.replace('walker ', '');\n return collector.command(command, data, options);\n }\n\n // Build event object\n let event: WalkerOS.DeepPartialEvent;\n\n if (typeof eventOrCommand === 'string') {\n // Convert string to object: elb('page view', { title: 'Home' })\n event = { name: eventOrCommand };\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = data as WalkerOS.Properties;\n }\n } else if (eventOrCommand && typeof eventOrCommand === 'object') {\n // Use object directly: elb({ name: 'page view', data: {...} })\n event = eventOrCommand as WalkerOS.DeepPartialEvent;\n // Merge additional data if provided\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = {\n ...(event.data || {}),\n ...(data as WalkerOS.Properties),\n };\n }\n } else {\n // Invalid input\n return { ok: false, successful: [], queued: [], failed: [] };\n }\n\n // Add optional properties if provided\n if (context && typeof context === 'object') {\n event.context = context as WalkerOS.OrderedProperties;\n }\n if (nested && Array.isArray(nested)) {\n event.nested = nested;\n }\n if (custom && typeof custom === 'object') {\n event.custom = custom as WalkerOS.Properties;\n }\n\n // Call collector.push with event object\n return collector.push(event);\n },\n };\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 * @returns Initialized sources\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 // Create wrapped push that auto-applies source mapping config\n const wrappedPush: Collector.PushFn = (\n event: WalkerOS.DeepPartialEvent,\n context: Collector.PushContext = {},\n ) => {\n // Pass source config as mapping in context\n return collector.push(event, {\n ...context,\n mapping: config,\n });\n };\n\n // Create initial logger scoped to sourceId (type will be added after init)\n const initialLogger = collector.logger.scope('source').scope(sourceId);\n\n const cleanEnv: Source.Env = {\n push: wrappedPush,\n command: collector.command,\n sources: collector.sources, // Provide access to all sources for chaining\n elb: collector.sources.elb.push, // ELB source is always available\n logger: initialLogger,\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 // Update logger with actual source type: [type:sourceId] or [unknown:sourceId]\n const sourceType = sourceInstance.type || 'unknown';\n const sourceLogger = collector.logger.scope(sourceType).scope(sourceId);\n cleanEnv.logger = sourceLogger;\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, Elb } from '@walkeros/core';\nimport type { StartFlow } from './types';\nimport { collector } from './collector';\nimport { createElbSource } from './elb';\nimport { initSources } from './source';\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\n // Create and register ELB source first\n const elbSource = createElbSource(instance);\n instance.sources.elb = elbSource;\n\n // Now initialize other sources with ELB source available\n const additionalSources = await initSources(\n instance,\n initConfig.sources || {},\n );\n Object.assign(instance.sources, additionalSources);\n\n const { consent, user, globals, custom } = initConfig;\n\n if (consent) await instance.command('consent', consent);\n if (user) await instance.command('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.command('run');\n\n // Determine the primary elb:\n // 1. Use explicitly marked primary source\n // 2. Use first non-elb source if any exist\n // 3. Fallback to ELB source\n let primaryElb: Elb.Fn = elbSource.push as Elb.Fn;\n\n const sources = Object.values(instance.sources).filter(\n (source) => source.type !== 'elb',\n );\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 as Elb.Fn;\n } else if (sources.length > 0) {\n // Use first source as default\n primaryElb = sources[0].push as Elb.Fn;\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;AAAA;AAAA;AAAA;;;ACAA;;;ACGO,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,EACL,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AACV;AAEA,IAAM,eAA+C;AAAA,EACnD,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS;AACX;AAEA,IAAM,QAAQ;AAAA,EACZ,SAAS;AACX;AAEO,IAAM,QAAQ;A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M,eAAeA,WAAU,OAAO,MAAM,UAAU,EAAE,MAAM,QAAQ;AACtE,aAAS,SAAS;AAGlB,QAAI,SAAS;AACX,qBAAe,SAAS,EAAE,GAAG,eAAe,QAAQ,QAAQ;AAAA,IAC9D;AAEA,WAAO,QAAQ,IAAI;AAAA,EACrB;AAEA,SAAO;AACT;;;ACxDA,eAAsB,UACpB,YAC6B;AAC7B,eAAa,cAAc,CAAC;AAC5B,QAAM,WAAW,MAAM,UAAU,UAAU;AAG3C,QAAM,YAAY,gBAAgB,QAAQ;AAC1C,WAAS,QAAQ,MAAM;AAGvB,QAAM,oBAAoB,MAAM;AAAA,IAC9B;AAAA,IACA,WAAW,WAAW,CAAC;AAAA,EACzB;AACA,SAAO,OAAO,SAAS,SAAS,iBAAiB;AAEjD,QAAM,EAAE,SAAS,MAAM,SAAS,OAAO,IAAI;AAE3C,MAAI,QAAS,OAAM,SAAS,QAAQ,WAAW,OAAO;AACtD,MAAI,KAAM,OAAM,SAAS,QAAQ,QAAQ,IAAI;AAC7C,MAAI,QAAS,QAAO,OAAO,SAAS,SAAS,OAAO;AACpD,MAAI,OAAQ,QAAO,OAAO,SAAS,QAAQ,MAAM;AAEjD,MAAI,SAAS,OAAO,IAAK,OAAM,SAAS,QAAQ,KAAK;AAMrD,MAAI,aAAqB,UAAU;AAEnC,QAAM,UAAU,OAAO,OAAO,SAAS,OAAO,EAAE;AAAA,IAC9C,CAAC,WAAW,OAAO,SAAS;AAAA,EAC9B;AAGA,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","collector","event","batchState","import_core","import_core","collector","on","option","collector","import_core","import_core","collector","import_core","collector","import_core","collector","collector","collector","import_core","collector"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/types/code.ts","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/destination-code.ts","../src/transformer.ts","../src/on.ts","../src/collector.ts","../src/handle.ts","../src/push.ts","../src/command.ts","../src/elb.ts","../src/source.ts","../src/flow.ts"],"sourcesContent":["export * from './types';\n\nexport * from './constants';\n\nexport * from './consent';\nexport * from './flow';\nexport * from './push';\nexport * from './destination';\nexport * from './destination-code';\nexport * from './handle';\nexport * from './on';\nexport * from './source';\n","import type { Destination, Mapping, On, WalkerOS } from '@walkeros/core';\n\nexport interface Settings {\n scripts?: string[];\n init?: string;\n on?: string;\n push?: string;\n pushBatch?: string;\n}\n\nexport interface CodeMapping extends Mapping.Rule<CodeMapping> {\n push?: string;\n pushBatch?: string;\n}\n\nexport type Types = Destination.Types<Settings, CodeMapping>;\nexport type Config = Destination.Config<Types>;\nexport type Context = Destination.Context<Types>;\nexport type PushContext = Destination.PushContext<Types>;\nexport type PushBatchContext = Destination.PushBatchContext<Types>;\n\nexport type InitFn = (context: Context) => void;\nexport type OnFn = (type: On.Types, context: Context) => void;\nexport type PushFn = (event: WalkerOS.Event, context: PushContext) => void;\nexport type PushBatchFn = (\n batch: Destination.Batch<CodeMapping>,\n context: PushBatchContext,\n) => void;\n","import type { Collector } from '@walkeros/core';\nimport type { CommandTypes, StorageType } from './types/collector';\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\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 isDefined,\n isObject,\n processEventMapping,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { destinationCode } from './destination-code';\nimport { runTransformerChain } from './transformer';\n\nfunction resolveCode(code: Destination.Instance | true): Destination.Instance {\n return code === true ? destinationCode : code;\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 resolved = resolveCode(code);\n const destination: Destination.Instance = {\n ...resolved,\n config,\n env: mergeEnvironments(resolved.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 meta - Optional metadata with id and ingest.\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 meta: { id?: string; ingest?: unknown } = {},\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 const currentEvent = clone(event);\n\n // Note: Policy is now applied in processEventMapping() within destinationPush()\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 id,\n );\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error: unknown;\n let response: unknown;\n if (!destination.dlq) destination.dlq = [];\n\n // Get post-collector transformer chain for this destination\n const postChain = collector.transformerChain?.post?.[id] || [];\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 // Run post-collector transformer chain if configured for this destination\n let processedEvent: WalkerOS.Event | null = event;\n if (\n postChain.length > 0 &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const chainResult = await runTransformerChain(\n collector,\n collector.transformers,\n postChain,\n event,\n meta.ingest,\n );\n\n if (chainResult === null) {\n // Chain stopped - skip this event for this destination\n return event;\n }\n\n // Use the processed event (cast back to full Event type)\n processedEvent = chainResult as WalkerOS.Event;\n }\n\n const result = await tryCatchAsync(destinationPush, (err) => {\n // Log the error with destination scope\n const destType = destination.type || 'unknown';\n collector.logger.scope(destType).error('Push failed', {\n error: err,\n event: processedEvent!.name,\n });\n error = err; // oh no\n\n // Add failed event to destinations DLQ\n destination.dlq!.push([processedEvent!, err]);\n\n return undefined;\n })(collector, destination, id, processedEvent!, meta.ingest);\n\n // Capture the last response (for single event pushes)\n if (result !== undefined) response = result;\n\n return event;\n }),\n );\n\n return { id, destination, error, response };\n }),\n );\n\n // Build result objects\n const done: Record<string, Destination.Ref> = {};\n const queued: Record<string, Destination.Ref> = {};\n const failed: Record<string, Destination.Ref> = {};\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n const ref: Destination.Ref = {\n type: destination.type || 'unknown',\n data: result.response, // Capture push() return value\n };\n\n if (result.error) {\n ref.error = result.error;\n failed[result.id] = ref;\n } else if (result.queue && result.queue.length) {\n destination.queue = (destination.queue || []).concat(result.queue);\n queued[result.id] = ref;\n } else {\n done[result.id] = ref;\n }\n }\n\n return createPushResult({\n event,\n ...(Object.keys(done).length && { done }),\n ...(Object.keys(queued).length && { queued }),\n ...(Object.keys(failed).length && { 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 * @param destId - The destination ID.\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 destId: string,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n // Create scoped logger for this destination: [type:id] or [unknown:id]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context: Destination.Context = {\n collector,\n logger: destLogger,\n id: destId,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n destLogger.debug('init');\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 destLogger.debug('init done');\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 destId - The destination ID.\n * @param event - The event to push.\n * @param ingest - Optional ingest metadata (frozen, same reference).\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 destId: string,\n event: WalkerOS.Event,\n ingest?: unknown,\n): Promise<unknown> {\n const { config } = destination;\n\n const processed = await processEventMapping(event, config, collector);\n\n if (processed.ignore) return false;\n\n // Create scoped logger for this destination: [type] or [unknown]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context: Destination.PushContext = {\n collector,\n logger: destLogger,\n id: destId,\n config,\n data: processed.data,\n rule: processed.mapping,\n ingest,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n const eventMapping = processed.mapping;\n const mappingKey = processed.mappingKey || '* *';\n\n if (eventMapping?.batch && destination.pushBatch) {\n // Initialize batch registry on destination (not on shared mapping config)\n destination.batches = destination.batches || {};\n\n // Get or create batch state for this mapping key\n if (!destination.batches[mappingKey]) {\n const batched: Destination.Batch<unknown> = {\n key: mappingKey,\n events: [],\n data: [],\n };\n\n destination.batches[mappingKey] = {\n batched,\n batchFn: debounce(() => {\n const batchState = destination.batches![mappingKey];\n const currentBatched = batchState.batched;\n\n const batchContext: Destination.PushBatchContext = {\n collector,\n logger: destLogger,\n id: destId,\n config,\n // Note: batch.data contains all transformed data; context.data is for single events\n data: undefined,\n rule: eventMapping, // Renamed from mapping to rule\n ingest, // Same frozen reference\n env: mergeEnvironments(destination.env, config.env),\n };\n\n destLogger.debug('push batch', {\n events: currentBatched.events.length,\n });\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n collector.hooks,\n )(currentBatched, batchContext);\n\n destLogger.debug('push batch done');\n\n // Reset batch\n currentBatched.events = [];\n currentBatched.data = [];\n }, eventMapping.batch),\n };\n }\n\n // Add event to batch\n const batchState = destination.batches[mappingKey];\n batchState.batched.events.push(processed.event);\n if (isDefined(processed.data)) batchState.batched.data.push(processed.data);\n\n // Trigger debounced batch\n batchState.batchFn();\n } else {\n destLogger.debug('push', { event: processed.event.name });\n\n // It's time to go to the destination's side now\n const response = await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(processed.event, context);\n\n destLogger.debug('push done');\n\n return response;\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 {\n ok: !partialResult?.failed,\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 const resolved = resolveCode(code);\n\n const mergedConfig = {\n ...resolved.config,\n ...config,\n };\n\n const mergedEnv = mergeEnvironments(resolved.env, env);\n\n result[name] = {\n ...resolved,\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 */\nexport function 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 { Destination } from '@walkeros/core';\nimport type { CodeMapping, Settings } from './types/code';\n\nexport const destinationCode: Destination.Instance = {\n type: 'code',\n config: {},\n\n init(context) {\n const { config, logger } = context;\n const settings = config.settings as Settings | undefined;\n\n // Inject scripts (fire and forget)\n const scripts = settings?.scripts;\n if (scripts && typeof document !== 'undefined') {\n for (const src of scripts) {\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n document.head.appendChild(script);\n }\n }\n\n // Execute init code\n const initCode = settings?.init;\n if (!initCode) return;\n try {\n const fn = new Function('context', initCode);\n fn(context);\n } catch (e) {\n logger.error('Code destination init error:', e);\n }\n },\n\n push(event, context) {\n const { rule, config, logger } = context;\n const pushCode =\n (rule as CodeMapping | undefined)?.push ??\n (config.settings as Settings | undefined)?.push;\n if (!pushCode) return;\n try {\n const fn = new Function('event', 'context', pushCode);\n fn(event, context);\n } catch (e) {\n logger.error('Code destination push error:', e);\n }\n },\n\n pushBatch(batch, context) {\n const { rule, config, logger } = context;\n const pushBatchCode =\n (rule as CodeMapping | undefined)?.pushBatch ??\n (config.settings as Settings | undefined)?.pushBatch;\n if (!pushBatchCode) return;\n try {\n const fn = new Function('batch', 'context', pushBatchCode);\n fn(batch, context);\n } catch (e) {\n logger.error('Code destination pushBatch error:', e);\n }\n },\n\n on(type, context) {\n const { config, logger } = context;\n const onCode = (config.settings as Settings | undefined)?.on;\n if (!onCode) return;\n try {\n const fn = new Function('type', 'context', onCode);\n fn(type, context);\n } catch (e) {\n logger.error('Code destination on error:', e);\n }\n },\n};\n\nexport default destinationCode;\n","import type { Collector, Transformer, WalkerOS } from '@walkeros/core';\nimport { isObject, tryCatchAsync, useHooks } from '@walkeros/core';\n\n/**\n * Resolved transformer chains for a flow.\n */\nexport interface TransformerChain {\n /** Ordered transformer IDs to run before collector (from source.next) */\n pre: string[];\n /** Per-destination transformer chains (from destination.before) */\n post: Record<string, string[]>;\n}\n\n/**\n * Extended collector with transformer support.\n */\nexport interface CollectorWithTransformers extends Collector.Instance {\n transformers: Transformer.Transformers;\n transformerChain: TransformerChain;\n}\n\n/**\n * Walks a transformer chain starting from a given transformer ID.\n * Returns ordered array of transformer IDs in the chain.\n *\n * @param startId - First transformer in chain\n * @param transformers - Available transformer configs with optional `next` field\n * @returns Ordered array of transformer IDs\n */\nexport function walkChain(\n startId: string | undefined,\n transformers: Record<string, { next?: string }> = {},\n): string[] {\n if (!startId) return [];\n\n const chain: string[] = [];\n const visited = new Set<string>();\n let current: string | undefined = startId;\n\n while (current && transformers[current]) {\n if (visited.has(current)) {\n // Circular reference detected - stop walking\n break;\n }\n visited.add(current);\n chain.push(current);\n current = transformers[current].next;\n }\n\n return chain;\n}\n\n/**\n * Resolves transformer chains from flow configuration.\n * Builds per-destination post-collector chains.\n * Note: Pre-chains are now resolved per-source in source.ts\n *\n * @param sources - Source configurations (unused, kept for API compatibility)\n * @param destinations - Destination configurations with optional before property\n * @param transformers - Transformer configurations with optional next property\n * @returns Resolved transformer chains\n */\nexport function resolveTransformerGraph(\n _sources: Record<string, { next?: string }> = {},\n destinations: Record<string, { before?: string }> = {},\n transformers: Record<string, { next?: string }> = {},\n): TransformerChain {\n const post: Record<string, string[]> = {};\n\n // Build post-collector chains from destinations\n for (const [destName, dest] of Object.entries(destinations)) {\n if (dest.before) {\n post[destName] = walkChain(dest.before, transformers);\n }\n }\n\n // Note: pre-chains are now resolved per-source in source.ts\n return { pre: [], post };\n}\n\n/**\n * Initializes transformer instances from configuration.\n * Does NOT call transformer.init() - that happens lazily before first push.\n *\n * @param collector - The collector instance\n * @param initTransformers - Transformer initialization configurations\n * @returns Initialized transformer instances\n */\nexport async function initTransformers(\n collector: Collector.Instance,\n initTransformers: Transformer.InitTransformers = {},\n): Promise<Transformer.Transformers> {\n const result: Transformer.Transformers = {};\n\n for (const [transformerId, transformerDef] of Object.entries(\n initTransformers,\n )) {\n const { code, config = {}, env = {} } = transformerDef;\n\n // Build transformer context for init\n const transformerLogger = collector.logger\n .scope('transformer')\n .scope(transformerId);\n\n const context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n config,\n env: env as Transformer.Env,\n };\n\n // Initialize the transformer instance with context\n const instance = await code(context);\n\n result[transformerId] = instance;\n }\n\n return result;\n}\n\n/**\n * Initializes a transformer if it hasn't been initialized yet.\n * Called lazily before first push.\n *\n * @param collector - The collector instance\n * @param transformer - The transformer to initialize\n * @param transformerId - The transformer ID\n * @returns Whether initialization succeeded\n */\nexport async function transformerInit(\n collector: Collector.Instance,\n transformer: Transformer.Instance,\n transformerId: string,\n): Promise<boolean> {\n // Check if already initialized\n if (transformer.init && !transformer.config.init) {\n const transformerType = transformer.type || 'unknown';\n const transformerLogger = collector.logger.scope(\n `transformer:${transformerType}`,\n );\n\n const context: Transformer.Context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n config: transformer.config,\n env: mergeTransformerEnvironments(transformer.config.env),\n };\n\n transformerLogger.debug('init');\n\n const configResult = await useHooks(\n transformer.init,\n 'TransformerInit',\n collector.hooks,\n )(context);\n\n // Check for initialization failure\n if (configResult === false) return false;\n\n // Update config if returned\n transformer.config = {\n ...(configResult || transformer.config),\n init: true,\n };\n\n transformerLogger.debug('init done');\n }\n\n return true;\n}\n\n/**\n * Pushes an event through a single transformer.\n *\n * @param collector - The collector instance\n * @param transformer - The transformer to push to\n * @param transformerId - The transformer ID\n * @param event - The event to process\n * @param ingest - Optional ingest metadata (frozen, same reference)\n * @returns The processed event, void for passthrough, or false to stop chain\n */\nexport async function transformerPush(\n collector: Collector.Instance,\n transformer: Transformer.Instance,\n transformerId: string,\n event: WalkerOS.DeepPartialEvent,\n ingest?: unknown,\n): Promise<WalkerOS.DeepPartialEvent | false | void> {\n const transformerType = transformer.type || 'unknown';\n const transformerLogger = collector.logger.scope(\n `transformer:${transformerType}`,\n );\n\n const context: Transformer.Context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n ingest, // Same frozen reference, no copying\n config: transformer.config,\n env: mergeTransformerEnvironments(transformer.config.env),\n };\n\n transformerLogger.debug('push', { event: (event as { name?: string }).name });\n\n const result = await useHooks(\n transformer.push,\n 'TransformerPush',\n collector.hooks,\n )(event, context);\n\n transformerLogger.debug('push done');\n\n return result;\n}\n\n/**\n * Runs an event through a chain of transformers.\n *\n * @param collector - The collector instance with transformers\n * @param transformers - Map of transformer instances\n * @param chain - Ordered array of transformer IDs to execute\n * @param event - The event to process\n * @param ingest - Optional ingest metadata (frozen, same reference)\n * @returns The processed event or null if chain was stopped\n */\nexport async function runTransformerChain(\n collector: Collector.Instance,\n transformers: Transformer.Transformers,\n chain: string[],\n event: WalkerOS.DeepPartialEvent,\n ingest?: unknown,\n): Promise<WalkerOS.DeepPartialEvent | null> {\n let processedEvent = event;\n\n for (const transformerName of chain) {\n const transformer = transformers[transformerName];\n if (!transformer) {\n collector.logger.info(`Transformer not found: ${transformerName}`);\n continue;\n }\n\n // Initialize transformer if needed\n const isInitialized = await tryCatchAsync(transformerInit)(\n collector,\n transformer,\n transformerName,\n );\n\n if (!isInitialized) {\n collector.logger.info(`Transformer init failed: ${transformerName}`);\n return null; // Stop chain on init failure\n }\n\n // Run the transformer\n const result = (await tryCatchAsync(transformerPush, (err) => {\n collector.logger\n .scope(`transformer:${transformer.type || 'unknown'}`)\n .error('Push failed', { error: err });\n return false; // Stop chain on error\n })(collector, transformer, transformerName, processedEvent, ingest)) as\n | WalkerOS.DeepPartialEvent\n | false\n | void;\n\n // Handle result\n if (result === false) {\n // Transformer explicitly stopped the chain\n return null;\n }\n\n if (result !== undefined) {\n // Transformer returned a modified event\n processedEvent = result;\n }\n // If result is undefined (void), continue with current event unchanged\n }\n\n return processedEvent;\n}\n\n/**\n * Merges transformer environments.\n */\nfunction mergeTransformerEnvironments(\n configEnv?: Transformer.Env,\n): Transformer.Env {\n if (!configEnv) return {};\n if (isObject(configEnv)) return configEnv;\n return {};\n}\n","import type { Collector, On, WalkerOS, Destination } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\nimport { mergeEnvironments } from './destination';\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.entries(collector.destinations).forEach(([destId, destination]) => {\n if (destination.on) {\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger\n .scope(destType)\n .scope('on')\n .scope(type);\n\n const context: Destination.Context = {\n collector,\n logger: destLogger,\n id: destId,\n config: destination.config,\n data: contextData as Destination.Data,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n tryCatch(destination.on)(type, context);\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, Logger, WalkerOS } from '@walkeros/core';\nimport { assign, createLogger } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations } from './destination';\nimport { initTransformers, resolveTransformerGraph } from './transformer';\nimport { createPush } from './push';\nimport { createCommand } from './command';\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 run: true,\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n // Create logger with config from initConfig\n const loggerConfig: Logger.Config = {\n level: initConfig.logger?.level,\n handler: initConfig.logger?.handler,\n };\n const logger = createLogger(loggerConfig);\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 transformers: {},\n transformerChain: { pre: [], post: {} },\n globals: finalGlobals,\n group: '',\n hooks: {},\n logger,\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 Collector.PushFn, // Placeholder, will be set below\n command: undefined as unknown as Collector.CommandFn, // Placeholder, will be set below\n };\n\n // Set the push and command functions with the collector reference\n collector.push = createPush(\n collector,\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 collector.command = createCommand(collector, commonHandleCommand);\n\n // Initialize destinations after collector is fully created\n // Sources are initialized in startFlow after ELB source is created\n collector.destinations = await initDestinations(\n collector,\n initConfig.destinations || {},\n );\n\n // Initialize transformers\n collector.transformers = await initTransformers(\n collector,\n initConfig.transformers || {},\n );\n\n // Resolve transformer chains based on source/destination configuration\n // Note: This is a placeholder - actual chain resolution happens in startFlow\n // when sources are configured with 'next' and destinations with 'before'\n\n return collector;\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Const } from './constants';\nimport {\n addDestination,\n pushToDestinations,\n createPushResult,\n} from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject } 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 result || createPushResult({ ok: true });\n}\n\n/**\n * Creates a full event from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param partialEvent The partial event to transform.\n * @returns The full event.\n */\nexport function createEvent(\n collector: Collector.Instance,\n partialEvent: WalkerOS.PartialEvent,\n): WalkerOS.Event {\n if (!partialEvent.name) throw new Error('Event name is required');\n\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n ++collector.count;\n\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\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 return {\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\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, WalkerOS, Elb } from '@walkeros/core';\nimport {\n getGrantedConsent,\n processEventMapping,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEvent } from './handle';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { runTransformerChain } from './transformer';\n\n/**\n * Creates the push function for the collector.\n * Handles source mapping, event creation, and routing to destinations.\n *\n * @param collector - The walkerOS collector instance\n * @param prepareEvent - Function to enrich partial events\n * @returns The push function\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Collector.PushFn {\n return useHooks(\n async (\n event: WalkerOS.DeepPartialEvent,\n options: Collector.PushOptions = {},\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n const { id, ingest, mapping, preChain } = options;\n let partialEvent = event;\n\n // Freeze ingest for performance (pass by reference, no copying)\n const frozenIngest = ingest ? Object.freeze(ingest) : undefined;\n\n // Apply source mapping if provided in options\n if (mapping) {\n const processed = await processEventMapping(\n partialEvent,\n mapping,\n collector,\n );\n\n // Check ignore flag\n if (processed.ignore) {\n return createPushResult({ ok: true });\n }\n\n // Check consent requirements\n if (mapping.consent) {\n const grantedConsent = getGrantedConsent(\n mapping.consent,\n collector.consent,\n processed.event.consent as WalkerOS.Consent | undefined,\n );\n\n if (!grantedConsent) {\n return createPushResult({ ok: true });\n }\n }\n\n partialEvent = processed.event;\n }\n\n // Run pre-collector transformer chain if provided in options\n if (\n preChain?.length &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const processedEvent = await runTransformerChain(\n collector,\n collector.transformers,\n preChain,\n partialEvent,\n frozenIngest,\n );\n\n // Chain was stopped - event dropped\n if (processedEvent === null) {\n return createPushResult({ ok: true });\n }\n\n partialEvent = processedEvent;\n }\n\n // Prepare event (add timing, source info)\n const enrichedEvent = prepareEvent(partialEvent);\n\n // Create full event\n const fullEvent = createEvent(collector, enrichedEvent);\n\n // Push to destinations with id and ingest\n return await pushToDestinations(collector, fullEvent, {\n id,\n ingest: frozenIngest,\n });\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Collector.PushFn;\n}\n","import type { Collector, Elb } from '@walkeros/core';\nimport type { HandleCommandFn } from './types/collector';\nimport { useHooks, tryCatchAsync } from '@walkeros/core';\nimport { createPushResult } from './destination';\n\n/**\n * Creates the command function for the collector.\n * Handles walker commands (config, consent, destination, etc.)\n *\n * @param collector - The walkerOS collector instance\n * @param handleCommand - Command handler function\n * @returns The command function\n */\nexport function createCommand<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n): Collector.CommandFn {\n return useHooks(\n async (\n command: string,\n data?: unknown,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n return await handleCommand(collector, command, data, options);\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Command',\n collector.hooks,\n ) as Collector.CommandFn;\n}\n","import type { Collector, Source, WalkerOS, Elb } from '@walkeros/core';\nimport { createPushResult } from './destination';\n\n/**\n * Creates the default ELB source.\n * Routes between collector.push and collector.command based on input.\n * Provides backward-compatible flexible argument interface.\n *\n * @param collector - The walkerOS collector instance\n * @returns ELB source instance\n */\nexport function createElbSource(\n collector: Collector.Instance,\n): Source.Instance {\n return {\n type: 'elb',\n config: {},\n\n // The push function is the elb() interface users interact with\n push: async (\n eventOrCommand?: unknown,\n data?: unknown,\n options?: unknown,\n context?: unknown,\n nested?: WalkerOS.Entities,\n custom?: WalkerOS.Properties,\n ): Promise<Elb.PushResult> => {\n // Detect walker commands\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n const command = eventOrCommand.replace('walker ', '');\n return collector.command(command, data, options);\n }\n\n // Build event object\n let event: WalkerOS.DeepPartialEvent;\n\n if (typeof eventOrCommand === 'string') {\n // Convert string to object: elb('page view', { title: 'Home' })\n event = { name: eventOrCommand };\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = data as WalkerOS.Properties;\n }\n } else if (eventOrCommand && typeof eventOrCommand === 'object') {\n // Use object directly: elb({ name: 'page view', data: {...} })\n event = eventOrCommand as WalkerOS.DeepPartialEvent;\n // Merge additional data if provided\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = {\n ...(event.data || {}),\n ...(data as WalkerOS.Properties),\n };\n }\n } else {\n // Invalid input\n return createPushResult({ ok: false });\n }\n\n // Add optional properties if provided\n if (context && typeof context === 'object') {\n event.context = context as WalkerOS.OrderedProperties;\n }\n if (nested && Array.isArray(nested)) {\n event.nested = nested;\n }\n if (custom && typeof custom === 'object') {\n event.custom = custom as WalkerOS.Properties;\n }\n\n // Call collector.push with event object\n return collector.push(event);\n },\n };\n}\n","import type { Collector, Source, WalkerOS } from '@walkeros/core';\nimport { getMappingValue, tryCatchAsync } from '@walkeros/core';\nimport { walkChain } from './transformer';\n\n/**\n * Extracts a simple {id: {next}} map from transformer instances.\n * Used for chain resolution.\n */\nfunction extractTransformerNextMap(\n transformers: Record<string, { config: { next?: string } }>,\n): Record<string, { next?: string }> {\n const result: Record<string, { next?: string }> = {};\n for (const [id, transformer] of Object.entries(transformers)) {\n result[id] = { next: transformer.config.next };\n }\n return result;\n}\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 * @returns Initialized sources\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, next } = sourceDefinition;\n\n // Track current ingest metadata (set per-request by setIngest)\n let currentIngest: unknown = undefined;\n\n // Resolve transformer chain for this source\n const preChain = walkChain(\n next,\n extractTransformerNextMap(collector.transformers),\n );\n\n // Create wrapped push that auto-applies source mapping config, preChain, and ingest\n const wrappedPush: Collector.PushFn = (\n event: WalkerOS.DeepPartialEvent,\n options: Collector.PushOptions = {},\n ) => {\n // Pass source config as mapping in options, plus resolved preChain, source id, and ingest\n return collector.push(event, {\n ...options,\n id: sourceId,\n ingest: currentIngest,\n mapping: config,\n preChain, // Source-specific transformer chain\n });\n };\n\n // Create initial logger scoped to sourceId (type will be added after init)\n const initialLogger = collector.logger.scope('source').scope(sourceId);\n\n const cleanEnv: Source.Env = {\n push: wrappedPush,\n command: collector.command,\n sources: collector.sources, // Provide access to all sources for chaining\n elb: collector.sources.elb.push, // ELB source is always available\n logger: initialLogger,\n ...env,\n };\n\n /**\n * setIngest extracts metadata from raw request using config.ingest mapping.\n * Opt-in: returns early if no config.ingest is defined.\n */\n const setIngest = async (value: unknown): Promise<void> => {\n // Opt-in barrier: no processing when ingest not configured\n if (!config.ingest) {\n currentIngest = undefined;\n return;\n }\n\n currentIngest = await getMappingValue(value, config.ingest, {\n collector,\n });\n };\n\n // Build source context for init\n const sourceContext: Source.Context = {\n collector,\n logger: initialLogger,\n id: sourceId,\n config,\n env: cleanEnv,\n setIngest,\n };\n\n // Call source function with context\n const sourceInstance = await tryCatchAsync(code)(sourceContext);\n\n if (!sourceInstance) continue; // Skip failed source initialization\n\n // Update logger with actual source type: [type:sourceId] or [unknown:sourceId]\n const sourceType = sourceInstance.type || 'unknown';\n const sourceLogger = collector.logger.scope(sourceType).scope(sourceId);\n cleanEnv.logger = sourceLogger;\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, Elb } from '@walkeros/core';\nimport type { StartFlow } from './types';\nimport { collector } from './collector';\nimport { createElbSource } from './elb';\nimport { initSources } from './source';\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\n // Create and register ELB source first\n const elbSource = createElbSource(instance);\n instance.sources.elb = elbSource;\n\n // Now initialize other sources with ELB source available\n const additionalSources = await initSources(\n instance,\n initConfig.sources || {},\n );\n Object.assign(instance.sources, additionalSources);\n\n const { consent, user, globals, custom } = initConfig;\n\n if (consent) await instance.command('consent', consent);\n if (user) await instance.command('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.command('run');\n\n // Determine the primary elb:\n // 1. Use explicitly marked primary source\n // 2. Use first non-elb source if any exist\n // 3. Fallback to ELB source\n let primaryElb: Elb.Fn = elbSource.push as Elb.Fn;\n\n const sources = Object.values(instance.sources).filter(\n (source) => source.type !== 'elb',\n );\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 as Elb.Fn;\n } else if (sources.length > 0) {\n // Use first source as default\n primaryElb = sources[0].push as Elb.Fn;\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;AAAA;AAAA;AAAA;;;ACAA;;;ACGO,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,EACL,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AACV;AAEA,IAAM,eAA+C;AAAA,EACnD,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS;AACX;AAEA,IAAM,QAAQ;AAAA,EACZ,SAAS;AACX;AAEO,IAAM,QAAQ;AAAA,EACnB;AAAA,EACA;AACF;;;ACrCA,IAAAA,eAAuB;;;ACAvB,IAAAC,eAWO;;;ACTA,IAAM,kBAAwC;AAAA,EACnD,MAAM;AAAA,EACN,QAAQ,CAAC;AAAA,EAET,KAAK,SAAS;AACZ,UAAM,EAAE,QAAQ,OAAO,IAAI;AAC3B,U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WAAS,QAAQ,MAAM;AAGvB,QAAM,oBAAoB,MAAM;AAAA,IAC9B;AAAA,IACA,WAAW,WAAW,CAAC;AAAA,EACzB;AACA,SAAO,OAAO,SAAS,SAAS,iBAAiB;AAEjD,QAAM,EAAE,SAAS,MAAM,SAAS,OAAO,IAAI;AAE3C,MAAI,QAAS,OAAM,SAAS,QAAQ,WAAW,OAAO;AACtD,MAAI,KAAM,OAAM,SAAS,QAAQ,QAAQ,IAAI;AAC7C,MAAI,QAAS,QAAO,OAAO,SAAS,SAAS,OAAO;AACpD,MAAI,OAAQ,QAAO,OAAO,SAAS,QAAQ,MAAM;AAEjD,MAAI,SAAS,OAAO,IAAK,OAAM,SAAS,QAAQ,KAAK;AAMrD,MAAI,aAAqB,UAAU;AAEnC,QAAM,UAAU,OAAO,OAAO,SAAS,OAAO,EAAE;AAAA,IAC9C,CAAC,WAAW,OAAO,SAAS;AAAA,EAC9B;AAGA,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","collector","initTransformers","collector","event","batchState","import_core","import_core","collector","on","option","collector","import_core","import_core","collector","import_core","collector","import_core","collector","collector","collector","import_core","collector"]}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var e={},n={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},o={Commands:n,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}};import{assign as t}from"@walkeros/core";import{assign as s,clone as a,debounce as c,getId as i,getGrantedConsent as r,isDefined as u,isObject as l,processEventMapping as g,tryCatchAsync as d,useHooks as f}from"@walkeros/core";var m={type:"code",config:{},init(e){const{config:n,logger:o}=e,t=n.settings,s=t?.scripts;if(s&&"undefined"!=typeof document)for(const e of s){const n=document.createElement("script");n.src=e,n.async=!0,document.head.appendChild(n)}const a=t?.init;if(a)try{new Function("context",a)(e)}catch(e){o.error("Code destination init error:",e)}},push(e,n){const{mapping:o,config:t,logger:s}=n,a=o?.push??t.settings?.push;if(a)try{new Function("event","context",a)(e,n)}catch(e){s.error("Code destination push error:",e)}},pushBatch(e,n){const{mapping:o,config:t,logger:s}=n,a=o?.pushBatch??t.settings?.pushBatch;if(a)try{new Function("batch","context",a)(e,n)}catch(e){s.error("Code destination pushBatch error:",e)}},on(e,n){const{config:o,logger:t}=n,s=o.settings?.on;if(s)try{new Function("type","context",s)(e,n)}catch(e){t.error("Code destination on error:",e)}}};function p(e){return!0===e?m:e}async function h(e,n,o){const{code:t,config:s={},env:a={}}=n,c=o||s||{init:!1},r=p(t),u={...r,config:c,env:C(r.env,a)};let l=u.config.id;if(!l)do{l=i(4)}while(e.destinations[l]);return e.destinations[l]=u,!1!==u.config.queue&&(u.queue=[...e.queue]),b(e,void 0,{[l]:u})}async function b(e,n,o){const{allowed:t,consent:c,globals:i,user:u}=e;if(!t)return k({ok:!1});n&&e.queue.push(n),o||(o=e.destinations);const l=await Promise.all(Object.entries(o||{}).map(async([o,t])=>{let l=(t.queue||[]).map(e=>({...e,consent:c}));if(t.queue=[],n){const e=a(n);l.push(e)}if(!l.length)return{id:o,destination:t,skipped:!0};const g=[],f=l.filter(e=>{const n=r(t.config.consent,c,e.consent);return!n||(e.consent=n,g.push(e),!1)});if(t.queue.concat(f),!g.length)return{id:o,destination:t,queue:l};if(!await d(y)(e,t))return{id:o,destination:t,queue:l};let m=!1;return t.dlq||(t.dlq=[]),await Promise.all(g.map(async n=>(n.globals=s(i,n.globals),n.user=s(u,n.user),await d(w,o=>{const s=t.type||"unknown";return e.logger.scope(s).error("Push failed",{error:o,event:n.name}),m=!0,t.dlq.push([n,o]),!1})(e,t,n),n))),{id:o,destination:t,error:m}})),g=[],f=[],m=[];for(const e of l){if(e.skipped)continue;const n=e.destination,o={id:e.id,destination:n};e.error?m.push(o):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),f.push(o)):g.push(o)}return k({ok:!m.length,event:n,successful:g,queued:f,failed:m})}async function y(e,n){if(n.init&&!n.config.init){const o=n.type||"unknown",t=e.logger.scope(o),s={collector:e,config:n.config,env:C(n.env,n.config.env),logger:t};t.debug("init");const a=await f(n.init,"DestinationInit",e.hooks)(s);if(!1===a)return a;n.config={...a||n.config,init:!0},t.debug("init done")}return!0}async function w(e,n,o){const{config:t}=n,s=await g(o,t,e);if(s.ignore)return!1;const a=n.type||"unknown",i=e.logger.scope(a),r={collector:e,config:t,data:s.data,mapping:s.mapping,env:C(n.env,t.env),logger:i},l=s.mapping,d=s.mappingKey||"* *";if(l?.batch&&n.pushBatch){if(n.batches=n.batches||{},!n.batches[d]){const o={key:d,events:[],data:[]};n.batches[d]={batched:o,batchFn:c(()=>{const o=n.batches[d].batched,s={collector:e,config:t,data:void 0,mapping:l,env:C(n.env,t.env),logger:i};i.debug("push batch",{events:o.events.length}),f(n.pushBatch,"DestinationPushBatch",e.hooks)(o,s),i.debug("push batch done"),o.events=[],o.data=[]},l.batch)}}const o=n.batches[d];o.batched.events.push(s.event),u(s.data)&&o.batched.data.push(s.data),o.batchFn()}else i.debug("push",{event:s.event.name}),await f(n.push,"DestinationPush",e.hooks)(s.event,r),i.debug("push done");return!0}function k(e){return s({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function v(e,n={}){const o={};for(const[e,t]of Object.entries(n)){const{code:n,config:s={},env:a={}}=t,c=p(n),i={...c.config,...s},r=C(c.env,a);o[e]={...c,config:i,env:r}}return o}function C(e,n){return e||n?n?e&&l(e)&&l(n)?{...e,...n}:n:e:{}}import{isArray as q}from"@walkeros/core";import{tryCatch as j}from"@walkeros/core";function E(e,n,o){const t=e.on,s=t[n]||[],a=q(o)?o:[o];a.forEach(e=>{s.push(e)}),t[n]=s,O(e,n,a)}function O(e,n,t,s){let a,c=t||[];switch(t||(c=e.on[n]||[]),n){case o.Commands.Consent:a=s||e.consent;break;case o.Commands.Session:a=e.session;break;case o.Commands.Ready:case o.Commands.Run:default:a=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&j(e.on)(n,a)}),Object.values(e.destinations).forEach(o=>{if(o.on){const t=o.type||"unknown",s=e.logger.scope(t).scope("on").scope(n),c={collector:e,config:o.config,data:a,env:C(o.env,o.config.env),logger:s};j(o.on)(n,c)}}),c.length)switch(n){case o.Commands.Consent:!function(e,n,o){const t=o||e.consent;n.forEach(n=>{Object.keys(t).filter(e=>e in n).forEach(o=>{j(n[o])(e,t)})})}(e,c,s);break;case o.Commands.Ready:case o.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{j(n)(e)})}(e,c);break;case o.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{j(n)(e,e.session)})}(e,c)}}async function x(e,n){const{consent:o}=e;let s=!1;const a={};return Object.entries(n).forEach(([e,n])=>{const o=!!n;a[e]=o,s=s||o}),e.consent=t(o,a),O(e,"consent",void 0,a),s?b(e):k({ok:!0})}import{assign as A,createLogger as S}from"@walkeros/core";import{assign as D,getId as R,isFunction as B,isString as P}from"@walkeros/core";import{isObject as F}from"@walkeros/core";async function $(e,n,t,s){let a;switch(n){case o.Commands.Config:F(t)&&D(e.config,t,{shallow:!1});break;case o.Commands.Consent:F(t)&&(a=await x(e,t));break;case o.Commands.Custom:F(t)&&(e.custom=D(e.custom,t));break;case o.Commands.Destination:F(t)&&B(t.push)&&(a=await h(e,{code:t},s));break;case o.Commands.Globals:F(t)&&(e.globals=D(e.globals,t));break;case o.Commands.On:P(t)&&E(e,t,s);break;case o.Commands.Ready:O(e,"ready");break;case o.Commands.Run:a=await H(e,t);break;case o.Commands.Session:O(e,"session");break;case o.Commands.User:F(t)&&D(e.user,t,{shallow:!1})}return a||{ok:!0,successful:[],queued:[],failed:[]}}function G(e,n){if(!n.name)throw new Error("Event name is required");const[o,t]=n.name.split(" ");if(!o||!t)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:c=e.count}=n,{name:i=`${o} ${t}`,data:r={},context:u={},globals:l=e.globals,custom:g={},user:d=e.user,nested:f=[],consent:m=e.consent,id:p=`${s}-${a}-${c}`,trigger:h="",entity:b=o,action:y=t,timing:w=0,version:k={source:e.version,tagging:e.config.tagging||0},source:v={type:"collector",id:"",previous_id:""}}=n;return{name:i,data:r,context:u,globals:l,custom:g,user:d,nested:f,consent:m,id:p,trigger:h,entity:b,action:y,timestamp:s,timing:w,group:a,count:c,version:k,source:v}}async function H(e,n){e.allowed=!0,e.count=0,e.group=R(),e.timing=Date.now(),n&&(n.consent&&(e.consent=D(e.consent,n.consent)),n.user&&(e.user=D(e.user,n.user)),n.globals&&(e.globals=D(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=D(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const o=await b(e);return O(e,"run"),o}import{getGrantedConsent as I,processEventMapping as U,tryCatchAsync as L,useHooks as M}from"@walkeros/core";function W(e,n){return M(async(o,t={})=>await L(async()=>{let s=o;if(t.mapping){const n=await U(s,t.mapping,e);if(n.ignore)return k({ok:!0});if(t.mapping.consent){if(!I(t.mapping.consent,e.consent,n.event.consent))return k({ok:!0})}s=n.event}const a=n(s),c=G(e,a);return await b(e,c)},()=>k({ok:!1}))(),"Push",e.hooks)}import{useHooks as _,tryCatchAsync as K}from"@walkeros/core";async function z(e){const n=A({globalsStatic:{},sessionStatic:{},tagging:0,run:!0},e,{merge:!1,extend:!1}),o={level:e.logger?.level,handler:e.logger?.handler},t=S(o),s={...n.globalsStatic,...e.globals},a={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},logger:t,on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.5.0",sources:{},push:void 0,command:void 0};return a.push=W(a,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.command=function(e,n){return _(async(o,t,s)=>await K(async()=>await n(e,o,t,s),()=>k({ok:!1}))(),"Command",e.hooks)}(a,$),a.destinations=await v(0,e.destinations||{}),a}import{tryCatchAsync as J}from"@walkeros/core";async function N(e,n={}){const o={};for(const[t,s]of Object.entries(n)){const{code:n,config:a={},env:c={},primary:i}=s,r=(n,o={})=>e.push(n,{...o,mapping:a}),u=e.logger.scope("source").scope(t),l={push:r,command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:u,...c},g=await J(n)(a,l);if(!g)continue;const d=g.type||"unknown",f=e.logger.scope(d).scope(t);l.logger=f,i&&(g.config={...g.config,primary:i}),o[t]=g}return o}async function Q(e){e=e||{};const n=await z(e),o=(t=n,{type:"elb",config:{},push:async(e,n,o,s,a,c)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return t.command(s,n,o)}let i;if("string"==typeof e)i={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(i.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};i=e,n&&"object"==typeof n&&!Array.isArray(n)&&(i.data={...i.data||{},...n})}return s&&"object"==typeof s&&(i.context=s),a&&Array.isArray(a)&&(i.nested=a),c&&"object"==typeof c&&(i.custom=c),t.push(i)}});var t;n.sources.elb=o;const s=await N(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:c,globals:i,custom:r}=e;a&&await n.command("consent",a),c&&await n.command("user",c),i&&Object.assign(n.globals,i),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=o.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),g=l.find(e=>e.config.primary);return g?u=g.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}export{e as Code,n as Commands,o as Const,h as addDestination,$ as commonHandleCommand,G as createEvent,W as createPush,k as createPushResult,m as destinationCode,y as destinationInit,w as destinationPush,v as initDestinations,N as initSources,C as mergeEnvironments,E as on,O as onApply,b as pushToDestinations,H as runCollector,x as setConsent,Q as startFlow};//# sourceMappingURL=index.mjs.map
1
+ var n={},e={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},o={Commands:e,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}};import{assign as t}from"@walkeros/core";import{assign as s,clone as r,debounce as c,getId as i,getGrantedConsent as a,isDefined as u,isObject as g,processEventMapping as l,tryCatchAsync as f,useHooks as d}from"@walkeros/core";var m={type:"code",config:{},init(n){const{config:e,logger:o}=n,t=e.settings,s=t?.scripts;if(s&&"undefined"!=typeof document)for(const n of s){const e=document.createElement("script");e.src=n,e.async=!0,document.head.appendChild(e)}const r=t?.init;if(r)try{new Function("context",r)(n)}catch(n){o.error("Code destination init error:",n)}},push(n,e){const{rule:o,config:t,logger:s}=e,r=o?.push??t.settings?.push;if(r)try{new Function("event","context",r)(n,e)}catch(n){s.error("Code destination push error:",n)}},pushBatch(n,e){const{rule:o,config:t,logger:s}=e,r=o?.pushBatch??t.settings?.pushBatch;if(r)try{new Function("batch","context",r)(n,e)}catch(n){s.error("Code destination pushBatch error:",n)}},on(n,e){const{config:o,logger:t}=e,s=o.settings?.on;if(s)try{new Function("type","context",s)(n,e)}catch(n){t.error("Code destination on error:",n)}}};import{isObject as p,tryCatchAsync as h,useHooks as b}from"@walkeros/core";function y(n,e={}){if(!n)return[];const o=[],t=new Set;let s=n;for(;s&&e[s]&&!t.has(s);)t.add(s),o.push(s),s=e[s].next;return o}async function w(n,e,o){if(e.init&&!e.config.init){const t=e.type||"unknown",s=n.logger.scope(`transformer:${t}`),r={collector:n,logger:s,id:o,config:e.config,env:C(e.config.env)};s.debug("init");const c=await b(e.init,"TransformerInit",n.hooks)(r);if(!1===c)return!1;e.config={...c||e.config,init:!0},s.debug("init done")}return!0}async function k(n,e,o,t,s){const r=e.type||"unknown",c=n.logger.scope(`transformer:${r}`),i={collector:n,logger:c,id:o,ingest:s,config:e.config,env:C(e.config.env)};c.debug("push",{event:t.name});const a=await b(e.push,"TransformerPush",n.hooks)(t,i);return c.debug("push done"),a}async function v(n,e,o,t,s){let r=t;for(const t of o){const o=e[t];if(!o){n.logger.info(`Transformer not found: ${t}`);continue}if(!await h(w)(n,o,t))return n.logger.info(`Transformer init failed: ${t}`),null;const c=await h(k,e=>(n.logger.scope(`transformer:${o.type||"unknown"}`).error("Push failed",{error:e}),!1))(n,o,t,r,s);if(!1===c)return null;void 0!==c&&(r=c)}return r}function C(n){return n&&p(n)?n:{}}function j(n){return!0===n?m:n}async function O(n,e,o){const{code:t,config:s={},env:r={}}=e,c=o||s||{init:!1},a=j(t),u={...a,config:c,env:$(a.env,r)};let g=u.config.id;if(!g)do{g=i(4)}while(n.destinations[g]);return n.destinations[g]=u,!1!==u.config.queue&&(u.queue=[...n.queue]),q(n,void 0,{},{[g]:u})}async function q(n,e,o={},t){const{allowed:c,consent:i,globals:u,user:g}=n;if(!c)return A({ok:!1});e&&n.queue.push(e),t||(t=n.destinations);const l=await Promise.all(Object.entries(t||{}).map(async([t,c])=>{let l=(c.queue||[]).map(n=>({...n,consent:i}));if(c.queue=[],e){const n=r(e);l.push(n)}if(!l.length)return{id:t,destination:c,skipped:!0};const d=[],m=l.filter(n=>{const e=a(c.config.consent,i,n.consent);return!e||(n.consent=e,d.push(n),!1)});if(c.queue.concat(m),!d.length)return{id:t,destination:c,queue:l};if(!await f(x)(n,c,t))return{id:t,destination:c,queue:l};let p,h;c.dlq||(c.dlq=[]);const b=n.transformerChain?.post?.[t]||[];return await Promise.all(d.map(async e=>{e.globals=s(u,e.globals),e.user=s(g,e.user);let r=e;if(b.length>0&&n.transformers&&Object.keys(n.transformers).length>0){const t=await v(n,n.transformers,b,e,o.ingest);if(null===t)return e;r=t}const i=await f(E,e=>{const o=c.type||"unknown";n.logger.scope(o).error("Push failed",{error:e,event:r.name}),p=e,c.dlq.push([r,e])})(n,c,t,r,o.ingest);return void 0!==i&&(h=i),e})),{id:t,destination:c,error:p,response:h}})),d={},m={},p={};for(const n of l){if(n.skipped)continue;const e=n.destination,o={type:e.type||"unknown",data:n.response};n.error?(o.error=n.error,p[n.id]=o):n.queue&&n.queue.length?(e.queue=(e.queue||[]).concat(n.queue),m[n.id]=o):d[n.id]=o}return A({event:e,...Object.keys(d).length&&{done:d},...Object.keys(m).length&&{queued:m},...Object.keys(p).length&&{failed:p}})}async function x(n,e,o){if(e.init&&!e.config.init){const t=e.type||"unknown",s=n.logger.scope(t),r={collector:n,logger:s,id:o,config:e.config,env:$(e.env,e.config.env)};s.debug("init");const c=await d(e.init,"DestinationInit",n.hooks)(r);if(!1===c)return c;e.config={...c||e.config,init:!0},s.debug("init done")}return!0}async function E(n,e,o,t,s){const{config:r}=e,i=await l(t,r,n);if(i.ignore)return!1;const a=e.type||"unknown",g=n.logger.scope(a),f={collector:n,logger:g,id:o,config:r,data:i.data,rule:i.mapping,ingest:s,env:$(e.env,r.env)},m=i.mapping,p=i.mappingKey||"* *";if(!m?.batch||!e.pushBatch){g.debug("push",{event:i.event.name});const o=await d(e.push,"DestinationPush",n.hooks)(i.event,f);return g.debug("push done"),o}{if(e.batches=e.batches||{},!e.batches[p]){const t={key:p,events:[],data:[]};e.batches[p]={batched:t,batchFn:c(()=>{const t=e.batches[p].batched,c={collector:n,logger:g,id:o,config:r,data:void 0,rule:m,ingest:s,env:$(e.env,r.env)};g.debug("push batch",{events:t.events.length}),d(e.pushBatch,"DestinationPushBatch",n.hooks)(t,c),g.debug("push batch done"),t.events=[],t.data=[]},m.batch)}}const t=e.batches[p];t.batched.events.push(i.event),u(i.data)&&t.batched.data.push(i.data),t.batchFn()}return!0}function A(n){return{ok:!n?.failed,...n}}async function S(n,e={}){const o={};for(const[n,t]of Object.entries(e)){const{code:e,config:s={},env:r={}}=t,c=j(e),i={...c.config,...s},a=$(c.env,r);o[n]={...c,config:i,env:a}}return o}function $(n,e){return n||e?e?n&&g(n)&&g(e)?{...n,...e}:e:n:{}}import{isArray as D}from"@walkeros/core";import{tryCatch as P}from"@walkeros/core";function R(n,e,o){const t=n.on,s=t[e]||[],r=D(o)?o:[o];r.forEach(n=>{s.push(n)}),t[e]=s,B(n,e,r)}function B(n,e,t,s){let r,c=t||[];switch(t||(c=n.on[e]||[]),e){case o.Commands.Consent:r=s||n.consent;break;case o.Commands.Session:r=n.session;break;case o.Commands.Ready:case o.Commands.Run:default:r=void 0}if(Object.values(n.sources).forEach(n=>{n.on&&P(n.on)(e,r)}),Object.entries(n.destinations).forEach(([o,t])=>{if(t.on){const s=t.type||"unknown",c=n.logger.scope(s).scope("on").scope(e),i={collector:n,logger:c,id:o,config:t.config,data:r,env:$(t.env,t.config.env)};P(t.on)(e,i)}}),c.length)switch(e){case o.Commands.Consent:!function(n,e,o){const t=o||n.consent;e.forEach(e=>{Object.keys(t).filter(n=>n in e).forEach(o=>{P(e[o])(n,t)})})}(n,c,s);break;case o.Commands.Ready:case o.Commands.Run:!function(n,e){n.allowed&&e.forEach(e=>{P(e)(n)})}(n,c);break;case o.Commands.Session:!function(n,e){if(!n.session)return;e.forEach(e=>{P(e)(n,n.session)})}(n,c)}}async function F(n,e){const{consent:o}=n;let s=!1;const r={};return Object.entries(e).forEach(([n,e])=>{const o=!!e;r[n]=o,s=s||o}),n.consent=t(o,r),B(n,"consent",void 0,r),s?q(n):A({ok:!0})}import{assign as I,createLogger as H}from"@walkeros/core";import{assign as T,getId as G,isFunction as U,isString as L}from"@walkeros/core";import{isObject as M}from"@walkeros/core";async function W(n,e,t,s){let r;switch(e){case o.Commands.Config:M(t)&&T(n.config,t,{shallow:!1});break;case o.Commands.Consent:M(t)&&(r=await F(n,t));break;case o.Commands.Custom:M(t)&&(n.custom=T(n.custom,t));break;case o.Commands.Destination:M(t)&&U(t.push)&&(r=await O(n,{code:t},s));break;case o.Commands.Globals:M(t)&&(n.globals=T(n.globals,t));break;case o.Commands.On:L(t)&&R(n,t,s);break;case o.Commands.Ready:B(n,"ready");break;case o.Commands.Run:r=await z(n,t);break;case o.Commands.Session:B(n,"session");break;case o.Commands.User:M(t)&&T(n.user,t,{shallow:!1})}return r||A({ok:!0})}function _(n,e){if(!e.name)throw new Error("Event name is required");const[o,t]=e.name.split(" ");if(!o||!t)throw new Error("Event name is invalid");++n.count;const{timestamp:s=Date.now(),group:r=n.group,count:c=n.count}=e,{name:i=`${o} ${t}`,data:a={},context:u={},globals:g=n.globals,custom:l={},user:f=n.user,nested:d=[],consent:m=n.consent,id:p=`${s}-${r}-${c}`,trigger:h="",entity:b=o,action:y=t,timing:w=0,version:k={source:n.version,tagging:n.config.tagging||0},source:v={type:"collector",id:"",previous_id:""}}=e;return{name:i,data:a,context:u,globals:g,custom:l,user:f,nested:d,consent:m,id:p,trigger:h,entity:b,action:y,timestamp:s,timing:w,group:r,count:c,version:k,source:v}}async function z(n,e){n.allowed=!0,n.count=0,n.group=G(),n.timing=Date.now(),e&&(e.consent&&(n.consent=T(n.consent,e.consent)),e.user&&(n.user=T(n.user,e.user)),e.globals&&(n.globals=T(n.config.globalsStatic||{},e.globals)),e.custom&&(n.custom=T(n.custom,e.custom))),Object.values(n.destinations).forEach(n=>{n.queue=[]}),n.queue=[],n.round++;const o=await q(n);return B(n,"run"),o}import{getGrantedConsent as K,processEventMapping as J,tryCatchAsync as N,useHooks as Q}from"@walkeros/core";function V(n,e){return Q(async(o,t={})=>await N(async()=>{const{id:s,ingest:r,mapping:c,preChain:i}=t;let a=o;const u=r?Object.freeze(r):void 0;if(c){const e=await J(a,c,n);if(e.ignore)return A({ok:!0});if(c.consent){if(!K(c.consent,n.consent,e.event.consent))return A({ok:!0})}a=e.event}if(i?.length&&n.transformers&&Object.keys(n.transformers).length>0){const e=await v(n,n.transformers,i,a,u);if(null===e)return A({ok:!0});a=e}const g=e(a),l=_(n,g);return await q(n,l,{id:s,ingest:u})},()=>A({ok:!1}))(),"Push",n.hooks)}import{useHooks as X,tryCatchAsync as Y}from"@walkeros/core";async function Z(n){const e=I({globalsStatic:{},sessionStatic:{},tagging:0,run:!0},n,{merge:!1,extend:!1}),o={level:n.logger?.level,handler:n.logger?.handler},t=H(o),s={...e.globalsStatic,...n.globals},r={allowed:!1,config:e,consent:n.consent||{},count:0,custom:n.custom||{},destinations:{},transformers:{},transformerChain:{pre:[],post:{}},globals:s,group:"",hooks:{},logger:t,on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:n.user||{},version:"0.6.0",sources:{},push:void 0,command:void 0};return r.push=V(r,n=>({timing:Math.round((Date.now()-r.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...n})),r.command=function(n,e){return X(async(o,t,s)=>await Y(async()=>await e(n,o,t,s),()=>A({ok:!1}))(),"Command",n.hooks)}(r,W),r.destinations=await S(0,n.destinations||{}),r.transformers=await async function(n,e={}){const o={};for(const[t,s]of Object.entries(e)){const{code:e,config:r={},env:c={}}=s,i=n.logger.scope("transformer").scope(t),a={collector:n,logger:i,id:t,config:r,env:c},u=await e(a);o[t]=u}return o}(r,n.transformers||{}),r}import{getMappingValue as nn,tryCatchAsync as en}from"@walkeros/core";function on(n){const e={};for(const[o,t]of Object.entries(n))e[o]={next:t.config.next};return e}async function tn(n,e={}){const o={};for(const[t,s]of Object.entries(e)){const{code:e,config:r={},env:c={},primary:i,next:a}=s;let u;const g=y(a,on(n.transformers)),l=(e,o={})=>n.push(e,{...o,id:t,ingest:u,mapping:r,preChain:g}),f=n.logger.scope("source").scope(t),d={push:l,command:n.command,sources:n.sources,elb:n.sources.elb.push,logger:f,...c},m={collector:n,logger:f,id:t,config:r,env:d,setIngest:async e=>{u=r.ingest?await nn(e,r.ingest,{collector:n}):void 0}},p=await en(e)(m);if(!p)continue;const h=p.type||"unknown",b=n.logger.scope(h).scope(t);d.logger=b,i&&(p.config={...p.config,primary:i}),o[t]=p}return o}async function sn(n){n=n||{};const e=await Z(n),o=(t=e,{type:"elb",config:{},push:async(n,e,o,s,r,c)=>{if("string"==typeof n&&n.startsWith("walker ")){const s=n.replace("walker ","");return t.command(s,e,o)}let i;if("string"==typeof n)i={name:n},e&&"object"==typeof e&&!Array.isArray(e)&&(i.data=e);else{if(!n||"object"!=typeof n)return A({ok:!1});i=n,e&&"object"==typeof e&&!Array.isArray(e)&&(i.data={...i.data||{},...e})}return s&&"object"==typeof s&&(i.context=s),r&&Array.isArray(r)&&(i.nested=r),c&&"object"==typeof c&&(i.custom=c),t.push(i)}});var t;e.sources.elb=o;const s=await tn(e,n.sources||{});Object.assign(e.sources,s);const{consent:r,user:c,globals:i,custom:a}=n;r&&await e.command("consent",r),c&&await e.command("user",c),i&&Object.assign(e.globals,i),a&&Object.assign(e.custom,a),e.config.run&&await e.command("run");let u=o.push;const g=Object.values(e.sources).filter(n=>"elb"!==n.type),l=g.find(n=>n.config.primary);return l?u=l.push:g.length>0&&(u=g[0].push),{collector:e,elb:u}}export{n as Code,e as Commands,o as Const,O as addDestination,W as commonHandleCommand,_ as createEvent,V as createPush,A as createPushResult,m as destinationCode,x as destinationInit,E as destinationPush,S as initDestinations,tn as initSources,$ as mergeEnvironments,R as on,B as onApply,q as pushToDestinations,z as runCollector,F as setConsent,sn as startFlow};//# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types/code.ts","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/destination-code.ts","../src/on.ts","../src/collector.ts","../src/handle.ts","../src/push.ts","../src/command.ts","../src/elb.ts","../src/source.ts","../src/flow.ts"],"sourcesContent":["import type { Destination, Mapping, On, WalkerOS } from '@walkeros/core';\n\nexport interface Settings {\n scripts?: string[];\n init?: string;\n on?: string;\n push?: string;\n pushBatch?: string;\n}\n\nexport interface CodeMapping extends Mapping.Rule<CodeMapping> {\n push?: string;\n pushBatch?: string;\n}\n\nexport type Types = Destination.Types<Settings, CodeMapping>;\nexport type Config = Destination.Config<Types>;\nexport type Context = Destination.Context<Types>;\nexport type InitContext = Destination.InitContext<Types>;\nexport type PushContext = Destination.PushContext<Types>;\nexport type PushBatchContext = Destination.PushBatchContext<Types>;\n\nexport type InitFn = (context: InitContext) => void;\nexport type OnFn = (type: On.Types, context: Context) => void;\nexport type PushFn = (event: WalkerOS.Event, context: PushContext) => void;\nexport type PushBatchFn = (\n batch: Destination.Batch<CodeMapping>,\n context: PushBatchContext,\n) => void;\n","import type { Collector } from '@walkeros/core';\nimport type { CommandTypes, StorageType } from './types/collector';\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\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 isDefined,\n isObject,\n processEventMapping,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { destinationCode } from './destination-code';\n\nfunction resolveCode(code: Destination.Instance | true): Destination.Instance {\n return code === true ? destinationCode : code;\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 resolved = resolveCode(code);\n const destination: Destination.Instance = {\n ...resolved,\n config,\n env: mergeEnvironments(resolved.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 const currentEvent = clone(event);\n\n // Note: Policy is now applied in processEventMapping() within destinationPush()\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 // Log the error with destination scope\n const destType = destination.type || 'unknown';\n collector.logger.scope(destType).error('Push failed', {\n error: err,\n event: event.name,\n });\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 // Create scoped logger for this destination: [type:id] or [unknown:id]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context = {\n collector,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n logger: destLogger,\n } as Destination.InitContext;\n\n destLogger.debug('init');\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 destLogger.debug('init done');\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\n const processed = await processEventMapping(event, config, collector);\n\n if (processed.ignore) return false;\n\n // Create scoped logger for this destination: [type] or [unknown]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context: Destination.PushContext = {\n collector,\n config,\n data: processed.data,\n mapping: processed.mapping,\n env: mergeEnvironments(destination.env, config.env),\n logger: destLogger,\n };\n\n const eventMapping = processed.mapping;\n const mappingKey = processed.mappingKey || '* *';\n\n if (eventMapping?.batch && destination.pushBatch) {\n // Initialize batch registry on destination (not on shared mapping config)\n destination.batches = destination.batches || {};\n\n // Get or create batch state for this mapping key\n if (!destination.batches[mappingKey]) {\n const batched: Destination.Batch<unknown> = {\n key: mappingKey,\n events: [],\n data: [],\n };\n\n destination.batches[mappingKey] = {\n batched,\n batchFn: debounce(() => {\n const batchState = destination.batches![mappingKey];\n const currentBatched = batchState.batched;\n\n const batchContext: Destination.PushBatchContext = {\n collector,\n config,\n // Note: batch.data contains all transformed data; context.data is for single events\n data: undefined,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n logger: destLogger,\n };\n\n destLogger.debug('push batch', {\n events: currentBatched.events.length,\n });\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n collector.hooks,\n )(currentBatched, batchContext);\n\n destLogger.debug('push batch done');\n\n // Reset batch\n currentBatched.events = [];\n currentBatched.data = [];\n }, eventMapping.batch),\n };\n }\n\n // Add event to batch\n const batchState = destination.batches[mappingKey];\n batchState.batched.events.push(processed.event);\n if (isDefined(processed.data)) batchState.batched.data.push(processed.data);\n\n // Trigger debounced batch\n batchState.batchFn();\n } else {\n destLogger.debug('push', { event: processed.event.name });\n\n // It's time to go to the destination's side now\n await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(processed.event, context);\n\n destLogger.debug('push done');\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 const resolved = resolveCode(code);\n\n const mergedConfig = {\n ...resolved.config,\n ...config,\n };\n\n const mergedEnv = mergeEnvironments(resolved.env, env);\n\n result[name] = {\n ...resolved,\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 */\nexport function 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 { Destination } from '@walkeros/core';\nimport type { CodeMapping, Settings } from './types/code';\n\nexport const destinationCode: Destination.Instance = {\n type: 'code',\n config: {},\n\n init(context) {\n const { config, logger } = context;\n const settings = config.settings as Settings | undefined;\n\n // Inject scripts (fire and forget)\n const scripts = settings?.scripts;\n if (scripts && typeof document !== 'undefined') {\n for (const src of scripts) {\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n document.head.appendChild(script);\n }\n }\n\n // Execute init code\n const initCode = settings?.init;\n if (!initCode) return;\n try {\n const fn = new Function('context', initCode);\n fn(context);\n } catch (e) {\n logger.error('Code destination init error:', e);\n }\n },\n\n push(event, context) {\n const { mapping, config, logger } = context;\n const pushCode =\n (mapping as CodeMapping | undefined)?.push ??\n (config.settings as Settings | undefined)?.push;\n if (!pushCode) return;\n try {\n const fn = new Function('event', 'context', pushCode);\n fn(event, context);\n } catch (e) {\n logger.error('Code destination push error:', e);\n }\n },\n\n pushBatch(batch, context) {\n const { mapping, config, logger } = context;\n const pushBatchCode =\n (mapping as CodeMapping | undefined)?.pushBatch ??\n (config.settings as Settings | undefined)?.pushBatch;\n if (!pushBatchCode) return;\n try {\n const fn = new Function('batch', 'context', pushBatchCode);\n fn(batch, context);\n } catch (e) {\n logger.error('Code destination pushBatch error:', e);\n }\n },\n\n on(type, context) {\n const { config, logger } = context;\n const onCode = (config.settings as Settings | undefined)?.on;\n if (!onCode) return;\n try {\n const fn = new Function('type', 'context', onCode);\n fn(type, context);\n } catch (e) {\n logger.error('Code destination on error:', e);\n }\n },\n};\n\nexport default destinationCode;\n","import type { Collector, On, WalkerOS, Destination } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\nimport { mergeEnvironments } from './destination';\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 const destType = destination.type || 'unknown';\n const destLogger = collector.logger\n .scope(destType)\n .scope('on')\n .scope(type);\n\n const context: Destination.Context = {\n collector,\n config: destination.config,\n data: contextData as Destination.Data,\n env: mergeEnvironments(destination.env, destination.config.env),\n logger: destLogger,\n };\n\n tryCatch(destination.on)(type, context);\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, Logger, WalkerOS } from '@walkeros/core';\nimport { assign, createLogger } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations } from './destination';\nimport { createPush } from './push';\nimport { createCommand } from './command';\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 run: true,\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n // Create logger with config from initConfig\n const loggerConfig: Logger.Config = {\n level: initConfig.logger?.level,\n handler: initConfig.logger?.handler,\n };\n const logger = createLogger(loggerConfig);\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 logger,\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 Collector.PushFn, // Placeholder, will be set below\n command: undefined as unknown as Collector.CommandFn, // Placeholder, will be set below\n };\n\n // Set the push and command functions with the collector reference\n collector.push = createPush(\n collector,\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 collector.command = createCommand(collector, commonHandleCommand);\n\n // Initialize destinations after collector is fully created\n // Sources are initialized in startFlow after ELB source is created\n collector.destinations = await initDestinations(\n collector,\n initConfig.destinations || {},\n );\n\n return collector;\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Const } from './constants';\nimport { addDestination, pushToDestinations } from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject } 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 a full event from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param partialEvent The partial event to transform.\n * @returns The full event.\n */\nexport function createEvent(\n collector: Collector.Instance,\n partialEvent: WalkerOS.PartialEvent,\n): WalkerOS.Event {\n if (!partialEvent.name) throw new Error('Event name is required');\n\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n ++collector.count;\n\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\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 return {\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\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, WalkerOS, Elb } from '@walkeros/core';\nimport {\n getGrantedConsent,\n processEventMapping,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEvent } from './handle';\nimport { pushToDestinations, createPushResult } from './destination';\n\n/**\n * Creates the push function for the collector.\n * Handles source mapping, event creation, and routing to destinations.\n *\n * @param collector - The walkerOS collector instance\n * @param prepareEvent - Function to enrich partial events\n * @returns The push function\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Collector.PushFn {\n return useHooks(\n async (\n event: WalkerOS.DeepPartialEvent,\n context: Collector.PushContext = {},\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n let partialEvent = event;\n\n // Apply source mapping if provided in context\n if (context.mapping) {\n const processed = await processEventMapping(\n partialEvent,\n context.mapping,\n collector,\n );\n\n // Check ignore flag\n if (processed.ignore) {\n return createPushResult({ ok: true });\n }\n\n // Check consent requirements\n if (context.mapping.consent) {\n const grantedConsent = getGrantedConsent(\n context.mapping.consent,\n collector.consent,\n processed.event.consent as WalkerOS.Consent | undefined,\n );\n\n if (!grantedConsent) {\n return createPushResult({ ok: true });\n }\n }\n\n partialEvent = processed.event;\n }\n\n // Prepare event (add timing, source info)\n const enrichedEvent = prepareEvent(partialEvent);\n\n // Create full event\n const fullEvent = createEvent(collector, enrichedEvent);\n\n // Push to destinations\n return await pushToDestinations(collector, fullEvent);\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Collector.PushFn;\n}\n","import type { Collector, Elb } from '@walkeros/core';\nimport type { HandleCommandFn } from './types/collector';\nimport { useHooks, tryCatchAsync } from '@walkeros/core';\nimport { createPushResult } from './destination';\n\n/**\n * Creates the command function for the collector.\n * Handles walker commands (config, consent, destination, etc.)\n *\n * @param collector - The walkerOS collector instance\n * @param handleCommand - Command handler function\n * @returns The command function\n */\nexport function createCommand<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n): Collector.CommandFn {\n return useHooks(\n async (\n command: string,\n data?: unknown,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n return await handleCommand(collector, command, data, options);\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Command',\n collector.hooks,\n ) as Collector.CommandFn;\n}\n","import type { Collector, Source, WalkerOS, Elb } from '@walkeros/core';\n\n/**\n * Creates the default ELB source.\n * Routes between collector.push and collector.command based on input.\n * Provides backward-compatible flexible argument interface.\n *\n * @param collector - The walkerOS collector instance\n * @returns ELB source instance\n */\nexport function createElbSource(\n collector: Collector.Instance,\n): Source.Instance {\n return {\n type: 'elb',\n config: {},\n\n // The push function is the elb() interface users interact with\n push: async (\n eventOrCommand?: unknown,\n data?: unknown,\n options?: unknown,\n context?: unknown,\n nested?: WalkerOS.Entities,\n custom?: WalkerOS.Properties,\n ): Promise<Elb.PushResult> => {\n // Detect walker commands\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n const command = eventOrCommand.replace('walker ', '');\n return collector.command(command, data, options);\n }\n\n // Build event object\n let event: WalkerOS.DeepPartialEvent;\n\n if (typeof eventOrCommand === 'string') {\n // Convert string to object: elb('page view', { title: 'Home' })\n event = { name: eventOrCommand };\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = data as WalkerOS.Properties;\n }\n } else if (eventOrCommand && typeof eventOrCommand === 'object') {\n // Use object directly: elb({ name: 'page view', data: {...} })\n event = eventOrCommand as WalkerOS.DeepPartialEvent;\n // Merge additional data if provided\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = {\n ...(event.data || {}),\n ...(data as WalkerOS.Properties),\n };\n }\n } else {\n // Invalid input\n return { ok: false, successful: [], queued: [], failed: [] };\n }\n\n // Add optional properties if provided\n if (context && typeof context === 'object') {\n event.context = context as WalkerOS.OrderedProperties;\n }\n if (nested && Array.isArray(nested)) {\n event.nested = nested;\n }\n if (custom && typeof custom === 'object') {\n event.custom = custom as WalkerOS.Properties;\n }\n\n // Call collector.push with event object\n return collector.push(event);\n },\n };\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 * @returns Initialized sources\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 // Create wrapped push that auto-applies source mapping config\n const wrappedPush: Collector.PushFn = (\n event: WalkerOS.DeepPartialEvent,\n context: Collector.PushContext = {},\n ) => {\n // Pass source config as mapping in context\n return collector.push(event, {\n ...context,\n mapping: config,\n });\n };\n\n // Create initial logger scoped to sourceId (type will be added after init)\n const initialLogger = collector.logger.scope('source').scope(sourceId);\n\n const cleanEnv: Source.Env = {\n push: wrappedPush,\n command: collector.command,\n sources: collector.sources, // Provide access to all sources for chaining\n elb: collector.sources.elb.push, // ELB source is always available\n logger: initialLogger,\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 // Update logger with actual source type: [type:sourceId] or [unknown:sourceId]\n const sourceType = sourceInstance.type || 'unknown';\n const sourceLogger = collector.logger.scope(sourceType).scope(sourceId);\n cleanEnv.logger = sourceLogger;\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, Elb } from '@walkeros/core';\nimport type { StartFlow } from './types';\nimport { collector } from './collector';\nimport { createElbSource } from './elb';\nimport { initSources } from './source';\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\n // Create and register ELB source first\n const elbSource = createElbSource(instance);\n instance.sources.elb = elbSource;\n\n // Now initialize other sources with ELB source available\n const additionalSources = await initSources(\n instance,\n initConfig.sources || {},\n );\n Object.assign(instance.sources, additionalSources);\n\n const { consent, user, globals, custom } = initConfig;\n\n if (consent) await instance.command('consent', consent);\n if (user) await instance.command('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.command('run');\n\n // Determine the primary elb:\n // 1. Use explicitly marked primary source\n // 2. Use first non-elb source if any exist\n // 3. Fallback to ELB source\n let primaryElb: Elb.Fn = elbSource.push as Elb.Fn;\n\n const sources = Object.values(instance.sources).filter(\n (source) => source.type !== 'elb',\n );\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 as Elb.Fn;\n } else if (sources.length > 0) {\n // Use first source as default\n primaryElb = sources[0].push as Elb.Fn;\n }\n\n return {\n collector: instance,\n elb: primaryElb as ElbPush,\n };\n}\n"],"mappings":";AAAA;;;ACGO,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,EACL,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AACV;AAEA,IAAM,eAA+C;AAAA,EACnD,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS;AACX;AAEA,IAAM,QAAQ;AAAA,EACZ,SAAS;AACX;AAEO,IAAM,QAAQ;AAAA,EACnB;AAAA,EACA;AACF;;;ACrCA,SAAS,UAAAA,eAAc;;;ACAvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACTA,IAAM,kBAAwC;AAAA,EACnD,MAAM;AAAA,EACN,QAAQ,CAAC;AAAA,EAET,KAAK,SAAS;AACZ,UAAM,EAAE,QAAQ,OAAO,IAAI;AAC3B,UAAM,WAAW,OAAO;AAGxB,UAAM,UAAU,UAAU;AAC1B,QAAI,WAAW,OAAO,aAAa,aAAa;AAC9C,iBAAW,OAAO,SAAS;AACzB,cAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,eAAO,MAAM;AACb,eAAO,QAAQ;AACf,iBAAS,KAAK,YAAY,MAAM;AAAA,MAClC;AAAA,IACF;AAGA,UAAM,WAAW,UAAU;AAC3B,QAAI,CAAC,SAAU;AACf,QAAI;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AAS,QAAQ,MAAM;AAGvB,QAAM,oBAAoB,MAAM;AAAA,IAC9B;AAAA,IACA,WAAW,WAAW,CAAC;AAAA,EACzB;AACA,SAAO,OAAO,SAAS,SAAS,iBAAiB;AAEjD,QAAM,EAAE,SAAS,MAAM,SAAS,OAAO,IAAI;AAE3C,MAAI,QAAS,OAAM,SAAS,QAAQ,WAAW,OAAO;AACtD,MAAI,KAAM,OAAM,SAAS,QAAQ,QAAQ,IAAI;AAC7C,MAAI,QAAS,QAAO,OAAO,SAAS,SAAS,OAAO;AACpD,MAAI,OAAQ,QAAO,OAAO,SAAS,QAAQ,MAAM;AAEjD,MAAI,SAAS,OAAO,IAAK,OAAM,SAAS,QAAQ,KAAK;AAMrD,MAAI,aAAqB,UAAU;AAEnC,QAAM,UAAU,OAAO,OAAO,SAAS,OAAO,EAAE;AAAA,IAC9C,CAAC,WAAW,OAAO,SAAS;AAAA,EAC9B;AAGA,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":["assign","collector","event","batchState","collector","on","option","collector","assign","assign","assign","getId","isObject","collector","isObject","assign","getId","getGrantedConsent","processEventMapping","tryCatchAsync","useHooks","collector","useHooks","tryCatchAsync","processEventMapping","getGrantedConsent","useHooks","tryCatchAsync","collector","useHooks","tryCatchAsync","assign","collector","collector","tryCatchAsync","collector"]}
1
+ {"version":3,"sources":["../src/types/code.ts","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/destination-code.ts","../src/transformer.ts","../src/on.ts","../src/collector.ts","../src/handle.ts","../src/push.ts","../src/command.ts","../src/elb.ts","../src/source.ts","../src/flow.ts"],"sourcesContent":["import type { Destination, Mapping, On, WalkerOS } from '@walkeros/core';\n\nexport interface Settings {\n scripts?: string[];\n init?: string;\n on?: string;\n push?: string;\n pushBatch?: string;\n}\n\nexport interface CodeMapping extends Mapping.Rule<CodeMapping> {\n push?: string;\n pushBatch?: string;\n}\n\nexport type Types = Destination.Types<Settings, CodeMapping>;\nexport type Config = Destination.Config<Types>;\nexport type Context = Destination.Context<Types>;\nexport type PushContext = Destination.PushContext<Types>;\nexport type PushBatchContext = Destination.PushBatchContext<Types>;\n\nexport type InitFn = (context: Context) => void;\nexport type OnFn = (type: On.Types, context: Context) => void;\nexport type PushFn = (event: WalkerOS.Event, context: PushContext) => void;\nexport type PushBatchFn = (\n batch: Destination.Batch<CodeMapping>,\n context: PushBatchContext,\n) => void;\n","import type { Collector } from '@walkeros/core';\nimport type { CommandTypes, StorageType } from './types/collector';\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\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 isDefined,\n isObject,\n processEventMapping,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { destinationCode } from './destination-code';\nimport { runTransformerChain } from './transformer';\n\nfunction resolveCode(code: Destination.Instance | true): Destination.Instance {\n return code === true ? destinationCode : code;\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 resolved = resolveCode(code);\n const destination: Destination.Instance = {\n ...resolved,\n config,\n env: mergeEnvironments(resolved.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 meta - Optional metadata with id and ingest.\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 meta: { id?: string; ingest?: unknown } = {},\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 const currentEvent = clone(event);\n\n // Note: Policy is now applied in processEventMapping() within destinationPush()\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 id,\n );\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error: unknown;\n let response: unknown;\n if (!destination.dlq) destination.dlq = [];\n\n // Get post-collector transformer chain for this destination\n const postChain = collector.transformerChain?.post?.[id] || [];\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 // Run post-collector transformer chain if configured for this destination\n let processedEvent: WalkerOS.Event | null = event;\n if (\n postChain.length > 0 &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const chainResult = await runTransformerChain(\n collector,\n collector.transformers,\n postChain,\n event,\n meta.ingest,\n );\n\n if (chainResult === null) {\n // Chain stopped - skip this event for this destination\n return event;\n }\n\n // Use the processed event (cast back to full Event type)\n processedEvent = chainResult as WalkerOS.Event;\n }\n\n const result = await tryCatchAsync(destinationPush, (err) => {\n // Log the error with destination scope\n const destType = destination.type || 'unknown';\n collector.logger.scope(destType).error('Push failed', {\n error: err,\n event: processedEvent!.name,\n });\n error = err; // oh no\n\n // Add failed event to destinations DLQ\n destination.dlq!.push([processedEvent!, err]);\n\n return undefined;\n })(collector, destination, id, processedEvent!, meta.ingest);\n\n // Capture the last response (for single event pushes)\n if (result !== undefined) response = result;\n\n return event;\n }),\n );\n\n return { id, destination, error, response };\n }),\n );\n\n // Build result objects\n const done: Record<string, Destination.Ref> = {};\n const queued: Record<string, Destination.Ref> = {};\n const failed: Record<string, Destination.Ref> = {};\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n const ref: Destination.Ref = {\n type: destination.type || 'unknown',\n data: result.response, // Capture push() return value\n };\n\n if (result.error) {\n ref.error = result.error;\n failed[result.id] = ref;\n } else if (result.queue && result.queue.length) {\n destination.queue = (destination.queue || []).concat(result.queue);\n queued[result.id] = ref;\n } else {\n done[result.id] = ref;\n }\n }\n\n return createPushResult({\n event,\n ...(Object.keys(done).length && { done }),\n ...(Object.keys(queued).length && { queued }),\n ...(Object.keys(failed).length && { 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 * @param destId - The destination ID.\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 destId: string,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n // Create scoped logger for this destination: [type:id] or [unknown:id]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context: Destination.Context = {\n collector,\n logger: destLogger,\n id: destId,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n destLogger.debug('init');\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 destLogger.debug('init done');\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 destId - The destination ID.\n * @param event - The event to push.\n * @param ingest - Optional ingest metadata (frozen, same reference).\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 destId: string,\n event: WalkerOS.Event,\n ingest?: unknown,\n): Promise<unknown> {\n const { config } = destination;\n\n const processed = await processEventMapping(event, config, collector);\n\n if (processed.ignore) return false;\n\n // Create scoped logger for this destination: [type] or [unknown]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context: Destination.PushContext = {\n collector,\n logger: destLogger,\n id: destId,\n config,\n data: processed.data,\n rule: processed.mapping,\n ingest,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n const eventMapping = processed.mapping;\n const mappingKey = processed.mappingKey || '* *';\n\n if (eventMapping?.batch && destination.pushBatch) {\n // Initialize batch registry on destination (not on shared mapping config)\n destination.batches = destination.batches || {};\n\n // Get or create batch state for this mapping key\n if (!destination.batches[mappingKey]) {\n const batched: Destination.Batch<unknown> = {\n key: mappingKey,\n events: [],\n data: [],\n };\n\n destination.batches[mappingKey] = {\n batched,\n batchFn: debounce(() => {\n const batchState = destination.batches![mappingKey];\n const currentBatched = batchState.batched;\n\n const batchContext: Destination.PushBatchContext = {\n collector,\n logger: destLogger,\n id: destId,\n config,\n // Note: batch.data contains all transformed data; context.data is for single events\n data: undefined,\n rule: eventMapping, // Renamed from mapping to rule\n ingest, // Same frozen reference\n env: mergeEnvironments(destination.env, config.env),\n };\n\n destLogger.debug('push batch', {\n events: currentBatched.events.length,\n });\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n collector.hooks,\n )(currentBatched, batchContext);\n\n destLogger.debug('push batch done');\n\n // Reset batch\n currentBatched.events = [];\n currentBatched.data = [];\n }, eventMapping.batch),\n };\n }\n\n // Add event to batch\n const batchState = destination.batches[mappingKey];\n batchState.batched.events.push(processed.event);\n if (isDefined(processed.data)) batchState.batched.data.push(processed.data);\n\n // Trigger debounced batch\n batchState.batchFn();\n } else {\n destLogger.debug('push', { event: processed.event.name });\n\n // It's time to go to the destination's side now\n const response = await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(processed.event, context);\n\n destLogger.debug('push done');\n\n return response;\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 {\n ok: !partialResult?.failed,\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 const resolved = resolveCode(code);\n\n const mergedConfig = {\n ...resolved.config,\n ...config,\n };\n\n const mergedEnv = mergeEnvironments(resolved.env, env);\n\n result[name] = {\n ...resolved,\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 */\nexport function 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 { Destination } from '@walkeros/core';\nimport type { CodeMapping, Settings } from './types/code';\n\nexport const destinationCode: Destination.Instance = {\n type: 'code',\n config: {},\n\n init(context) {\n const { config, logger } = context;\n const settings = config.settings as Settings | undefined;\n\n // Inject scripts (fire and forget)\n const scripts = settings?.scripts;\n if (scripts && typeof document !== 'undefined') {\n for (const src of scripts) {\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n document.head.appendChild(script);\n }\n }\n\n // Execute init code\n const initCode = settings?.init;\n if (!initCode) return;\n try {\n const fn = new Function('context', initCode);\n fn(context);\n } catch (e) {\n logger.error('Code destination init error:', e);\n }\n },\n\n push(event, context) {\n const { rule, config, logger } = context;\n const pushCode =\n (rule as CodeMapping | undefined)?.push ??\n (config.settings as Settings | undefined)?.push;\n if (!pushCode) return;\n try {\n const fn = new Function('event', 'context', pushCode);\n fn(event, context);\n } catch (e) {\n logger.error('Code destination push error:', e);\n }\n },\n\n pushBatch(batch, context) {\n const { rule, config, logger } = context;\n const pushBatchCode =\n (rule as CodeMapping | undefined)?.pushBatch ??\n (config.settings as Settings | undefined)?.pushBatch;\n if (!pushBatchCode) return;\n try {\n const fn = new Function('batch', 'context', pushBatchCode);\n fn(batch, context);\n } catch (e) {\n logger.error('Code destination pushBatch error:', e);\n }\n },\n\n on(type, context) {\n const { config, logger } = context;\n const onCode = (config.settings as Settings | undefined)?.on;\n if (!onCode) return;\n try {\n const fn = new Function('type', 'context', onCode);\n fn(type, context);\n } catch (e) {\n logger.error('Code destination on error:', e);\n }\n },\n};\n\nexport default destinationCode;\n","import type { Collector, Transformer, WalkerOS } from '@walkeros/core';\nimport { isObject, tryCatchAsync, useHooks } from '@walkeros/core';\n\n/**\n * Resolved transformer chains for a flow.\n */\nexport interface TransformerChain {\n /** Ordered transformer IDs to run before collector (from source.next) */\n pre: string[];\n /** Per-destination transformer chains (from destination.before) */\n post: Record<string, string[]>;\n}\n\n/**\n * Extended collector with transformer support.\n */\nexport interface CollectorWithTransformers extends Collector.Instance {\n transformers: Transformer.Transformers;\n transformerChain: TransformerChain;\n}\n\n/**\n * Walks a transformer chain starting from a given transformer ID.\n * Returns ordered array of transformer IDs in the chain.\n *\n * @param startId - First transformer in chain\n * @param transformers - Available transformer configs with optional `next` field\n * @returns Ordered array of transformer IDs\n */\nexport function walkChain(\n startId: string | undefined,\n transformers: Record<string, { next?: string }> = {},\n): string[] {\n if (!startId) return [];\n\n const chain: string[] = [];\n const visited = new Set<string>();\n let current: string | undefined = startId;\n\n while (current && transformers[current]) {\n if (visited.has(current)) {\n // Circular reference detected - stop walking\n break;\n }\n visited.add(current);\n chain.push(current);\n current = transformers[current].next;\n }\n\n return chain;\n}\n\n/**\n * Resolves transformer chains from flow configuration.\n * Builds per-destination post-collector chains.\n * Note: Pre-chains are now resolved per-source in source.ts\n *\n * @param sources - Source configurations (unused, kept for API compatibility)\n * @param destinations - Destination configurations with optional before property\n * @param transformers - Transformer configurations with optional next property\n * @returns Resolved transformer chains\n */\nexport function resolveTransformerGraph(\n _sources: Record<string, { next?: string }> = {},\n destinations: Record<string, { before?: string }> = {},\n transformers: Record<string, { next?: string }> = {},\n): TransformerChain {\n const post: Record<string, string[]> = {};\n\n // Build post-collector chains from destinations\n for (const [destName, dest] of Object.entries(destinations)) {\n if (dest.before) {\n post[destName] = walkChain(dest.before, transformers);\n }\n }\n\n // Note: pre-chains are now resolved per-source in source.ts\n return { pre: [], post };\n}\n\n/**\n * Initializes transformer instances from configuration.\n * Does NOT call transformer.init() - that happens lazily before first push.\n *\n * @param collector - The collector instance\n * @param initTransformers - Transformer initialization configurations\n * @returns Initialized transformer instances\n */\nexport async function initTransformers(\n collector: Collector.Instance,\n initTransformers: Transformer.InitTransformers = {},\n): Promise<Transformer.Transformers> {\n const result: Transformer.Transformers = {};\n\n for (const [transformerId, transformerDef] of Object.entries(\n initTransformers,\n )) {\n const { code, config = {}, env = {} } = transformerDef;\n\n // Build transformer context for init\n const transformerLogger = collector.logger\n .scope('transformer')\n .scope(transformerId);\n\n const context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n config,\n env: env as Transformer.Env,\n };\n\n // Initialize the transformer instance with context\n const instance = await code(context);\n\n result[transformerId] = instance;\n }\n\n return result;\n}\n\n/**\n * Initializes a transformer if it hasn't been initialized yet.\n * Called lazily before first push.\n *\n * @param collector - The collector instance\n * @param transformer - The transformer to initialize\n * @param transformerId - The transformer ID\n * @returns Whether initialization succeeded\n */\nexport async function transformerInit(\n collector: Collector.Instance,\n transformer: Transformer.Instance,\n transformerId: string,\n): Promise<boolean> {\n // Check if already initialized\n if (transformer.init && !transformer.config.init) {\n const transformerType = transformer.type || 'unknown';\n const transformerLogger = collector.logger.scope(\n `transformer:${transformerType}`,\n );\n\n const context: Transformer.Context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n config: transformer.config,\n env: mergeTransformerEnvironments(transformer.config.env),\n };\n\n transformerLogger.debug('init');\n\n const configResult = await useHooks(\n transformer.init,\n 'TransformerInit',\n collector.hooks,\n )(context);\n\n // Check for initialization failure\n if (configResult === false) return false;\n\n // Update config if returned\n transformer.config = {\n ...(configResult || transformer.config),\n init: true,\n };\n\n transformerLogger.debug('init done');\n }\n\n return true;\n}\n\n/**\n * Pushes an event through a single transformer.\n *\n * @param collector - The collector instance\n * @param transformer - The transformer to push to\n * @param transformerId - The transformer ID\n * @param event - The event to process\n * @param ingest - Optional ingest metadata (frozen, same reference)\n * @returns The processed event, void for passthrough, or false to stop chain\n */\nexport async function transformerPush(\n collector: Collector.Instance,\n transformer: Transformer.Instance,\n transformerId: string,\n event: WalkerOS.DeepPartialEvent,\n ingest?: unknown,\n): Promise<WalkerOS.DeepPartialEvent | false | void> {\n const transformerType = transformer.type || 'unknown';\n const transformerLogger = collector.logger.scope(\n `transformer:${transformerType}`,\n );\n\n const context: Transformer.Context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n ingest, // Same frozen reference, no copying\n config: transformer.config,\n env: mergeTransformerEnvironments(transformer.config.env),\n };\n\n transformerLogger.debug('push', { event: (event as { name?: string }).name });\n\n const result = await useHooks(\n transformer.push,\n 'TransformerPush',\n collector.hooks,\n )(event, context);\n\n transformerLogger.debug('push done');\n\n return result;\n}\n\n/**\n * Runs an event through a chain of transformers.\n *\n * @param collector - The collector instance with transformers\n * @param transformers - Map of transformer instances\n * @param chain - Ordered array of transformer IDs to execute\n * @param event - The event to process\n * @param ingest - Optional ingest metadata (frozen, same reference)\n * @returns The processed event or null if chain was stopped\n */\nexport async function runTransformerChain(\n collector: Collector.Instance,\n transformers: Transformer.Transformers,\n chain: string[],\n event: WalkerOS.DeepPartialEvent,\n ingest?: unknown,\n): Promise<WalkerOS.DeepPartialEvent | null> {\n let processedEvent = event;\n\n for (const transformerName of chain) {\n const transformer = transformers[transformerName];\n if (!transformer) {\n collector.logger.info(`Transformer not found: ${transformerName}`);\n continue;\n }\n\n // Initialize transformer if needed\n const isInitialized = await tryCatchAsync(transformerInit)(\n collector,\n transformer,\n transformerName,\n );\n\n if (!isInitialized) {\n collector.logger.info(`Transformer init failed: ${transformerName}`);\n return null; // Stop chain on init failure\n }\n\n // Run the transformer\n const result = (await tryCatchAsync(transformerPush, (err) => {\n collector.logger\n .scope(`transformer:${transformer.type || 'unknown'}`)\n .error('Push failed', { error: err });\n return false; // Stop chain on error\n })(collector, transformer, transformerName, processedEvent, ingest)) as\n | WalkerOS.DeepPartialEvent\n | false\n | void;\n\n // Handle result\n if (result === false) {\n // Transformer explicitly stopped the chain\n return null;\n }\n\n if (result !== undefined) {\n // Transformer returned a modified event\n processedEvent = result;\n }\n // If result is undefined (void), continue with current event unchanged\n }\n\n return processedEvent;\n}\n\n/**\n * Merges transformer environments.\n */\nfunction mergeTransformerEnvironments(\n configEnv?: Transformer.Env,\n): Transformer.Env {\n if (!configEnv) return {};\n if (isObject(configEnv)) return configEnv;\n return {};\n}\n","import type { Collector, On, WalkerOS, Destination } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\nimport { mergeEnvironments } from './destination';\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.entries(collector.destinations).forEach(([destId, destination]) => {\n if (destination.on) {\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger\n .scope(destType)\n .scope('on')\n .scope(type);\n\n const context: Destination.Context = {\n collector,\n logger: destLogger,\n id: destId,\n config: destination.config,\n data: contextData as Destination.Data,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n tryCatch(destination.on)(type, context);\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, Logger, WalkerOS } from '@walkeros/core';\nimport { assign, createLogger } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations } from './destination';\nimport { initTransformers, resolveTransformerGraph } from './transformer';\nimport { createPush } from './push';\nimport { createCommand } from './command';\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 run: true,\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n // Create logger with config from initConfig\n const loggerConfig: Logger.Config = {\n level: initConfig.logger?.level,\n handler: initConfig.logger?.handler,\n };\n const logger = createLogger(loggerConfig);\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 transformers: {},\n transformerChain: { pre: [], post: {} },\n globals: finalGlobals,\n group: '',\n hooks: {},\n logger,\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 Collector.PushFn, // Placeholder, will be set below\n command: undefined as unknown as Collector.CommandFn, // Placeholder, will be set below\n };\n\n // Set the push and command functions with the collector reference\n collector.push = createPush(\n collector,\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 collector.command = createCommand(collector, commonHandleCommand);\n\n // Initialize destinations after collector is fully created\n // Sources are initialized in startFlow after ELB source is created\n collector.destinations = await initDestinations(\n collector,\n initConfig.destinations || {},\n );\n\n // Initialize transformers\n collector.transformers = await initTransformers(\n collector,\n initConfig.transformers || {},\n );\n\n // Resolve transformer chains based on source/destination configuration\n // Note: This is a placeholder - actual chain resolution happens in startFlow\n // when sources are configured with 'next' and destinations with 'before'\n\n return collector;\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Const } from './constants';\nimport {\n addDestination,\n pushToDestinations,\n createPushResult,\n} from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject } 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 result || createPushResult({ ok: true });\n}\n\n/**\n * Creates a full event from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param partialEvent The partial event to transform.\n * @returns The full event.\n */\nexport function createEvent(\n collector: Collector.Instance,\n partialEvent: WalkerOS.PartialEvent,\n): WalkerOS.Event {\n if (!partialEvent.name) throw new Error('Event name is required');\n\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n ++collector.count;\n\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\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 return {\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\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, WalkerOS, Elb } from '@walkeros/core';\nimport {\n getGrantedConsent,\n processEventMapping,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEvent } from './handle';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { runTransformerChain } from './transformer';\n\n/**\n * Creates the push function for the collector.\n * Handles source mapping, event creation, and routing to destinations.\n *\n * @param collector - The walkerOS collector instance\n * @param prepareEvent - Function to enrich partial events\n * @returns The push function\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Collector.PushFn {\n return useHooks(\n async (\n event: WalkerOS.DeepPartialEvent,\n options: Collector.PushOptions = {},\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n const { id, ingest, mapping, preChain } = options;\n let partialEvent = event;\n\n // Freeze ingest for performance (pass by reference, no copying)\n const frozenIngest = ingest ? Object.freeze(ingest) : undefined;\n\n // Apply source mapping if provided in options\n if (mapping) {\n const processed = await processEventMapping(\n partialEvent,\n mapping,\n collector,\n );\n\n // Check ignore flag\n if (processed.ignore) {\n return createPushResult({ ok: true });\n }\n\n // Check consent requirements\n if (mapping.consent) {\n const grantedConsent = getGrantedConsent(\n mapping.consent,\n collector.consent,\n processed.event.consent as WalkerOS.Consent | undefined,\n );\n\n if (!grantedConsent) {\n return createPushResult({ ok: true });\n }\n }\n\n partialEvent = processed.event;\n }\n\n // Run pre-collector transformer chain if provided in options\n if (\n preChain?.length &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const processedEvent = await runTransformerChain(\n collector,\n collector.transformers,\n preChain,\n partialEvent,\n frozenIngest,\n );\n\n // Chain was stopped - event dropped\n if (processedEvent === null) {\n return createPushResult({ ok: true });\n }\n\n partialEvent = processedEvent;\n }\n\n // Prepare event (add timing, source info)\n const enrichedEvent = prepareEvent(partialEvent);\n\n // Create full event\n const fullEvent = createEvent(collector, enrichedEvent);\n\n // Push to destinations with id and ingest\n return await pushToDestinations(collector, fullEvent, {\n id,\n ingest: frozenIngest,\n });\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Collector.PushFn;\n}\n","import type { Collector, Elb } from '@walkeros/core';\nimport type { HandleCommandFn } from './types/collector';\nimport { useHooks, tryCatchAsync } from '@walkeros/core';\nimport { createPushResult } from './destination';\n\n/**\n * Creates the command function for the collector.\n * Handles walker commands (config, consent, destination, etc.)\n *\n * @param collector - The walkerOS collector instance\n * @param handleCommand - Command handler function\n * @returns The command function\n */\nexport function createCommand<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n): Collector.CommandFn {\n return useHooks(\n async (\n command: string,\n data?: unknown,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n return await handleCommand(collector, command, data, options);\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Command',\n collector.hooks,\n ) as Collector.CommandFn;\n}\n","import type { Collector, Source, WalkerOS, Elb } from '@walkeros/core';\nimport { createPushResult } from './destination';\n\n/**\n * Creates the default ELB source.\n * Routes between collector.push and collector.command based on input.\n * Provides backward-compatible flexible argument interface.\n *\n * @param collector - The walkerOS collector instance\n * @returns ELB source instance\n */\nexport function createElbSource(\n collector: Collector.Instance,\n): Source.Instance {\n return {\n type: 'elb',\n config: {},\n\n // The push function is the elb() interface users interact with\n push: async (\n eventOrCommand?: unknown,\n data?: unknown,\n options?: unknown,\n context?: unknown,\n nested?: WalkerOS.Entities,\n custom?: WalkerOS.Properties,\n ): Promise<Elb.PushResult> => {\n // Detect walker commands\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n const command = eventOrCommand.replace('walker ', '');\n return collector.command(command, data, options);\n }\n\n // Build event object\n let event: WalkerOS.DeepPartialEvent;\n\n if (typeof eventOrCommand === 'string') {\n // Convert string to object: elb('page view', { title: 'Home' })\n event = { name: eventOrCommand };\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = data as WalkerOS.Properties;\n }\n } else if (eventOrCommand && typeof eventOrCommand === 'object') {\n // Use object directly: elb({ name: 'page view', data: {...} })\n event = eventOrCommand as WalkerOS.DeepPartialEvent;\n // Merge additional data if provided\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = {\n ...(event.data || {}),\n ...(data as WalkerOS.Properties),\n };\n }\n } else {\n // Invalid input\n return createPushResult({ ok: false });\n }\n\n // Add optional properties if provided\n if (context && typeof context === 'object') {\n event.context = context as WalkerOS.OrderedProperties;\n }\n if (nested && Array.isArray(nested)) {\n event.nested = nested;\n }\n if (custom && typeof custom === 'object') {\n event.custom = custom as WalkerOS.Properties;\n }\n\n // Call collector.push with event object\n return collector.push(event);\n },\n };\n}\n","import type { Collector, Source, WalkerOS } from '@walkeros/core';\nimport { getMappingValue, tryCatchAsync } from '@walkeros/core';\nimport { walkChain } from './transformer';\n\n/**\n * Extracts a simple {id: {next}} map from transformer instances.\n * Used for chain resolution.\n */\nfunction extractTransformerNextMap(\n transformers: Record<string, { config: { next?: string } }>,\n): Record<string, { next?: string }> {\n const result: Record<string, { next?: string }> = {};\n for (const [id, transformer] of Object.entries(transformers)) {\n result[id] = { next: transformer.config.next };\n }\n return result;\n}\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 * @returns Initialized sources\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, next } = sourceDefinition;\n\n // Track current ingest metadata (set per-request by setIngest)\n let currentIngest: unknown = undefined;\n\n // Resolve transformer chain for this source\n const preChain = walkChain(\n next,\n extractTransformerNextMap(collector.transformers),\n );\n\n // Create wrapped push that auto-applies source mapping config, preChain, and ingest\n const wrappedPush: Collector.PushFn = (\n event: WalkerOS.DeepPartialEvent,\n options: Collector.PushOptions = {},\n ) => {\n // Pass source config as mapping in options, plus resolved preChain, source id, and ingest\n return collector.push(event, {\n ...options,\n id: sourceId,\n ingest: currentIngest,\n mapping: config,\n preChain, // Source-specific transformer chain\n });\n };\n\n // Create initial logger scoped to sourceId (type will be added after init)\n const initialLogger = collector.logger.scope('source').scope(sourceId);\n\n const cleanEnv: Source.Env = {\n push: wrappedPush,\n command: collector.command,\n sources: collector.sources, // Provide access to all sources for chaining\n elb: collector.sources.elb.push, // ELB source is always available\n logger: initialLogger,\n ...env,\n };\n\n /**\n * setIngest extracts metadata from raw request using config.ingest mapping.\n * Opt-in: returns early if no config.ingest is defined.\n */\n const setIngest = async (value: unknown): Promise<void> => {\n // Opt-in barrier: no processing when ingest not configured\n if (!config.ingest) {\n currentIngest = undefined;\n return;\n }\n\n currentIngest = await getMappingValue(value, config.ingest, {\n collector,\n });\n };\n\n // Build source context for init\n const sourceContext: Source.Context = {\n collector,\n logger: initialLogger,\n id: sourceId,\n config,\n env: cleanEnv,\n setIngest,\n };\n\n // Call source function with context\n const sourceInstance = await tryCatchAsync(code)(sourceContext);\n\n if (!sourceInstance) continue; // Skip failed source initialization\n\n // Update logger with actual source type: [type:sourceId] or [unknown:sourceId]\n const sourceType = sourceInstance.type || 'unknown';\n const sourceLogger = collector.logger.scope(sourceType).scope(sourceId);\n cleanEnv.logger = sourceLogger;\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, Elb } from '@walkeros/core';\nimport type { StartFlow } from './types';\nimport { collector } from './collector';\nimport { createElbSource } from './elb';\nimport { initSources } from './source';\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\n // Create and register ELB source first\n const elbSource = createElbSource(instance);\n instance.sources.elb = elbSource;\n\n // Now initialize other sources with ELB source available\n const additionalSources = await initSources(\n instance,\n initConfig.sources || {},\n );\n Object.assign(instance.sources, additionalSources);\n\n const { consent, user, globals, custom } = initConfig;\n\n if (consent) await instance.command('consent', consent);\n if (user) await instance.command('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.command('run');\n\n // Determine the primary elb:\n // 1. Use explicitly marked primary source\n // 2. Use first non-elb source if any exist\n // 3. Fallback to ELB source\n let primaryElb: Elb.Fn = elbSource.push as Elb.Fn;\n\n const sources = Object.values(instance.sources).filter(\n (source) => source.type !== 'elb',\n );\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 as Elb.Fn;\n } else if (sources.length > 0) {\n // Use first source as default\n primaryElb = sources[0].push as Elb.Fn;\n }\n\n return {\n collector: instance,\n elb: primaryElb as ElbPush,\n };\n}\n"],"mappings":";AAAA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OAAM,SAAS,QAAQ,WAAW,OAAO;AACtD,MAAI,KAAM,OAAM,SAAS,QAAQ,QAAQ,IAAI;AAC7C,MAAI,QAAS,QAAO,OAAO,SAAS,SAAS,OAAO;AACpD,MAAI,OAAQ,QAAO,OAAO,SAAS,QAAQ,MAAM;AAEjD,MAAI,SAAS,OAAO,IAAK,OAAM,SAAS,QAAQ,KAAK;AAMrD,MAAI,aAAqB,UAAU;AAEnC,QAAM,UAAU,OAAO,OAAO,SAAS,OAAO,EAAE;AAAA,IAC9C,CAAC,WAAW,OAAO,SAAS;AAAA,EAC9B;AAGA,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":["assign","isObject","tryCatchAsync","useHooks","collector","initTransformers","collector","event","tryCatchAsync","useHooks","batchState","isObject","collector","on","option","collector","assign","assign","assign","getId","isObject","collector","isObject","assign","getId","getGrantedConsent","processEventMapping","tryCatchAsync","useHooks","collector","useHooks","tryCatchAsync","processEventMapping","getGrantedConsent","useHooks","tryCatchAsync","collector","useHooks","tryCatchAsync","assign","collector","collector","tryCatchAsync","collector","tryCatchAsync"]}
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.5.1-next.0",
4
+ "version": "0.7.0",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
@@ -25,12 +25,12 @@
25
25
  "build": "tsup --silent",
26
26
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
27
27
  "dev": "jest --watchAll --colors",
28
- "lint": "tsc && eslint \"**/*.ts*\"",
28
+ "lint": "tsc --noEmit && eslint \"**/*.ts*\"",
29
29
  "test": "jest",
30
30
  "update": "npx npm-check-updates -u && npm update"
31
31
  },
32
32
  "dependencies": {
33
- "@walkeros/core": "0.5.1-next.0"
33
+ "@walkeros/core": "0.7.0"
34
34
  },
35
35
  "devDependencies": {},
36
36
  "repository": {