@walkeros/collector 0.0.7 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,56 +1,47 @@
1
1
  <p align="left">
2
2
  <a href="https://elbwalker.com">
3
- <img title="elbwalker" src='https://www.elbwalker.com/img/elbwalker_logo.png' width="256px"/>
3
+ <img title="elbwalker" src="https://www.elbwalker.com/img/elbwalker_logo.png" width="256px"/>
4
4
  </a>
5
5
  </p>
6
6
 
7
7
  # Collector for walkerOS
8
8
 
9
- The walkerOS Collector is the central event processing engine that unifies data
10
- collection across web and server environments. It acts as the orchestrator
11
- between sources (where events originate) and destinations (where events are
12
- sent), providing consistent event processing, consent management, and data
13
- validation across your entire data collection infrastructure.
9
+ [Source Code](https://github.com/elbwalker/walkerOS/tree/main/packages/collector)
10
+ &bull; [NPM Package](https://www.npmjs.com/package/@walkeros/collector)
14
11
 
15
- ## Role in walkerOS Ecosystem
12
+ The collector is the central **processing engine** of walkerOS that receives
13
+ events from sources, **enriches** them with additional data, applies consent
14
+ rules, and **routes** them to destinations. It acts as the **intelligent
15
+ middleware** between event capture and event delivery.
16
16
 
17
- walkerOS follows a **source → collector → destination** architecture:
17
+ ### What it does
18
18
 
19
- - **Sources**: Capture events from various environments (browser DOM, dataLayer,
20
- server requests)
21
- - **Collector**: Processes, validates, and routes events with consent awareness
22
- - **Destinations**: Send processed events to analytics platforms (GA4, Meta,
23
- custom APIs)
19
+ The Collector transforms raw events into enriched, compliant data streams by:
24
20
 
25
- The Collector serves as the foundation that both web and server sources depend
26
- on, ensuring consistent event handling regardless of the environment.
21
+ - **Event processing** - Validates, normalizes, and enriches incoming events
22
+ - **Consent management** - Applies privacy rules and user consent preferences
23
+ - **Data enrichment** - Adds session data, user context, and custom properties
24
+ - **Destination routing** - Sends processed events to configured analytics
25
+ platforms
27
26
 
28
- ## Installation
29
-
30
- ```sh
31
- npm install @walkeros/collector
32
- ```
33
-
34
- ## Usage
27
+ ### Key features
35
28
 
36
- The collector provides a factory function for creating collector instances:
29
+ - **Compatibility** - Works in both web browsers and server environments
30
+ - **Privacy-first** - Built-in consent management and data protection
31
+ - **Event validation** - Ensures data quality and consistency
32
+ - **Flexible routing** - Send events to multiple destinations simultaneously
37
33
 
38
- ```typescript
39
- import { createCollector } from '@walkeros/collector';
34
+ ### Role in architecture
40
35
 
41
- // Basic setup
42
- const { collector, elb } = await createCollector({
43
- consent: { functional: true },
44
- destinations: [
45
- // Add your destinations here
46
- ],
47
- });
36
+ In the walkerOS data flow, the collector sits between sources and destinations:
48
37
 
49
- // Process events - use elb as the standard API
50
- await elb('page view', {
51
- page: '/home',
52
- });
53
38
  ```
39
+ Sources → Collector → Destinations
40
+ ```
41
+
42
+ Sources capture events and send them to the collector, which processes and
43
+ routes them to your chosen destinations like Google Analytics, custom APIs, or
44
+ data warehouses.
54
45
 
55
46
  ## Event Naming Convention
56
47
 
@@ -78,15 +69,66 @@ The collector will validate event names and destinations handle
78
69
  platform-specific transformations. If the event name isn't separated into entity
79
70
  action by space the collector won't process it.
80
71
 
81
- ## Core Features
72
+ ## Installation
73
+
74
+ ```bash
75
+ npm install @walkeros/collector
76
+ ```
77
+
78
+ ## Setup
79
+
80
+ ### Basic setup
81
+
82
+ ```typescript
83
+ import { createCollector } from '@walkeros/collector';
84
+
85
+ const config = {
86
+ run: true,
87
+ consent: { functional: true },
88
+ sources: [
89
+ // add your event sources
90
+ ]
91
+ },
92
+ };
93
+
94
+ const { collector, elb } = await createCollector(config);
95
+ ```
96
+
97
+ ### Advanced setup
98
+
99
+ ```typescript
100
+ import { createCollector } from '@walkeros/collector';
101
+
102
+ const { collector, elb } = await createCollector({
103
+ run: true,
104
+ consent: { functional: true },
105
+ sources: [
106
+ // add your event sources
107
+ ],
108
+ destinations: [
109
+ // add your event destinations
110
+ ],
111
+ verbose: true,
112
+ onError: (error: unknown) => {
113
+ console.error('Collector error:', error);
114
+ },
115
+ onLog: (message: string, level: 'debug' | 'info' | 'warn' | 'error') => {
116
+ console.log(`[${level}] ${message}`);
117
+ },
118
+ });
119
+ ```
82
120
 
83
- - **Event Processing**: Validates and enriches events with context and metadata
84
- - **Consent Management**: Respects user consent preferences across all
85
- destinations
86
- - **Destination Routing**: Translates and routes events to configured
87
- destinations
88
- - **State Management**: Maintains consistent state across the collection
89
- pipeline
121
+ ## Configuration
122
+
123
+ | Name | Type | Description | Required | Example |
124
+ | -------------- | ---------- | -------------------------------------------------------------- | -------- | ------------------------------------------ |
125
+ | `run` | `boolean` | Automatically start the collector pipeline on initialization | No | `true` |
126
+ | `sources` | `array` | Configurations for sources providing events to the collector | No | `[{ source, config }]` |
127
+ | `destinations` | `array` | Configurations for destinations receiving processed events | No | `[{ destination, config }]` |
128
+ | `consent` | `object` | Initial consent state to control routing of events | No | `{ analytics: true, marketing: false }` |
129
+ | `verbose` | `boolean` | Enable verbose logging for debugging | No | `false` |
130
+ | `onError` | `function` | Error handler triggered when the collector encounters failures | No | `(error) => console.error(error)` |
131
+ | `onLog` | `function` | Custom log handler for collector messages | No | `(message, level) => console.log(message)` |
90
132
 
91
133
  ## Contribute
92
134
 
package/dist/index.d.mts CHANGED
@@ -10,12 +10,8 @@ import { Source, WalkerOS, Collector, Elb, Destination, On } from '@walkeros/cor
10
10
  * @returns Promise resolving to the created source with its elb function
11
11
  */
12
12
  declare function createSource<T extends Source.Config, E = WalkerOS.AnyFunction>(collector: Collector.Instance, source: Source.Init<T, E>, config: Source.InitConfig): Promise<Source.CreateSource<T, E>>;
13
- interface SourceInit<T extends Source.Config = Source.Config, E = WalkerOS.AnyFunction> {
14
- code: Source.Init<T, E>;
15
- config?: Partial<T>;
16
- }
17
13
  interface InitSources {
18
- [sourceId: string]: SourceInit<any, any>;
14
+ [sourceId: string]: Source.Init<any, any>;
19
15
  }
20
16
  /**
21
17
  * Initialize multiple sources for a collector
@@ -40,7 +36,7 @@ interface CollectorConfig extends Collector.Config {
40
36
  sources?: InitSources;
41
37
  }
42
38
 
43
- type CommandTypes = 'Action' | 'Config' | 'Consent' | 'Context' | 'Custom' | 'Destination' | 'Elb' | 'Globals' | 'Hook' | 'Init' | 'Link' | 'On' | 'Prefix' | 'Ready' | 'Run' | 'Session' | 'User' | 'Walker';
39
+ type CommandTypes = 'Action' | 'Actions' | 'Config' | 'Consent' | 'Context' | 'Custom' | 'Destination' | 'Elb' | 'Globals' | 'Hook' | 'Init' | 'Link' | 'On' | 'Prefix' | 'Ready' | 'Run' | 'Session' | 'User' | 'Walker';
44
40
  declare const Commands: Record<CommandTypes, Collector.CommandType>;
45
41
  type StorageType = 'cookie' | 'local' | 'session';
46
42
  declare const Const: {
@@ -176,4 +172,4 @@ declare function on(collector: Collector.Instance, type: On.Types, option: Walke
176
172
  */
177
173
  declare function onApply(collector: Collector.Instance, type: On.Types, options?: Array<On.Options>, config?: WalkerOS.Consent): void;
178
174
 
179
- export { type CollectorConfig, type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type InitSource, type InitSources, type RunState, type SourceInit, type StorageType, addDestination, commonHandleCommand, createCollector, createEventOrCommand, createPush, createPushResult, createSource, destinationInit, destinationPush, initDestinations, initSources, on, onApply, pushToDestinations, runCollector, setConsent };
175
+ export { type CollectorConfig, type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type InitSource, type InitSources, type RunState, type StorageType, addDestination, commonHandleCommand, createCollector, createEventOrCommand, createPush, createPushResult, createSource, destinationInit, destinationPush, initDestinations, initSources, on, onApply, pushToDestinations, runCollector, setConsent };
package/dist/index.d.ts CHANGED
@@ -10,12 +10,8 @@ import { Source, WalkerOS, Collector, Elb, Destination, On } from '@walkeros/cor
10
10
  * @returns Promise resolving to the created source with its elb function
11
11
  */
12
12
  declare function createSource<T extends Source.Config, E = WalkerOS.AnyFunction>(collector: Collector.Instance, source: Source.Init<T, E>, config: Source.InitConfig): Promise<Source.CreateSource<T, E>>;
13
- interface SourceInit<T extends Source.Config = Source.Config, E = WalkerOS.AnyFunction> {
14
- code: Source.Init<T, E>;
15
- config?: Partial<T>;
16
- }
17
13
  interface InitSources {
18
- [sourceId: string]: SourceInit<any, any>;
14
+ [sourceId: string]: Source.Init<any, any>;
19
15
  }
20
16
  /**
21
17
  * Initialize multiple sources for a collector
@@ -40,7 +36,7 @@ interface CollectorConfig extends Collector.Config {
40
36
  sources?: InitSources;
41
37
  }
42
38
 
43
- type CommandTypes = 'Action' | 'Config' | 'Consent' | 'Context' | 'Custom' | 'Destination' | 'Elb' | 'Globals' | 'Hook' | 'Init' | 'Link' | 'On' | 'Prefix' | 'Ready' | 'Run' | 'Session' | 'User' | 'Walker';
39
+ type CommandTypes = 'Action' | 'Actions' | 'Config' | 'Consent' | 'Context' | 'Custom' | 'Destination' | 'Elb' | 'Globals' | 'Hook' | 'Init' | 'Link' | 'On' | 'Prefix' | 'Ready' | 'Run' | 'Session' | 'User' | 'Walker';
44
40
  declare const Commands: Record<CommandTypes, Collector.CommandType>;
45
41
  type StorageType = 'cookie' | 'local' | 'session';
46
42
  declare const Const: {
@@ -176,4 +172,4 @@ declare function on(collector: Collector.Instance, type: On.Types, option: Walke
176
172
  */
177
173
  declare function onApply(collector: Collector.Instance, type: On.Types, options?: Array<On.Options>, config?: WalkerOS.Consent): void;
178
174
 
179
- export { type CollectorConfig, type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type InitSource, type InitSources, type RunState, type SourceInit, type StorageType, addDestination, commonHandleCommand, createCollector, createEventOrCommand, createPush, createPushResult, createSource, destinationInit, destinationPush, initDestinations, initSources, on, onApply, pushToDestinations, runCollector, setConsent };
175
+ export { type CollectorConfig, type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type InitSource, type InitSources, type RunState, type StorageType, addDestination, commonHandleCommand, createCollector, createEventOrCommand, createPush, createPushResult, createSource, destinationInit, destinationPush, initDestinations, initSources, on, onApply, pushToDestinations, runCollector, setConsent };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t,n=Object.defineProperty,s=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,a=(e={"package.json"(e,t){t.exports={name:"@walkeros/collector",description:"Unified platform-agnostic collector for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{"@walkeros/core":"0.0.7"},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/collector"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","collector","event processing"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return t||(0,e[o(e)[0]])((t={exports:{}}).exports,t),t.exports}),r={};((e,t)=>{for(var s in t)n(e,s,{get:t[s],enumerable:!0})})(r,{Commands:()=>c,Const:()=>u,addDestination:()=>C,commonHandleCommand:()=>w,createCollector:()=>H,createEventOrCommand:()=>k,createPush:()=>v,createPushResult:()=>E,createSource:()=>A,destinationInit:()=>q,destinationPush:()=>j,initDestinations:()=>S,initSources:()=>M,on:()=>b,onApply:()=>h,pushToDestinations:()=>O,runCollector:()=>y,setConsent:()=>x}),module.exports=(e=>((e,t,a,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of o(t))i.call(e,c)||c===a||n(e,c,{get:()=>t[c],enumerable:!(r=s(t,c))||r.enumerable});return e})(n({},"__esModule",{value:!0}),e))(r);var c={Action:"action",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},u={Commands:c,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},l=require("@walkeros/core"),d=require("@walkeros/core"),g=require("@walkeros/core"),p=require("@walkeros/core"),f=require("@walkeros/core"),m=require("@walkeros/core");function b(e,t,n){const s=e.on,o=s[t]||[],i=(0,f.isArray)(n)?n:[n];i.forEach(e=>{o.push(e)}),s[t]=o,h(e,t,i)}function h(e,t,n,s){let o=n||[];if(n||(o=e.on[t]||[],Object.values(e.destinations).forEach(e=>{const n=e.config.on?.[t];n&&(o=o.concat(n))})),o.length)switch(t){case u.Commands.Consent:!function(e,t,n){const s=n||e.consent;t.forEach(t=>{Object.keys(s).filter(e=>e in t).forEach(n=>{(0,m.tryCatch)(t[n])(e,s)})})}(e,o,s);break;case u.Commands.Ready:case u.Commands.Run:!function(e,t){e.allowed&&t.forEach(t=>{(0,m.tryCatch)(t)(e)})}(e,o);break;case u.Commands.Session:!function(e,t){if(!e.session)return;t.forEach(t=>{(0,m.tryCatch)(t)(e,e.session)})}(e,o)}}async function w(e,t,n,s){let o;switch(t){case u.Commands.Config:(0,p.isObject)(n)&&(0,g.assign)(e.config,n,{shallow:!1});break;case u.Commands.Consent:(0,p.isObject)(n)&&(o=await x(e,n));break;case u.Commands.Custom:(0,p.isObject)(n)&&(e.custom=(0,g.assign)(e.custom,n));break;case u.Commands.Destination:(0,p.isObject)(n)&&(0,g.isFunction)(n.push)&&(o=await C(e,n,s));break;case u.Commands.Globals:(0,p.isObject)(n)&&(e.globals=(0,g.assign)(e.globals,n));break;case u.Commands.On:(0,g.isString)(n)&&b(e,n,s);break;case u.Commands.Run:o=await y(e,n);break;case u.Commands.User:(0,p.isObject)(n)&&(0,g.assign)(e.user,n,{shallow:!1})}return o||{ok:!0,successful:[],queued:[],failed:[]}}function k(e,t,n={}){const s=(0,p.isSameType)(t,"")?{event:t,...n}:{...n,...t||{}};if(!s.event)throw new Error("Event name is required");const[o,i]=s.event.split(" ");if(!o||!i)throw new Error("Event name is invalid");if(o===c.Walker)return{command:i};++e.count;const{timestamp:a=Date.now(),group:r=e.group,count:u=e.count}=s,{event:l=`${o} ${i}`,data:d={},context:g={},globals:f=e.globals,custom:m={},user:b=e.user,nested:h=[],consent:w=e.consent,id:k=`${a}-${r}-${u}`,trigger:y="",entity:v=o,action:C=i,timing:O=0,version:q={source:e.version,tagging:e.config.tagging||0},source:j={type:"collector",id:"",previous_id:""}}=s;return{event:{event:l,data:d,context:g,globals:f,custom:m,user:b,nested:h,consent:w,id:k,trigger:y,entity:v,action:C,timestamp:a,timing:O,group:r,count:u,version:q,source:j}}}async function y(e,t){e.allowed=!0,e.count=0,e.group=(0,g.getId)(),e.timing=Date.now(),t&&(t.consent&&(e.consent=(0,g.assign)(e.consent,t.consent)),t.user&&(e.user=(0,g.assign)(e.user,t.user)),t.globals&&(e.globals=(0,g.assign)(e.config.globalsStatic||{},t.globals)),t.custom&&(e.custom=(0,g.assign)(e.custom,t.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.round++,h(e,"run");return await O(e)}function v(e,t,n){return(0,d.useHooks)(async(s,o,i)=>await(0,d.tryCatchAsync)(async()=>{if("string"==typeof s&&s.startsWith("walker ")){const n=s.replace("walker ","");return await t(e,n,o,i)}{const a=n("string"==typeof s?{event:s}:s),{event:r,command:c}=k(e,a.event,a);return c?await t(e,c,o,i):await O(e,r)}},()=>E({ok:!1}))(),"Push",e.hooks)}async function C(e,t,n){const s=n||t.config||{init:!1},o={...t,config:s};let i=s.id;if(!i)do{i=(0,d.getId)(4)}while(e.destinations[i]);return e.destinations[i]=o,!1!==s.queue&&(o.queue=[...e.queue]),O(e,void 0,{[i]:o})}async function O(e,t,n){const{allowed:s,consent:o,globals:i,user:a}=e;if(!s)return E({ok:!1});t&&e.queue.push(t),n||(n=e.destinations);const r=await Promise.all(Object.entries(n||{}).map(async([n,s])=>{let r=(s.queue||[]).map(e=>({...e,consent:o}));if(s.queue=[],t){let n=(0,d.clone)(t);await Promise.all(Object.entries(s.config.policy||[]).map(async([s,o])=>{const i=await(0,d.getMappingValue)(t,o,{collector:e});n=(0,d.setByPath)(n,s,i)})),r.push(n)}if(!r.length)return{id:n,destination:s,skipped:!0};const c=[],u=r.filter(e=>{const t=(0,d.getGrantedConsent)(s.config.consent,o,e.consent);return!t||(e.consent=t,c.push(e),!1)});if(s.queue.concat(u),!c.length)return{id:n,destination:s,queue:r};if(!await(0,d.tryCatchAsync)(q)(e,s))return{id:n,destination:s,queue:r};let l=!1;return s.dlq||(s.dlq=[]),await Promise.all(c.map(async t=>(t.globals=(0,d.assign)(i,t.globals),t.user=(0,d.assign)(a,t.user),await(0,d.tryCatchAsync)(j,n=>(e.config.onError&&e.config.onError(n,e),l=!0,s.dlq.push([t,n]),!1))(e,s,t),t))),{id:n,destination:s,error:l}})),c=[],u=[],l=[];for(const e of r){if(e.skipped)continue;const t=e.destination,n={id:e.id,destination:t};e.error?l.push(n):e.queue&&e.queue.length?(t.queue=(t.queue||[]).concat(e.queue),u.push(n)):c.push(n)}return E({ok:!l.length,event:t,successful:c,queued:u,failed:l})}async function q(e,t){if(t.init&&!t.config.init){const n={collector:e,config:t.config,wrap:D(t,e)},s=await(0,d.useHooks)(t.init,"DestinationInit",e.hooks)(n);if(!1===s)return s;t.config={...s||t.config,init:!0}}return!0}async function j(e,t,n){const{config:s}=t,{eventMapping:o,mappingKey:i}=await(0,d.getMappingEvent)(n,s.mapping);let a=s.data&&await(0,d.getMappingValue)(n,s.data,{collector:e});if(o){if(o.ignore)return!1;if(o.name&&(n.event=o.name),o.data){const t=o.data&&await(0,d.getMappingValue)(n,o.data,{collector:e});a=(0,d.isObject)(a)&&(0,d.isObject)(t)?(0,d.assign)(a,t):t}}const r={collector:e,config:s,data:a,mapping:o,wrap:D(t,e)};if(o?.batch&&t.pushBatch){const r=o.batched||{key:i||"",events:[],data:[]};r.events.push(n),(0,d.isDefined)(a)&&r.data.push(a),o.batchFn=o.batchFn||(0,d.debounce)((e,t)=>{const n={collector:t,config:s,data:a,mapping:o,wrap:D(e,t)};(0,d.useHooks)(e.pushBatch,"DestinationPushBatch",t.hooks)(r,n),r.events=[],r.data=[]},o.batch),o.batched=r,o.batchFn?.(t,e)}else await(0,d.useHooks)(t.push,"DestinationPush",e.hooks)(n,r);return!0}function E(e){return(0,d.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}function S(e){return Object.entries(e).reduce((e,[t,n])=>(e[t]={...n,config:(0,d.isObject)(n.config)?n.config:{}},e),{})}function D(e,t){const n=e.config.wrapper||{},s=e.config.dryRun??t?.config.dryRun;return(0,d.createWrapper)(e.type||"unknown",{...n,...(0,d.isDefined)(s)&&{dryRun:s}})}async function x(e,t){const{consent:n}=e;let s=!1;const o={};return Object.entries(t).forEach(([e,t])=>{const n=!!t;o[e]=n,s=s||n}),e.consent=(0,l.assign)(n,o),h(e,"consent",void 0,o),s?O(e):E({ok:!0})}var P=require("@walkeros/core"),R=require("@walkeros/core");async function A(e,t,n){const s={disabled:n.disabled??!1,settings:n.settings??{},onError:n.onError};if(s.disabled)return{};const o=await(0,R.tryCatchAsync)(t)(e,s);if(!o||!o.source)return{};const i=s.type||o.source.type||"",a=n.id||`${i}_${(0,R.getId)(5)}`;if(o.source&&o.elb){o.source.elb=o.elb}return e.sources[a]={type:i,settings:s.settings,mapping:void 0,elb:o.elb},o}async function M(e,t={}){for(const[n,s]of Object.entries(t)){const{code:t,config:o={}}=s,i={id:n,...o},a=await A(e,t,i);if(a.source){if(a.elb){a.source.elb=a.elb}e.sources[n]={type:a.source.type,settings:a.source.config.settings,mapping:void 0,elb:a.elb}}}}async function H(e={}){const t=function(e){const{version:t}=a(),n={dryRun:!1,globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0,destinations:{},consent:{},user:{},globals:{},custom:{}},s=(0,P.assign)(n,e,{merge:!1,extend:!1});function o(e,t){(0,P.onLog)({message:e},t||s.verbose)}s.onLog=o;const i={...s.globalsStatic,...s.globals},r={allowed:!1,config:s,consent:s.consent||{},count:0,custom:s.custom||{},destinations:S(s.destinations||{}),globals:i,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:s.user||{},version:t,sources:{},push:void 0};return r.push=v(r,w,e=>({timing:Math.round((Date.now()-r.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),r}(e),{consent:n,user:s,globals:o,custom:i,sources:r}=e;return n&&await t.push("walker consent",n),s&&await t.push("walker user",s),o&&Object.assign(t.globals,o),i&&Object.assign(t.custom,i),r&&await M(t,r),t.config.run&&await t.push("walker run"),{collector:t,elb:t.push}}//# sourceMappingURL=index.js.map
1
+ "use strict";var e,n,t=Object.defineProperty,s=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,a=(e={"package.json"(e,n){n.exports={name:"@walkeros/collector",description:"Unified platform-agnostic collector for walkerOS",version:"0.1.0",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{"@walkeros/core":"0.1.0"},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/collector"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","collector","event processing"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return n||(0,e[o(e)[0]])((n={exports:{}}).exports,n),n.exports}),c={};((e,n)=>{for(var s in n)t(e,s,{get:n[s],enumerable:!0})})(c,{Commands:()=>r,Const:()=>u,addDestination:()=>C,commonHandleCommand:()=>w,createCollector:()=>I,createEventOrCommand:()=>k,createPush:()=>v,createPushResult:()=>E,createSource:()=>M,destinationInit:()=>q,destinationPush:()=>j,initDestinations:()=>S,initSources:()=>H,on:()=>b,onApply:()=>h,pushToDestinations:()=>O,runCollector:()=>y,setConsent:()=>D}),module.exports=(e=>((e,n,a,c)=>{if(n&&"object"==typeof n||"function"==typeof n)for(let r of o(n))i.call(e,r)||r===a||t(e,r,{get:()=>n[r],enumerable:!(c=s(n,r))||c.enumerable});return e})(t({},"__esModule",{value:!0}),e))(c);var r={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},u={Commands:r,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},l=require("@walkeros/core"),d=require("@walkeros/core"),g=require("@walkeros/core"),f=require("@walkeros/core"),m=require("@walkeros/core"),p=require("@walkeros/core");function b(e,n,t){const s=e.on,o=s[n]||[],i=(0,m.isArray)(t)?t:[t];i.forEach(e=>{o.push(e)}),s[n]=o,h(e,n,i)}function h(e,n,t,s){let o=t||[];if(t||(o=e.on[n]||[],Object.values(e.destinations).forEach(e=>{const t=e.config.on?.[n];t&&(o=o.concat(t))})),o.length)switch(n){case u.Commands.Consent:!function(e,n,t){const s=t||e.consent;n.forEach(n=>{Object.keys(s).filter(e=>e in n).forEach(t=>{(0,p.tryCatch)(n[t])(e,s)})})}(e,o,s);break;case u.Commands.Ready:case u.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,p.tryCatch)(n)(e)})}(e,o);break;case u.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,p.tryCatch)(n)(e,e.session)})}(e,o)}}async function w(e,n,t,s){let o;switch(n){case u.Commands.Config:(0,f.isObject)(t)&&(0,g.assign)(e.config,t,{shallow:!1});break;case u.Commands.Consent:(0,f.isObject)(t)&&(o=await D(e,t));break;case u.Commands.Custom:(0,f.isObject)(t)&&(e.custom=(0,g.assign)(e.custom,t));break;case u.Commands.Destination:(0,f.isObject)(t)&&(0,g.isFunction)(t.push)&&(o=await C(e,t,s));break;case u.Commands.Globals:(0,f.isObject)(t)&&(e.globals=(0,g.assign)(e.globals,t));break;case u.Commands.On:(0,g.isString)(t)&&b(e,t,s);break;case u.Commands.Run:o=await y(e,t);break;case u.Commands.User:(0,f.isObject)(t)&&(0,g.assign)(e.user,t,{shallow:!1})}return o||{ok:!0,successful:[],queued:[],failed:[]}}function k(e,n,t={}){const s=(0,f.isSameType)(n,"")?{name:n,...t}:{...t,...n||{}};if(!s.name)throw new Error("Event name is required");const[o,i]=s.name.split(" ");if(!o||!i)throw new Error("Event name is invalid");if(o===r.Walker)return{command:i};++e.count;const{timestamp:a=Date.now(),group:c=e.group,count:u=e.count}=s,{name:l=`${o} ${i}`,data:d={},context:g={},globals:m=e.globals,custom:p={},user:b=e.user,nested:h=[],consent:w=e.consent,id:k=`${a}-${c}-${u}`,trigger:y="",entity:v=o,action:C=i,timing:O=0,version:q={source:e.version,tagging:e.config.tagging||0},source:j={type:"collector",id:"",previous_id:""}}=s;return{event:{name:l,data:d,context:g,globals:m,custom:p,user:b,nested:h,consent:w,id:k,trigger:y,entity:v,action:C,timestamp:a,timing:O,group:c,count:u,version:q,source:j}}}async function y(e,n){e.allowed=!0,e.count=0,e.group=(0,g.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,g.assign)(e.consent,n.consent)),n.user&&(e.user=(0,g.assign)(e.user,n.user)),n.globals&&(e.globals=(0,g.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,g.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await O(e);return h(e,"run"),t}function v(e,n,t){return(0,d.useHooks)(async(s,o,i)=>await(0,d.tryCatchAsync)(async()=>{if("string"==typeof s&&s.startsWith("walker ")){const t=s.replace("walker ","");return await n(e,t,o,i)}{const a=t("string"==typeof s?{name:s}:s),{event:c,command:r}=k(e,a.name,a);return r?await n(e,r,o,i):await O(e,c)}},()=>E({ok:!1}))(),"Push",e.hooks)}async function C(e,n,t){const s=t||n.config||{init:!1},o={...n,config:s};let i=s.id;if(!i)do{i=(0,d.getId)(4)}while(e.destinations[i]);return e.destinations[i]=o,!1!==s.queue&&(o.queue=[...e.queue]),O(e,void 0,{[i]:o})}async function O(e,n,t){const{allowed:s,consent:o,globals:i,user:a}=e;if(!s)return E({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const c=await Promise.all(Object.entries(t||{}).map(async([t,s])=>{let c=(s.queue||[]).map(e=>({...e,consent:o}));if(s.queue=[],n){let t=(0,d.clone)(n);await Promise.all(Object.entries(s.config.policy||[]).map(async([s,o])=>{const i=await(0,d.getMappingValue)(n,o,{collector:e});t=(0,d.setByPath)(t,s,i)})),c.push(t)}if(!c.length)return{id:t,destination:s,skipped:!0};const r=[],u=c.filter(e=>{const n=(0,d.getGrantedConsent)(s.config.consent,o,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(s.queue.concat(u),!r.length)return{id:t,destination:s,queue:c};if(!await(0,d.tryCatchAsync)(q)(e,s))return{id:t,destination:s,queue:c};let l=!1;return s.dlq||(s.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,d.assign)(i,n.globals),n.user=(0,d.assign)(a,n.user),await(0,d.tryCatchAsync)(j,t=>(e.config.onError&&e.config.onError(t,e),l=!0,s.dlq.push([n,t]),!1))(e,s,n),n))),{id:t,destination:s,error:l}})),r=[],u=[],l=[];for(const e of c){if(e.skipped)continue;const n=e.destination,t={id:e.id,destination:n};e.error?l.push(t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),u.push(t)):r.push(t)}return E({ok:!l.length,event:n,successful:r,queued:u,failed:l})}async function q(e,n){if(n.init&&!n.config.init){const t={collector:e,config:n.config,env:x(n.env,n.config.env)},s=await(0,d.useHooks)(n.init,"DestinationInit",e.hooks)(t);if(!1===s)return s;n.config={...s||n.config,init:!0}}return!0}async function j(e,n,t){const{config:s}=n,{eventMapping:o,mappingKey:i}=await(0,d.getMappingEvent)(t,s.mapping);let a=s.data&&await(0,d.getMappingValue)(t,s.data,{collector:e});if(o){if(o.ignore)return!1;if(o.name&&(t.name=o.name),o.data){const n=o.data&&await(0,d.getMappingValue)(t,o.data,{collector:e});a=(0,d.isObject)(a)&&(0,d.isObject)(n)?(0,d.assign)(a,n):n}}const c={collector:e,config:s,data:a,mapping:o,env:x(n.env,s.env)};if(o?.batch&&n.pushBatch){const c=o.batched||{key:i||"",events:[],data:[]};c.events.push(t),(0,d.isDefined)(a)&&c.data.push(a),o.batchFn=o.batchFn||(0,d.debounce)((e,n)=>{const t={collector:n,config:s,data:a,mapping:o,env:x(e.env,s.env)};(0,d.useHooks)(e.pushBatch,"DestinationPushBatch",n.hooks)(c,t),c.events=[],c.data=[]},o.batch),o.batched=c,o.batchFn?.(n,e)}else await(0,d.useHooks)(n.push,"DestinationPush",e.hooks)(t,c);return!0}function E(e){return(0,d.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}function S(e){return Object.entries(e).reduce((e,[n,t])=>(e[n]={...t,config:(0,d.isObject)(t.config)?t.config:{}},e),{})}function x(e,n){return e||n?n?e&&(0,d.isObject)(e)&&(0,d.isObject)(n)?{...e,...n}:n:e:{}}async function D(e,n){const{consent:t}=e;let s=!1;const o={};return Object.entries(n).forEach(([e,n])=>{const t=!!n;o[e]=t,s=s||t}),e.consent=(0,l.assign)(t,o),h(e,"consent",void 0,o),s?O(e):E({ok:!0})}var P=require("@walkeros/core"),A=require("@walkeros/core");async function M(e,n,t){const s={disabled:t.disabled??!1,settings:t.settings??{},onError:t.onError};if(s.disabled)return{};const o=await(0,A.tryCatchAsync)(n)(e,s);if(!o||!o.source)return{};const i=s.type||o.source.type||"",a=t.id||`${i}_${(0,A.getId)(5)}`;if(o.source&&o.elb){o.source.elb=o.elb}return e.sources||(e.sources={}),e.sources[a]={type:i,settings:s.settings,mapping:void 0,elb:o.elb},o}async function H(e,n={}){for(const[t,s]of Object.entries(n)){const n={id:t},o=await M(e,s,n);if(o.source){if(o.elb){o.source.elb=o.elb}e.sources[t]={type:o.source.type,settings:o.source.config.settings,mapping:void 0,elb:o.elb}}}}async function I(e={}){const n=function(e){const{version:n}=a(),t={globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0,destinations:{},consent:{},user:{},globals:{},custom:{}},s=(0,P.assign)(t,e,{merge:!1,extend:!1});function o(e,n){(0,P.onLog)({message:e},n||s.verbose)}s.onLog=o;const i={...s.globalsStatic,...s.globals},c={allowed:!1,config:s,consent:s.consent||{},count:0,custom:s.custom||{},destinations:S(s.destinations||{}),globals:i,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:s.user||{},version:n,sources:{},push:void 0};return c.push=v(c,w,e=>({timing:Math.round((Date.now()-c.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),c}(e),{consent:t,user:s,globals:o,custom:i,sources:c}=e;return t&&await n.push("walker consent",t),s&&await n.push("walker user",s),o&&Object.assign(n.globals,o),i&&Object.assign(n.custom,i),c&&await H(n,c),n.config.run&&await n.push("walker run"),{collector:n,elb:n.push}}//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/index.ts","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/handle.ts","../src/on.ts","../src/collector.ts","../src/source.ts"],"sourcesContent":["{\n \"name\": \"@walkeros/collector\",\n \"description\": \"Unified platform-agnostic collector for walkerOS\",\n \"version\": \"0.0.7\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"files\": [\n \"dist/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup --silent\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist\",\n \"dev\": \"jest --watchAll --colors\",\n \"lint\": \"tsc && eslint \\\"**/*.ts*\\\"\",\n \"test\": \"jest\",\n \"update\": \"npx npm-check-updates -u && npm update\"\n },\n \"dependencies\": {\n \"@walkeros/core\": \"0.0.7\"\n },\n \"devDependencies\": {},\n \"repository\": {\n \"url\": \"git+https://github.com/elbwalker/walkerOS.git\",\n \"directory\": \"packages/collector\"\n },\n \"author\": \"elbwalker <hello@elbwalker.com>\",\n \"homepage\": \"https://github.com/elbwalker/walkerOS#readme\",\n \"bugs\": {\n \"url\": \"https://github.com/elbwalker/walkerOS/issues\"\n },\n \"keywords\": [\n \"walker\",\n \"walkerOS\",\n \"analytics\",\n \"tracking\",\n \"data collection\",\n \"measurement\",\n \"data privacy\",\n \"privacy friendly\",\n \"collector\",\n \"event processing\"\n ],\n \"funding\": [\n {\n \"type\": \"GitHub Sponsors\",\n \"url\": \"https://github.com/sponsors/elbwalker\"\n }\n ]\n}\n","export * from './types';\n\nexport * from './constants';\nexport * from './consent';\nexport * from './collector';\nexport * from './destination';\nexport * from './handle';\nexport * from './on';\nexport * from './source';\n","import type { Collector } from '@walkeros/core';\nimport type { WalkerOS } from '@walkeros/core';\n\nexport type CommandTypes =\n | 'Action'\n | 'Config'\n | 'Consent'\n | 'Context'\n | 'Custom'\n | 'Destination'\n | 'Elb'\n | 'Globals'\n | 'Hook'\n | 'Init'\n | 'Link'\n | 'On'\n | 'Prefix'\n | 'Ready'\n | 'Run'\n | 'Session'\n | 'User'\n | 'Walker';\n\nexport const Commands: Record<CommandTypes, Collector.CommandType> = {\n Action: 'action',\n Config: 'config',\n Consent: 'consent',\n Context: 'context',\n Custom: 'custom',\n Destination: 'destination',\n Elb: 'elb',\n Globals: 'globals',\n Hook: 'hook',\n Init: 'init',\n Link: 'link',\n On: 'on',\n Prefix: 'data-elb',\n Ready: 'ready',\n Run: 'run',\n Session: 'session',\n User: 'user',\n Walker: 'walker',\n} as const;\n\nexport type StorageType = 'cookie' | 'local' | 'session';\n\nconst UtilsStorage: { [key: string]: StorageType } = {\n Cookie: 'cookie',\n Local: 'local',\n Session: 'session',\n} as const;\n\nconst Utils = {\n Storage: UtilsStorage,\n};\n\nexport const Const = {\n Commands,\n Utils,\n};\n\nexport default Const;\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport { assign } from '@walkeros/core';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { onApply } from './on';\n\n/**\n * Sets the consent state and processes the queue.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The consent data to set.\n * @returns The result of the push operation.\n */\nexport async function setConsent(\n collector: Collector.Instance,\n data: WalkerOS.Consent,\n): Promise<Elb.PushResult> {\n const { consent } = collector;\n\n let runQueue = false;\n const update: WalkerOS.Consent = {};\n Object.entries(data).forEach(([name, granted]) => {\n const state = !!granted;\n\n update[name] = state;\n\n // Only run queue if state was set to true\n runQueue = runQueue || state;\n });\n\n // Update consent state\n collector.consent = assign(consent, update);\n\n // Run on consent events\n onApply(collector, 'consent', undefined, update);\n\n // Process previous events if not disabled\n return runQueue\n ? pushToDestinations(collector)\n : createPushResult({ ok: true });\n}\n","import type { Collector, WalkerOS, Elb, Destination } from '@walkeros/core';\nimport {\n assign,\n clone,\n createWrapper,\n debounce,\n getId,\n getGrantedConsent,\n getMappingEvent,\n getMappingValue,\n isDefined,\n isObject,\n setByPath,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEventOrCommand } from './handle';\n\nexport type HandleCommandFn<T extends Collector.Instance> = (\n collector: T,\n action: string,\n data?: Elb.PushData,\n options?: unknown,\n) => Promise<Elb.PushResult>;\n\n/**\n * Creates the main push function for the collector.\n *\n * @template T, F\n * @param collector - The walkerOS collector instance.\n * @param handleCommand - TBD.\n * @param prepareEvent - TBD.\n * @returns The push function.\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Elb.Fn {\n return useHooks(\n async (\n eventOrCommand: unknown,\n data?: Elb.PushData,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n // Handle simplified core collector interface\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n // Walker command format: 'walker action', data, options\n const command = eventOrCommand.replace('walker ', '');\n return await handleCommand(collector, command, data, options);\n } else {\n // Event format: event object or string\n const partialEvent =\n typeof eventOrCommand === 'string'\n ? { event: eventOrCommand }\n : (eventOrCommand as WalkerOS.DeepPartialEvent);\n\n const enrichedEvent = prepareEvent(partialEvent);\n\n const { event, command } = createEventOrCommand(\n collector,\n enrichedEvent.event,\n enrichedEvent,\n );\n\n const result = command\n ? await handleCommand(collector, command, data, options)\n : await pushToDestinations(collector, event);\n\n return result;\n }\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Elb.Fn;\n}\n\n/**\n * Adds a new destination to the collector.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The destination's init data.\n * @param options - The destination's config.\n * @returns The result of the push operation.\n */\nexport async function addDestination(\n collector: Collector.Instance,\n data: Destination.Init,\n options?: Destination.Config,\n): Promise<Elb.PushResult> {\n // Prefer explicit given config over default config\n const config = options || data.config || { init: false };\n // @TODO might not be the best solution to use options || data.config\n\n const destination: Destination.Instance = {\n ...data,\n config,\n };\n\n let id = 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 (config.queue !== false) destination.queue = [...collector.queue];\n\n return pushToDestinations(collector, undefined, { [id]: destination });\n}\n\n/**\n * Pushes an event to all or a subset of destinations.\n *\n * @param collector - The walkerOS collector instance.\n * @param event - The event to push.\n * @param destinations - The destinations to push to.\n * @returns The result of the push operation.\n */\nexport async function pushToDestinations(\n collector: Collector.Instance,\n event?: WalkerOS.Event,\n destinations?: Collector.Destinations,\n): Promise<Elb.PushResult> {\n const { allowed, consent, globals, user } = collector;\n\n // Check if collector is allowed to push\n if (!allowed) return createPushResult({ ok: false });\n\n // Add event to the collector queue\n if (event) collector.queue.push(event);\n\n // Use given destinations or use internal destinations\n if (!destinations) destinations = collector.destinations;\n\n const results = await Promise.all(\n // Process all destinations in parallel\n Object.entries(destinations || {}).map(async ([id, destination]) => {\n // Create a queue of events to be processed\n let currentQueue = (destination.queue || []).map((event) => ({\n ...event,\n consent,\n }));\n\n // Reset original queue while processing to enable async processing\n destination.queue = [];\n\n // Add event to queue stack\n if (event) {\n // Clone the event to avoid mutating the original event\n let currentEvent = clone(event);\n\n // Policy check\n await Promise.all(\n Object.entries(destination.config.policy || []).map(\n async ([key, mapping]) => {\n const value = await getMappingValue(event, mapping, {\n collector,\n });\n currentEvent = setByPath(currentEvent, key, value);\n },\n ),\n );\n\n // Add event to queue stack\n currentQueue.push(currentEvent);\n }\n\n // Nothing to do here if the queue is empty\n if (!currentQueue.length) return { id, destination, skipped: true };\n\n const allowedEvents: WalkerOS.Events = [];\n const skippedEvents = currentQueue.filter((queuedEvent) => {\n const grantedConsent = getGrantedConsent(\n destination.config.consent, // Required\n consent, // Current collector state\n queuedEvent.consent, // Individual event state\n );\n\n if (grantedConsent) {\n queuedEvent.consent = grantedConsent; // Save granted consent states only\n\n allowedEvents.push(queuedEvent); // Add to allowed queue\n return false; // Remove from destination queue\n }\n\n return true; // Keep denied events in the queue\n });\n\n // Add skipped events back to the queue\n destination.queue.concat(skippedEvents);\n\n // Execution shall not pass if no events are allowed\n if (!allowedEvents.length) {\n return { id, destination, queue: currentQueue }; // Don't push if not allowed\n }\n\n // Initialize the destination if needed\n const isInitialized = await tryCatchAsync(destinationInit)(\n collector,\n destination,\n );\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error = false;\n if (!destination.dlq) destination.dlq = [];\n\n // Process allowed events and store failed ones in the dead letter queue (DLQ)\n await Promise.all(\n allowedEvents.map(async (event) => {\n // Merge event with collector state, prioritizing event properties\n event.globals = assign(globals, event.globals);\n event.user = assign(user, event.user);\n\n await tryCatchAsync(destinationPush, (err) => {\n // Call custom error handling if available\n if (collector.config.onError)\n collector.config.onError(err, collector);\n error = true; // oh no\n\n // Add failed event to destinations DLQ\n destination.dlq!.push([event, err]);\n\n return false;\n })(collector, destination, event);\n\n return event;\n }),\n );\n\n return { id, destination, error };\n }),\n );\n\n const successful = [];\n const queued = [];\n const failed = [];\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n\n const ref = { id: result.id, destination };\n\n if (result.error) {\n failed.push(ref);\n } else if (result.queue && result.queue.length) {\n // Merge queue with existing queue\n destination.queue = (destination.queue || []).concat(result.queue);\n queued.push(ref);\n } else {\n successful.push(ref);\n }\n }\n\n return createPushResult({\n ok: !failed.length,\n event,\n successful,\n queued,\n failed,\n });\n}\n\n/**\n * Initializes a destination.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to initialize.\n * @returns Whether the destination was initialized successfully.\n */\nexport async function destinationInit<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n const context: Destination.Context = {\n collector,\n config: destination.config,\n wrap: getWrapper(destination, collector),\n };\n\n const configResult = await useHooks(\n destination.init,\n 'DestinationInit',\n collector.hooks,\n )(context);\n\n // Actively check for errors (when false)\n if (configResult === false) return configResult; // don't push if init is false\n\n // Update the destination config if it was returned\n destination.config = {\n ...(configResult || destination.config),\n init: true, // Remember that the destination was initialized\n };\n }\n\n return true; // Destination is ready to push\n}\n\n/**\n * Pushes an event to a single destination.\n * Handles mapping, batching, and consent checks.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to push to.\n * @param event - The event to push.\n * @returns Whether the event was pushed successfully.\n */\nexport async function destinationPush<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n event: WalkerOS.Event,\n): Promise<boolean> {\n const { config } = destination;\n const { eventMapping, mappingKey } = await getMappingEvent(\n event,\n config.mapping,\n );\n\n let data =\n config.data && (await getMappingValue(event, config.data, { collector }));\n\n if (eventMapping) {\n // Check if event should be processed or ignored\n if (eventMapping.ignore) return false;\n\n // Check to use specific event names\n if (eventMapping.name) event.event = eventMapping.name;\n\n // Transform event to a custom data\n if (eventMapping.data) {\n const dataEvent =\n eventMapping.data &&\n (await getMappingValue(event, eventMapping.data, { collector }));\n data =\n isObject(data) && isObject(dataEvent) // Only merge objects\n ? assign(data, dataEvent)\n : dataEvent;\n }\n }\n\n const context: Destination.PushContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n wrap: getWrapper(destination, collector),\n };\n\n if (eventMapping?.batch && destination.pushBatch) {\n const batched = eventMapping.batched || {\n key: mappingKey || '',\n events: [],\n data: [],\n };\n batched.events.push(event);\n if (isDefined(data)) batched.data.push(data);\n\n eventMapping.batchFn =\n eventMapping.batchFn ||\n debounce((destination, collector) => {\n const batchContext: Destination.PushBatchContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n wrap: getWrapper(destination, collector as Collector.Instance),\n };\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n (collector as Collector.Instance).hooks,\n )(batched, batchContext);\n\n // Reset the batched queues\n batched.events = [];\n batched.data = [];\n }, eventMapping.batch);\n\n eventMapping.batched = batched;\n eventMapping.batchFn?.(destination, collector);\n } else {\n // It's time to go to the destination's side now\n await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(event, context);\n }\n\n return true;\n}\n\n/**\n * Creates a standardized result object for push operations.\n *\n * @param partialResult - A partial result to merge with the default result.\n * @returns The push result.\n */\nexport function createPushResult(\n partialResult?: Partial<Elb.PushResult>,\n): Elb.PushResult {\n return assign(\n {\n ok: !partialResult?.failed?.length,\n successful: [],\n queued: [],\n failed: [],\n },\n partialResult,\n );\n}\n\n/**\n * Initializes a map of destinations.\n *\n * @param destinations - The destinations to initialize.\n * @returns The initialized destinations.\n */\nexport function initDestinations(\n destinations: Destination.InitDestinations,\n): Collector.Destinations {\n return Object.entries(destinations).reduce<Collector.Destinations>(\n (acc, [name, destination]) => {\n acc[name] = {\n ...destination,\n config: isObject(destination.config) ? destination.config : {},\n };\n return acc;\n },\n {},\n );\n}\n\nfunction getWrapper(\n destination: Destination.Instance,\n collector?: Collector.Instance,\n) {\n const wrapperConfig = destination.config.wrapper || {};\n const dryRun = destination.config.dryRun ?? collector?.config.dryRun;\n\n return createWrapper(destination.type || 'unknown', {\n ...wrapperConfig,\n ...(isDefined(dryRun) && { dryRun }),\n });\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Commands, Const } from './constants';\nimport { addDestination, pushToDestinations } from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject, isSameType } from '@walkeros/core';\nimport { setConsent } from './consent';\nimport { on, onApply } from './on';\nimport type { RunState } from './types/collector';\n\n/**\n * Handles common commands.\n *\n * @param collector The walkerOS collector instance.\n * @param action The action to handle.\n * @param data The data to handle.\n * @param options The options to handle.\n * @returns A promise that resolves with the push result or undefined.\n */\nexport async function commonHandleCommand(\n collector: Collector.Instance,\n action: string,\n data?: unknown,\n options?: unknown,\n): Promise<Elb.PushResult> {\n let result: Elb.PushResult | undefined;\n switch (action) {\n case Const.Commands.Config:\n if (isObject(data)) {\n assign(collector.config, data as Partial<Collector.Config>, {\n shallow: false,\n });\n }\n break;\n\n case Const.Commands.Consent:\n if (isObject(data)) {\n result = await setConsent(collector, data as WalkerOS.Consent);\n }\n break;\n\n case Const.Commands.Custom:\n if (isObject(data)) {\n collector.custom = assign(\n collector.custom,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.Destination:\n if (isObject(data) && isFunction(data.push)) {\n result = await addDestination(\n collector,\n data as Destination.Init,\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.Run:\n result = await runCollector(collector, data as RunState);\n break;\n\n case Const.Commands.User:\n if (isObject(data)) {\n assign(collector.user, data as WalkerOS.User, { shallow: false });\n }\n break;\n }\n\n return (\n result || {\n ok: true,\n successful: [],\n queued: [],\n failed: [],\n }\n );\n}\n\n/**\n * Creates an event or a command from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param nameOrEvent The name of the event or a partial event.\n * @param defaults The default values for the event.\n * @returns An object with the event or the command.\n */\nexport function createEventOrCommand(\n collector: Collector.Instance,\n nameOrEvent: unknown,\n defaults: WalkerOS.PartialEvent = {},\n): { event?: WalkerOS.Event; command?: string } {\n // Determine the partial event\n const partialEvent: WalkerOS.PartialEvent = isSameType(\n nameOrEvent,\n '' as string,\n )\n ? { event: nameOrEvent, ...defaults }\n : { ...defaults, ...(nameOrEvent || {}) };\n\n if (!partialEvent.event) throw new Error('Event name is required');\n\n // Check for valid entity and action event format\n const [entityValue, actionValue] = partialEvent.event.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n // It's a walker command\n if (entityValue === Commands.Walker) {\n return { command: actionValue };\n }\n\n // Regular event\n ++collector.count;\n\n // Values that are eventually used by other properties\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\n // Extract properties with default fallbacks\n const {\n event = `${entityValue} ${actionValue}`,\n data = {},\n context = {},\n globals = collector.globals,\n custom = {},\n user = collector.user,\n nested = [],\n consent = collector.consent,\n id = `${timestamp}-${group}-${count}`,\n trigger = '',\n entity = entityValue,\n action = actionValue,\n timing = 0,\n version = {\n source: collector.version,\n tagging: collector.config.tagging || 0,\n },\n source = { type: 'collector', id: '', previous_id: '' },\n } = partialEvent;\n\n const fullEvent: WalkerOS.Event = {\n event,\n data,\n context,\n globals,\n custom,\n user,\n nested,\n consent,\n id,\n trigger,\n entity,\n action,\n timestamp,\n timing,\n group,\n count,\n version,\n source,\n };\n\n return { event: fullEvent };\n}\n\n/**\n * Runs the collector by setting it to allowed state and processing queued events.\n *\n * @param collector The walkerOS collector instance.\n * @param state Optional state to merge with the collector (user, globals, consent, custom).\n * @returns A promise that resolves with the push result.\n */\nexport async function runCollector(\n collector: Collector.Instance,\n state?: RunState,\n): Promise<Elb.PushResult> {\n // Set the collector to allowed state\n collector.allowed = true;\n\n // Reset count and generate new group ID\n collector.count = 0;\n collector.group = getId();\n\n // Update timing for this run\n collector.timing = Date.now();\n\n // Update collector state if provided\n if (state) {\n // Update consent if provided\n if (state.consent) {\n collector.consent = assign(collector.consent, state.consent);\n }\n\n // Update user if provided\n if (state.user) {\n collector.user = assign(collector.user, state.user);\n }\n\n // Update globals if provided\n if (state.globals) {\n collector.globals = assign(\n collector.config.globalsStatic || {},\n state.globals,\n );\n }\n\n // Update custom if provided\n if (state.custom) {\n collector.custom = assign(collector.custom, state.custom);\n }\n }\n\n // Reset destination queues\n Object.values(collector.destinations).forEach((destination) => {\n destination.queue = [];\n });\n\n // Increase round counter\n collector.round++;\n\n // Call the predefined run events\n onApply(collector, 'run');\n\n // Process any queued events now that the collector is allowed\n const result = await pushToDestinations(collector);\n\n return result;\n}\n","import type { Collector, On, WalkerOS } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\n\n/**\n * Registers a callback for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to listen for.\n * @param option The callback function or an array of callback functions.\n */\nexport function on(\n collector: Collector.Instance,\n type: On.Types,\n option: WalkerOS.SingleOrArray<On.Options>,\n) {\n const on = collector.on;\n const onType: Array<On.Options> = on[type] || [];\n const options = isArray(option) ? option : [option];\n\n options.forEach((option) => {\n onType.push(option);\n });\n\n // Update collector on state\n (on[type] as typeof onType) = onType;\n\n // Execute the on function directly\n onApply(collector, type, options);\n}\n\n/**\n * Applies all registered callbacks for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to apply the callbacks for.\n * @param options The options for the callbacks.\n * @param config The consent configuration.\n */\nexport function onApply(\n collector: Collector.Instance,\n type: On.Types,\n options?: Array<On.Options>,\n config?: WalkerOS.Consent,\n) {\n // Use the optionally provided options\n let onConfig = options || [];\n\n if (!options) {\n // Get the collector on events\n onConfig = collector.on[type] || [];\n\n // Add all available on events from the destinations\n Object.values(collector.destinations).forEach((destination) => {\n const onTypeConfig = destination.config.on?.[type];\n if (onTypeConfig) onConfig = onConfig.concat(onTypeConfig);\n });\n }\n\n if (!onConfig.length) return; // No on-events registered, nothing to do\n\n switch (type) {\n case Const.Commands.Consent:\n onConsent(collector, onConfig as Array<On.ConsentConfig>, config);\n break;\n case Const.Commands.Ready:\n onReady(collector, onConfig as Array<On.ReadyConfig>);\n break;\n case Const.Commands.Run:\n onRun(collector, onConfig as Array<On.RunConfig>);\n break;\n case Const.Commands.Session:\n onSession(collector, onConfig as Array<On.SessionConfig>);\n break;\n default:\n break;\n }\n}\n\nfunction onConsent(\n collector: Collector.Instance,\n onConfig: Array<On.ConsentConfig>,\n currentConsent?: WalkerOS.Consent,\n): void {\n const consentState = currentConsent || collector.consent;\n\n onConfig.forEach((consentConfig) => {\n // Collect functions whose consent keys match the rule keys directly\n // Directly execute functions whose consent keys match the rule keys\n Object.keys(consentState) // consent keys\n .filter((consent) => consent in consentConfig) // check for matching rule keys\n .forEach((consent) => {\n // Execute the function\n tryCatch(consentConfig[consent])(collector, consentState);\n });\n });\n}\n\nfunction onReady(\n collector: Collector.Instance,\n onConfig: Array<On.ReadyConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onRun(\n collector: Collector.Instance,\n onConfig: Array<On.RunConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onSession(\n collector: Collector.Instance,\n onConfig: Array<On.SessionConfig>,\n): void {\n if (!collector.session) return;\n\n onConfig.forEach((func) => {\n tryCatch(func)(collector, collector.session);\n });\n}\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport type { CreateCollector, CollectorConfig } from './types';\nimport { assign, onLog } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations, createPush } from './destination';\nimport { initSources } from './source';\n\nexport async function createCollector<\n TConfig extends Partial<CollectorConfig> = Partial<CollectorConfig>,\n>(initConfig: TConfig = {} as TConfig): Promise<CreateCollector> {\n const instance = collector(initConfig);\n const { consent, user, globals, custom, sources } = initConfig;\n\n if (consent) await instance.push('walker consent', consent);\n if (user) await instance.push('walker user', user);\n if (globals) Object.assign(instance.globals, globals);\n if (custom) Object.assign(instance.custom, custom);\n\n // Initialize sources if provided\n if (sources) {\n await initSources(instance, sources);\n }\n\n if (instance.config.run) await instance.push('walker run');\n\n return {\n collector: instance,\n elb: instance.push,\n };\n}\n\nfunction collector(initConfig: Partial<CollectorConfig>): Collector.Instance {\n const { version } = require('../package.json');\n\n const defaultConfig: Collector.Config = {\n dryRun: false,\n globalsStatic: {},\n sessionStatic: {},\n tagging: 0,\n verbose: false,\n onLog: log,\n run: true,\n destinations: {},\n consent: {},\n user: {},\n globals: {},\n custom: {},\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n function log(message: string, verbose?: boolean) {\n onLog({ message }, verbose || config.verbose);\n }\n config.onLog = log;\n\n // Enhanced globals with static globals from config\n const finalGlobals = { ...config.globalsStatic, ...config.globals };\n\n const collector: Collector.Instance = {\n allowed: false,\n config,\n consent: config.consent || {},\n count: 0,\n custom: config.custom || {},\n destinations: initDestinations(config.destinations || {}),\n globals: finalGlobals,\n group: '',\n hooks: {},\n on: {},\n queue: [],\n round: 0,\n session: undefined,\n timing: Date.now(),\n user: config.user || {},\n version,\n sources: {},\n push: undefined as unknown as Elb.Fn, // Placeholder, will be set below\n };\n\n // Set the push function with the collector reference\n collector.push = createPush(\n collector,\n commonHandleCommand,\n (event: WalkerOS.DeepPartialEvent): WalkerOS.PartialEvent =>\n ({\n timing: Math.round((Date.now() - collector.timing) / 10) / 100,\n source: { type: 'collector', id: '', previous_id: '' },\n ...event,\n }) as WalkerOS.PartialEvent,\n );\n\n return collector;\n}\n","import type { Collector, WalkerOS, Source } from '@walkeros/core';\nimport { tryCatchAsync, getId } from '@walkeros/core';\n\n/**\n * Core source factory function that creates sources with consistent error handling and lifecycle management.\n *\n * @template T - The source configuration type\n * @param collector - The WalkerOS collector instance\n * @param source - The source function\n * @param config - The source configuration\n * @returns Promise resolving to the created source with its elb function\n */\nexport async function createSource<\n T extends Source.Config,\n E = WalkerOS.AnyFunction,\n>(\n collector: Collector.Instance,\n source: Source.Init<T, E>,\n config: Source.InitConfig,\n): Promise<Source.CreateSource<T, E>> {\n const fullConfig: T = {\n disabled: config.disabled ?? false,\n settings: config.settings ?? {},\n onError: config.onError, // TODO: add default onError\n } as T;\n\n if (fullConfig.disabled) return {};\n\n // Initialize the source\n const result = await tryCatchAsync(source)(collector, fullConfig);\n\n if (!result || !result.source) return {};\n\n const type = fullConfig.type || result.source.type || '';\n const id = config.id || `${type}_${getId(5)}`;\n\n // Store the elb function on the source instance for easy access\n if (result.source && result.elb) {\n const sourceWithElb = result.source as Source.Instance & { elb?: E };\n sourceWithElb.elb = result.elb;\n }\n\n // Register the source in the collector\n collector.sources[id] = {\n type,\n settings: fullConfig.settings,\n mapping: undefined, // Sources handle their own mapping\n elb: result.elb as WalkerOS.AnyFunction | undefined,\n };\n\n return result;\n}\n\n// Types for source initialization\nexport interface SourceInit<\n T extends Source.Config = Source.Config,\n E = WalkerOS.AnyFunction,\n> {\n code: Source.Init<T, E>;\n config?: Partial<T>;\n}\n\nexport interface InitSources {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [sourceId: string]: SourceInit<any, any>;\n}\n\n/**\n * Initialize multiple sources for a collector\n *\n * @param collector - The WalkerOS collector instance\n * @param sources - Map of source configurations\n */\nexport async function initSources(\n collector: Collector.Instance,\n sources: InitSources = {},\n): Promise<void> {\n for (const [sourceId, initSource] of Object.entries(sources)) {\n const { code, config = {} } = initSource;\n\n const fullConfig: Source.InitConfig = {\n id: sourceId,\n ...config,\n };\n\n const result = await createSource(collector, code, fullConfig);\n\n if (result.source) {\n // Store source with elb attached\n if (result.elb) {\n const sourceWithElb = result.source as Source.Instance & {\n elb?: WalkerOS.AnyFunction;\n };\n sourceWithElb.elb = result.elb;\n }\n // Store as CollectorSource format\n collector.sources[sourceId] = {\n type: result.source.type,\n settings: result.source.config.settings,\n mapping: undefined,\n elb: result.elb as WalkerOS.AnyFunction | undefined,\n };\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,iBAAAA,UAAAC,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,MAAQ;AAAA,MACR,aAAe;AAAA,MACf,SAAW;AAAA,MACX,MAAQ;AAAA,MACR,QAAU;AAAA,MACV,OAAS;AAAA,MACT,SAAW;AAAA,MACX,OAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA,SAAW;AAAA,QACT,OAAS;AAAA,QACT,OAAS;AAAA,QACT,KAAO;AAAA,QACP,MAAQ;AAAA,QACR,MAAQ;AAAA,QACR,QAAU;AAAA,MACZ;AAAA,MACA,cAAgB;AAAA,QACd,kBAAkB;AAAA,MACpB;AAAA,MACA,iBAAmB,CAAC;AAAA,MACpB,YAAc;AAAA,QACZ,KAAO;AAAA,QACP,WAAa;AAAA,MACf;AAAA,MACA,QAAU;AAAA,MACV,UAAY;AAAA,MACZ,MAAQ;AAAA,QACN,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,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MAAM,aAAa,IAAI,IAAI,aAAa,GAAG;AAAA,MACrD,GAAG;AAAA,IACL;AAAA,EACJ;AAEA,SAAOA;AACT;","names":["exports","module","import_core","import_core","import_core","import_core","collector","on","option","collector","collector","event","destination","collector","import_core","import_core","collector","collector"]}
1
+ {"version":3,"sources":["../package.json","../src/index.ts","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/handle.ts","../src/on.ts","../src/collector.ts","../src/source.ts"],"sourcesContent":["{\n \"name\": \"@walkeros/collector\",\n \"description\": \"Unified platform-agnostic collector for walkerOS\",\n \"version\": \"0.1.0\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"files\": [\n \"dist/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup --silent\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist\",\n \"dev\": \"jest --watchAll --colors\",\n \"lint\": \"tsc && eslint \\\"**/*.ts*\\\"\",\n \"test\": \"jest\",\n \"update\": \"npx npm-check-updates -u && npm update\"\n },\n \"dependencies\": {\n \"@walkeros/core\": \"0.1.0\"\n },\n \"devDependencies\": {},\n \"repository\": {\n \"url\": \"git+https://github.com/elbwalker/walkerOS.git\",\n \"directory\": \"packages/collector\"\n },\n \"author\": \"elbwalker <hello@elbwalker.com>\",\n \"homepage\": \"https://github.com/elbwalker/walkerOS#readme\",\n \"bugs\": {\n \"url\": \"https://github.com/elbwalker/walkerOS/issues\"\n },\n \"keywords\": [\n \"walker\",\n \"walkerOS\",\n \"analytics\",\n \"tracking\",\n \"data collection\",\n \"measurement\",\n \"data privacy\",\n \"privacy friendly\",\n \"collector\",\n \"event processing\"\n ],\n \"funding\": [\n {\n \"type\": \"GitHub Sponsors\",\n \"url\": \"https://github.com/sponsors/elbwalker\"\n }\n ]\n}\n","export * from './types';\n\nexport * from './constants';\nexport * from './consent';\nexport * from './collector';\nexport * from './destination';\nexport * from './handle';\nexport * from './on';\nexport * from './source';\n","import type { Collector } from '@walkeros/core';\nimport type { WalkerOS } from '@walkeros/core';\n\nexport type CommandTypes =\n | 'Action'\n | 'Actions'\n | 'Config'\n | 'Consent'\n | 'Context'\n | 'Custom'\n | 'Destination'\n | 'Elb'\n | 'Globals'\n | 'Hook'\n | 'Init'\n | 'Link'\n | 'On'\n | 'Prefix'\n | 'Ready'\n | 'Run'\n | 'Session'\n | 'User'\n | 'Walker';\n\nexport const Commands: Record<CommandTypes, Collector.CommandType> = {\n Action: 'action',\n Actions: 'actions',\n Config: 'config',\n Consent: 'consent',\n Context: 'context',\n Custom: 'custom',\n Destination: 'destination',\n Elb: 'elb',\n Globals: 'globals',\n Hook: 'hook',\n Init: 'init',\n Link: 'link',\n On: 'on',\n Prefix: 'data-elb',\n Ready: 'ready',\n Run: 'run',\n Session: 'session',\n User: 'user',\n Walker: 'walker',\n} as const;\n\nexport type StorageType = 'cookie' | 'local' | 'session';\n\nconst UtilsStorage: { [key: string]: StorageType } = {\n Cookie: 'cookie',\n Local: 'local',\n Session: 'session',\n} as const;\n\nconst Utils = {\n Storage: UtilsStorage,\n};\n\nexport const Const = {\n Commands,\n Utils,\n};\n\nexport default Const;\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport { assign } from '@walkeros/core';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { onApply } from './on';\n\n/**\n * Sets the consent state and processes the queue.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The consent data to set.\n * @returns The result of the push operation.\n */\nexport async function setConsent(\n collector: Collector.Instance,\n data: WalkerOS.Consent,\n): Promise<Elb.PushResult> {\n const { consent } = collector;\n\n let runQueue = false;\n const update: WalkerOS.Consent = {};\n Object.entries(data).forEach(([name, granted]) => {\n const state = !!granted;\n\n update[name] = state;\n\n // Only run queue if state was set to true\n runQueue = runQueue || state;\n });\n\n // Update consent state\n collector.consent = assign(consent, update);\n\n // Run on consent events\n onApply(collector, 'consent', undefined, update);\n\n // Process previous events if not disabled\n return runQueue\n ? pushToDestinations(collector)\n : createPushResult({ ok: true });\n}\n","import type { Collector, WalkerOS, Elb, Destination } from '@walkeros/core';\nimport {\n assign,\n clone,\n debounce,\n getId,\n getGrantedConsent,\n getMappingEvent,\n getMappingValue,\n isDefined,\n isObject,\n setByPath,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEventOrCommand } from './handle';\n\nexport type HandleCommandFn<T extends Collector.Instance> = (\n collector: T,\n action: string,\n data?: Elb.PushData,\n options?: unknown,\n) => Promise<Elb.PushResult>;\n\n/**\n * Creates the main push function for the collector.\n *\n * @template T, F\n * @param collector - The walkerOS collector instance.\n * @param handleCommand - TBD.\n * @param prepareEvent - TBD.\n * @returns The push function.\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Elb.Fn {\n return useHooks(\n async (\n eventOrCommand: unknown,\n data?: Elb.PushData,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n // Handle simplified core collector interface\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n // Walker command format: 'walker action', data, options\n const command = eventOrCommand.replace('walker ', '');\n return await handleCommand(collector, command, data, options);\n } else {\n // Event format: event object or string\n const partialEvent =\n typeof eventOrCommand === 'string'\n ? { name: eventOrCommand }\n : (eventOrCommand as WalkerOS.DeepPartialEvent);\n\n const enrichedEvent = prepareEvent(partialEvent);\n\n const { event, command } = createEventOrCommand(\n collector,\n enrichedEvent.name,\n enrichedEvent,\n );\n\n const result = command\n ? await handleCommand(collector, command, data, options)\n : await pushToDestinations(collector, event);\n\n return result;\n }\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Elb.Fn;\n}\n\n/**\n * Adds a new destination to the collector.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The destination's init data.\n * @param options - The destination's config.\n * @returns The result of the push operation.\n */\nexport async function addDestination(\n collector: Collector.Instance,\n data: Destination.Init,\n options?: Destination.Config,\n): Promise<Elb.PushResult> {\n // Prefer explicit given config over default config\n const config = options || data.config || { init: false };\n // @TODO might not be the best solution to use options || data.config\n\n const destination: Destination.Instance = {\n ...data,\n config,\n };\n\n let id = 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 (config.queue !== false) destination.queue = [...collector.queue];\n\n return pushToDestinations(collector, undefined, { [id]: destination });\n}\n\n/**\n * Pushes an event to all or a subset of destinations.\n *\n * @param collector - The walkerOS collector instance.\n * @param event - The event to push.\n * @param destinations - The destinations to push to.\n * @returns The result of the push operation.\n */\nexport async function pushToDestinations(\n collector: Collector.Instance,\n event?: WalkerOS.Event,\n destinations?: Collector.Destinations,\n): Promise<Elb.PushResult> {\n const { allowed, consent, globals, user } = collector;\n\n // Check if collector is allowed to push\n if (!allowed) return createPushResult({ ok: false });\n\n // Add event to the collector queue\n if (event) collector.queue.push(event);\n\n // Use given destinations or use internal destinations\n if (!destinations) destinations = collector.destinations;\n\n const results = await Promise.all(\n // Process all destinations in parallel\n Object.entries(destinations || {}).map(async ([id, destination]) => {\n // Create a queue of events to be processed\n let currentQueue = (destination.queue || []).map((event) => ({\n ...event,\n consent,\n }));\n\n // Reset original queue while processing to enable async processing\n destination.queue = [];\n\n // Add event to queue stack\n if (event) {\n // Clone the event to avoid mutating the original event\n let currentEvent = clone(event);\n\n // Policy check\n await Promise.all(\n Object.entries(destination.config.policy || []).map(\n async ([key, mapping]) => {\n const value = await getMappingValue(event, mapping, {\n collector,\n });\n currentEvent = setByPath(currentEvent, key, value);\n },\n ),\n );\n\n // Add event to queue stack\n currentQueue.push(currentEvent);\n }\n\n // Nothing to do here if the queue is empty\n if (!currentQueue.length) return { id, destination, skipped: true };\n\n const allowedEvents: WalkerOS.Events = [];\n const skippedEvents = currentQueue.filter((queuedEvent) => {\n const grantedConsent = getGrantedConsent(\n destination.config.consent, // Required\n consent, // Current collector state\n queuedEvent.consent, // Individual event state\n );\n\n if (grantedConsent) {\n queuedEvent.consent = grantedConsent; // Save granted consent states only\n\n allowedEvents.push(queuedEvent); // Add to allowed queue\n return false; // Remove from destination queue\n }\n\n return true; // Keep denied events in the queue\n });\n\n // Add skipped events back to the queue\n destination.queue.concat(skippedEvents);\n\n // Execution shall not pass if no events are allowed\n if (!allowedEvents.length) {\n return { id, destination, queue: currentQueue }; // Don't push if not allowed\n }\n\n // Initialize the destination if needed\n const isInitialized = await tryCatchAsync(destinationInit)(\n collector,\n destination,\n );\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error = false;\n if (!destination.dlq) destination.dlq = [];\n\n // Process allowed events and store failed ones in the dead letter queue (DLQ)\n await Promise.all(\n allowedEvents.map(async (event) => {\n // Merge event with collector state, prioritizing event properties\n event.globals = assign(globals, event.globals);\n event.user = assign(user, event.user);\n\n await tryCatchAsync(destinationPush, (err) => {\n // Call custom error handling if available\n if (collector.config.onError)\n collector.config.onError(err, collector);\n error = true; // oh no\n\n // Add failed event to destinations DLQ\n destination.dlq!.push([event, err]);\n\n return false;\n })(collector, destination, event);\n\n return event;\n }),\n );\n\n return { id, destination, error };\n }),\n );\n\n const successful = [];\n const queued = [];\n const failed = [];\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n\n const ref = { id: result.id, destination };\n\n if (result.error) {\n failed.push(ref);\n } else if (result.queue && result.queue.length) {\n // Merge queue with existing queue\n destination.queue = (destination.queue || []).concat(result.queue);\n queued.push(ref);\n } else {\n successful.push(ref);\n }\n }\n\n return createPushResult({\n ok: !failed.length,\n event,\n successful,\n queued,\n failed,\n });\n}\n\n/**\n * Initializes a destination.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to initialize.\n * @returns Whether the destination was initialized successfully.\n */\nexport async function destinationInit<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n const context: Destination.Context = {\n collector,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n const configResult = await useHooks(\n destination.init,\n 'DestinationInit',\n collector.hooks,\n )(context);\n\n // Actively check for errors (when false)\n if (configResult === false) return configResult; // don't push if init is false\n\n // Update the destination config if it was returned\n destination.config = {\n ...(configResult || destination.config),\n init: true, // Remember that the destination was initialized\n };\n }\n\n return true; // Destination is ready to push\n}\n\n/**\n * Pushes an event to a single destination.\n * Handles mapping, batching, and consent checks.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to push to.\n * @param event - The event to push.\n * @returns Whether the event was pushed successfully.\n */\nexport async function destinationPush<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n event: WalkerOS.Event,\n): Promise<boolean> {\n const { config } = destination;\n const { eventMapping, mappingKey } = await getMappingEvent(\n event,\n config.mapping,\n );\n\n let data =\n config.data && (await getMappingValue(event, config.data, { collector }));\n\n if (eventMapping) {\n // Check if event should be processed or ignored\n if (eventMapping.ignore) return false;\n\n // Check to use specific event names\n if (eventMapping.name) event.name = eventMapping.name;\n\n // Transform event to a custom data\n if (eventMapping.data) {\n const dataEvent =\n eventMapping.data &&\n (await getMappingValue(event, eventMapping.data, { collector }));\n data =\n isObject(data) && isObject(dataEvent) // Only merge objects\n ? assign(data, dataEvent)\n : dataEvent;\n }\n }\n\n const context: Destination.PushContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n if (eventMapping?.batch && destination.pushBatch) {\n const batched = eventMapping.batched || {\n key: mappingKey || '',\n events: [],\n data: [],\n };\n batched.events.push(event);\n if (isDefined(data)) batched.data.push(data);\n\n eventMapping.batchFn =\n eventMapping.batchFn ||\n debounce((destination, collector) => {\n const batchContext: Destination.PushBatchContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n (collector as Collector.Instance).hooks,\n )(batched, batchContext);\n\n // Reset the batched queues\n batched.events = [];\n batched.data = [];\n }, eventMapping.batch);\n\n eventMapping.batched = batched;\n eventMapping.batchFn?.(destination, collector);\n } else {\n // It's time to go to the destination's side now\n await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(event, context);\n }\n\n return true;\n}\n\n/**\n * Creates a standardized result object for push operations.\n *\n * @param partialResult - A partial result to merge with the default result.\n * @returns The push result.\n */\nexport function createPushResult(\n partialResult?: Partial<Elb.PushResult>,\n): Elb.PushResult {\n return assign(\n {\n ok: !partialResult?.failed?.length,\n successful: [],\n queued: [],\n failed: [],\n },\n partialResult,\n );\n}\n\n/**\n * Initializes a map of destinations.\n *\n * @param destinations - The destinations to initialize.\n * @returns The initialized destinations.\n */\nexport function initDestinations(\n destinations: Destination.InitDestinations,\n): Collector.Destinations {\n return Object.entries(destinations).reduce<Collector.Destinations>(\n (acc, [name, destination]) => {\n acc[name] = {\n ...destination,\n config: isObject(destination.config) ? destination.config : {},\n };\n return acc;\n },\n {},\n );\n}\n\n/**\n * Merges destination environment with config environment\n * Config env takes precedence over destination env for overrides\n */\nfunction mergeEnvironments(\n destinationEnv?: Destination.Environment,\n configEnv?: Destination.Environment,\n): Destination.Environment {\n // If neither environment exists, return empty object\n if (!destinationEnv && !configEnv) return {};\n\n // If only one exists, return it\n if (!configEnv) return destinationEnv!;\n if (!destinationEnv) return configEnv;\n\n // Both exist - merge objects with configEnv taking precedence\n if (isObject(destinationEnv) && isObject(configEnv)) {\n return { ...destinationEnv, ...configEnv };\n }\n\n // If they're not both objects, config env overrides destination env\n return configEnv;\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Commands, Const } from './constants';\nimport { addDestination, pushToDestinations } from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject, isSameType } from '@walkeros/core';\nimport { setConsent } from './consent';\nimport { on, onApply } from './on';\nimport type { RunState } from './types/collector';\n\n/**\n * Handles common commands.\n *\n * @param collector The walkerOS collector instance.\n * @param action The action to handle.\n * @param data The data to handle.\n * @param options The options to handle.\n * @returns A promise that resolves with the push result or undefined.\n */\nexport async function commonHandleCommand(\n collector: Collector.Instance,\n action: string,\n data?: unknown,\n options?: unknown,\n): Promise<Elb.PushResult> {\n let result: Elb.PushResult | undefined;\n switch (action) {\n case Const.Commands.Config:\n if (isObject(data)) {\n assign(collector.config, data as Partial<Collector.Config>, {\n shallow: false,\n });\n }\n break;\n\n case Const.Commands.Consent:\n if (isObject(data)) {\n result = await setConsent(collector, data as WalkerOS.Consent);\n }\n break;\n\n case Const.Commands.Custom:\n if (isObject(data)) {\n collector.custom = assign(\n collector.custom,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.Destination:\n if (isObject(data) && isFunction(data.push)) {\n result = await addDestination(\n collector,\n data as Destination.Init,\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.Run:\n result = await runCollector(collector, data as RunState);\n break;\n\n case Const.Commands.User:\n if (isObject(data)) {\n assign(collector.user, data as WalkerOS.User, { shallow: false });\n }\n break;\n }\n\n return (\n result || {\n ok: true,\n successful: [],\n queued: [],\n failed: [],\n }\n );\n}\n\n/**\n * Creates an event or a command from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param nameOrEvent The name of the event or a partial event.\n * @param defaults The default values for the event.\n * @returns An object with the event or the command.\n */\nexport function createEventOrCommand(\n collector: Collector.Instance,\n nameOrEvent: unknown,\n defaults: WalkerOS.PartialEvent = {},\n): { event?: WalkerOS.Event; command?: string } {\n // Determine the partial event\n const partialEvent: WalkerOS.PartialEvent = isSameType(\n nameOrEvent,\n '' as string,\n )\n ? { name: nameOrEvent, ...defaults }\n : { ...defaults, ...(nameOrEvent || {}) };\n\n if (!partialEvent.name) throw new Error('Event name is required');\n\n // Check for valid entity and action event format\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n // It's a walker command\n if (entityValue === Commands.Walker) {\n return { command: actionValue };\n }\n\n // Regular event\n ++collector.count;\n\n // Values that are eventually used by other properties\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\n // Extract properties with default fallbacks\n const {\n name = `${entityValue} ${actionValue}`,\n data = {},\n context = {},\n globals = collector.globals,\n custom = {},\n user = collector.user,\n nested = [],\n consent = collector.consent,\n id = `${timestamp}-${group}-${count}`,\n trigger = '',\n entity = entityValue,\n action = actionValue,\n timing = 0,\n version = {\n source: collector.version,\n tagging: collector.config.tagging || 0,\n },\n source = { type: 'collector', id: '', previous_id: '' },\n } = partialEvent;\n\n const fullEvent: WalkerOS.Event = {\n name,\n data,\n context,\n globals,\n custom,\n user,\n nested,\n consent,\n id,\n trigger,\n entity,\n action,\n timestamp,\n timing,\n group,\n count,\n version,\n source,\n };\n\n return { event: fullEvent };\n}\n\n/**\n * Runs the collector by setting it to allowed state and processing queued events.\n *\n * @param collector The walkerOS collector instance.\n * @param state Optional state to merge with the collector (user, globals, consent, custom).\n * @returns A promise that resolves with the push result.\n */\nexport async function runCollector(\n collector: Collector.Instance,\n state?: RunState,\n): Promise<Elb.PushResult> {\n // Set the collector to allowed state\n collector.allowed = true;\n\n // Reset count and generate new group ID\n collector.count = 0;\n collector.group = getId();\n\n // Update timing for this run\n collector.timing = Date.now();\n\n // Update collector state if provided\n if (state) {\n // Update consent if provided\n if (state.consent) {\n collector.consent = assign(collector.consent, state.consent);\n }\n\n // Update user if provided\n if (state.user) {\n collector.user = assign(collector.user, state.user);\n }\n\n // Update globals if provided\n if (state.globals) {\n collector.globals = assign(\n collector.config.globalsStatic || {},\n state.globals,\n );\n }\n\n // Update custom if provided\n if (state.custom) {\n collector.custom = assign(collector.custom, state.custom);\n }\n }\n\n // Reset destination queues\n Object.values(collector.destinations).forEach((destination) => {\n destination.queue = [];\n });\n\n // Reset collector queue for this run\n collector.queue = [];\n\n // Increase round counter\n collector.round++;\n\n // Process any queued events now that the collector is allowed\n const result = await pushToDestinations(collector);\n\n // Call the predefined run events\n onApply(collector, 'run');\n\n return result;\n}\n","import type { Collector, On, WalkerOS } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\n\n/**\n * Registers a callback for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to listen for.\n * @param option The callback function or an array of callback functions.\n */\nexport function on(\n collector: Collector.Instance,\n type: On.Types,\n option: WalkerOS.SingleOrArray<On.Options>,\n) {\n const on = collector.on;\n const onType: Array<On.Options> = on[type] || [];\n const options = isArray(option) ? option : [option];\n\n options.forEach((option) => {\n onType.push(option);\n });\n\n // Update collector on state\n (on[type] as typeof onType) = onType;\n\n // Execute the on function directly\n onApply(collector, type, options);\n}\n\n/**\n * Applies all registered callbacks for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to apply the callbacks for.\n * @param options The options for the callbacks.\n * @param config The consent configuration.\n */\nexport function onApply(\n collector: Collector.Instance,\n type: On.Types,\n options?: Array<On.Options>,\n config?: WalkerOS.Consent,\n) {\n // Use the optionally provided options\n let onConfig = options || [];\n\n if (!options) {\n // Get the collector on events\n onConfig = collector.on[type] || [];\n\n // Add all available on events from the destinations\n Object.values(collector.destinations).forEach((destination) => {\n const onTypeConfig = destination.config.on?.[type];\n if (onTypeConfig) onConfig = onConfig.concat(onTypeConfig);\n });\n }\n\n if (!onConfig.length) return; // No on-events registered, nothing to do\n\n switch (type) {\n case Const.Commands.Consent:\n onConsent(collector, onConfig as Array<On.ConsentConfig>, config);\n break;\n case Const.Commands.Ready:\n onReady(collector, onConfig as Array<On.ReadyConfig>);\n break;\n case Const.Commands.Run:\n onRun(collector, onConfig as Array<On.RunConfig>);\n break;\n case Const.Commands.Session:\n onSession(collector, onConfig as Array<On.SessionConfig>);\n break;\n default:\n break;\n }\n}\n\nfunction onConsent(\n collector: Collector.Instance,\n onConfig: Array<On.ConsentConfig>,\n currentConsent?: WalkerOS.Consent,\n): void {\n const consentState = currentConsent || collector.consent;\n\n onConfig.forEach((consentConfig) => {\n // Collect functions whose consent keys match the rule keys directly\n // Directly execute functions whose consent keys match the rule keys\n Object.keys(consentState) // consent keys\n .filter((consent) => consent in consentConfig) // check for matching rule keys\n .forEach((consent) => {\n // Execute the function\n tryCatch(consentConfig[consent])(collector, consentState);\n });\n });\n}\n\nfunction onReady(\n collector: Collector.Instance,\n onConfig: Array<On.ReadyConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onRun(\n collector: Collector.Instance,\n onConfig: Array<On.RunConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onSession(\n collector: Collector.Instance,\n onConfig: Array<On.SessionConfig>,\n): void {\n if (!collector.session) return;\n\n onConfig.forEach((func) => {\n tryCatch(func)(collector, collector.session);\n });\n}\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport type { CreateCollector, CollectorConfig } from './types';\nimport { assign, onLog } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations, createPush } from './destination';\nimport { initSources } from './source';\n\nexport async function createCollector<\n TConfig extends Partial<CollectorConfig> = Partial<CollectorConfig>,\n>(initConfig: TConfig = {} as TConfig): Promise<CreateCollector> {\n const instance = collector(initConfig);\n const { consent, user, globals, custom, sources } = initConfig;\n\n if (consent) await instance.push('walker consent', consent);\n if (user) await instance.push('walker user', user);\n if (globals) Object.assign(instance.globals, globals);\n if (custom) Object.assign(instance.custom, custom);\n\n // Initialize sources if provided\n if (sources) {\n await initSources(instance, sources);\n }\n\n if (instance.config.run) await instance.push('walker run');\n\n return {\n collector: instance,\n elb: instance.push,\n };\n}\n\nfunction collector(initConfig: Partial<CollectorConfig>): Collector.Instance {\n const { version } = require('../package.json');\n\n const defaultConfig: Collector.Config = {\n globalsStatic: {},\n sessionStatic: {},\n tagging: 0,\n verbose: false,\n onLog: log,\n run: true,\n destinations: {},\n consent: {},\n user: {},\n globals: {},\n custom: {},\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n function log(message: string, verbose?: boolean) {\n onLog({ message }, verbose || config.verbose);\n }\n config.onLog = log;\n\n // Enhanced globals with static globals from config\n const finalGlobals = { ...config.globalsStatic, ...config.globals };\n\n const collector: Collector.Instance = {\n allowed: false,\n config,\n consent: config.consent || {},\n count: 0,\n custom: config.custom || {},\n destinations: initDestinations(config.destinations || {}),\n globals: finalGlobals,\n group: '',\n hooks: {},\n on: {},\n queue: [],\n round: 0,\n session: undefined,\n timing: Date.now(),\n user: config.user || {},\n version,\n sources: {},\n push: undefined as unknown as Elb.Fn, // Placeholder, will be set below\n };\n\n // Set the push function with the collector reference\n collector.push = createPush(\n collector,\n commonHandleCommand,\n (event: WalkerOS.DeepPartialEvent): WalkerOS.PartialEvent =>\n ({\n timing: Math.round((Date.now() - collector.timing) / 10) / 100,\n source: { type: 'collector', id: '', previous_id: '' },\n ...event,\n }) as WalkerOS.PartialEvent,\n );\n\n return collector;\n}\n","import type { Collector, WalkerOS, Source } from '@walkeros/core';\nimport { tryCatchAsync, getId } from '@walkeros/core';\n\n/**\n * Core source factory function that creates sources with consistent error handling and lifecycle management.\n *\n * @template T - The source configuration type\n * @param collector - The WalkerOS collector instance\n * @param source - The source function\n * @param config - The source configuration\n * @returns Promise resolving to the created source with its elb function\n */\nexport async function createSource<\n T extends Source.Config,\n E = WalkerOS.AnyFunction,\n>(\n collector: Collector.Instance,\n source: Source.Init<T, E>,\n config: Source.InitConfig,\n): Promise<Source.CreateSource<T, E>> {\n const fullConfig: T = {\n disabled: config.disabled ?? false,\n settings: config.settings ?? {},\n onError: config.onError, // TODO: add default onError\n } as T;\n\n if (fullConfig.disabled) {\n return {};\n }\n\n // Initialize the source\n const result = await tryCatchAsync(source)(collector, fullConfig);\n\n if (!result || !result.source) {\n return {};\n }\n\n const type = fullConfig.type || result.source.type || '';\n const id = config.id || `${type}_${getId(5)}`;\n\n // Store the elb function on the source instance for easy access\n if (result.source && result.elb) {\n const sourceWithElb = result.source as Source.Instance & { elb?: E };\n sourceWithElb.elb = result.elb;\n }\n\n // Register the source in the collector (ensure sources object exists)\n if (!collector.sources) {\n collector.sources = {};\n }\n collector.sources[id] = {\n type,\n settings: fullConfig.settings,\n mapping: undefined, // Sources handle their own mapping\n elb: result.elb as WalkerOS.AnyFunction | undefined,\n };\n\n return result;\n}\n\n// Types for source initialization\nexport interface InitSources {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [sourceId: string]: Source.Init<any, any>;\n}\n\n/**\n * Initialize multiple sources for a collector\n *\n * @param collector - The WalkerOS collector instance\n * @param sources - Map of source configurations\n */\nexport async function initSources(\n collector: Collector.Instance,\n sources: InitSources = {},\n): Promise<void> {\n for (const [sourceId, sourceInit] of Object.entries(sources)) {\n const fullConfig: Source.InitConfig = {\n id: sourceId,\n };\n\n const result = await createSource(collector, sourceInit, fullConfig);\n\n if (result.source) {\n // Store source with elb attached\n if (result.elb) {\n const sourceWithElb = result.source as Source.Instance & {\n elb?: WalkerOS.AnyFunction;\n };\n sourceWithElb.elb = result.elb;\n }\n // Store as CollectorSource format\n collector.sources[sourceId] = {\n type: result.source.type,\n settings: result.source.config.settings,\n mapping: undefined,\n elb: result.elb as WalkerOS.AnyFunction | undefined,\n };\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AAS,IAAI,SAAiB,SAAmB;AAC/C,4BAAM,EAAE,QAAQ,GAAG,WAAW,OAAO,OAAO;AAAA,EAC9C;AACA,SAAO,QAAQ;AAGf,QAAM,eAAe,EAAE,GAAG,OAAO,eAAe,GAAG,OAAO,QAAQ;AAElE,QAAMC,aAAgC;AAAA,IACpC,SAAS;AAAA,IACT;AAAA,IACA,SAAS,OAAO,WAAW,CAAC;AAAA,IAC5B,OAAO;AAAA,IACP,QAAQ,OAAO,UAAU,CAAC;AAAA,IAC1B,cAAc,iBAAiB,OAAO,gBAAgB,CAAC,CAAC;AAAA,IACxD,SAAS;AAAA,IACT,OAAO;AAAA,IACP,OAAO,CAAC;AAAA,IACR,IAAI,CAAC;AAAA,IACL,OAAO,CAAC;AAAA,IACR,OAAO;AAAA,IACP,SAAS;AAAA,IACT,QAAQ,KAAK,IAAI;AAAA,IACjB,MAAM,OAAO,QAAQ,CAAC;AAAA,IACtB;AAAA,IACA,SAAS,CAAC;AAAA,IACV,MAAM;AAAA;AAAA,EACR;AAGA,EAAAA,WAAU,OAAO;AAAA,IACfA;AAAA,IACA;AAAA,IACA,CAAC,WACE;AAAA,MACC,QAAQ,KAAK,OAAO,KAAK,IAAI,IAAIA,WAAU,UAAU,EAAE,IAAI;AAAA,MAC3D,QAAQ,EAAE,MAAM,aAAa,IAAI,IAAI,aAAa,GAAG;AAAA,MACrD,GAAG;AAAA,IACL;AAAA,EACJ;AAEA,SAAOA;AACT;","names":["exports","module","import_core","import_core","import_core","import_core","collector","on","option","collector","collector","event","destination","collector","import_core","import_core","collector","collector"]}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var e,n,t=Object.getOwnPropertyNames,o=(e={"package.json"(e,n){n.exports={name:"@walkeros/collector",description:"Unified platform-agnostic collector for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{"@walkeros/core":"0.0.7"},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/collector"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","collector","event processing"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return n||(0,e[t(e)[0]])((n={exports:{}}).exports,n),n.exports}),s={Action:"action",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"},i={Commands:s,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}};import{assign as a}from"@walkeros/core";import{assign as r,clone as c,createWrapper as u,debounce as l,getId as d,getGrantedConsent as g,getMappingEvent as f,getMappingValue as m,isDefined as p,isObject as b,setByPath as w,tryCatchAsync as h,useHooks as k}from"@walkeros/core";import{assign as y,getId as v,isFunction as q,isString as C}from"@walkeros/core";import{isObject as O,isSameType as j}from"@walkeros/core";import{isArray as E}from"@walkeros/core";import{tryCatch as x}from"@walkeros/core";function S(e,n,t){const o=e.on,s=o[n]||[],i=E(t)?t:[t];i.forEach(e=>{s.push(e)}),o[n]=s,D(e,n,i)}function D(e,n,t,o){let s=t||[];if(t||(s=e.on[n]||[],Object.values(e.destinations).forEach(e=>{const t=e.config.on?.[n];t&&(s=s.concat(t))})),s.length)switch(n){case i.Commands.Consent:!function(e,n,t){const o=t||e.consent;n.forEach(n=>{Object.keys(o).filter(e=>e in n).forEach(t=>{x(n[t])(e,o)})})}(e,s,o);break;case i.Commands.Ready:case i.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{x(n)(e)})}(e,s);break;case i.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{x(n)(e,e.session)})}(e,s)}}async function R(e,n,t,o){let s;switch(n){case i.Commands.Config:O(t)&&y(e.config,t,{shallow:!1});break;case i.Commands.Consent:O(t)&&(s=await M(e,t));break;case i.Commands.Custom:O(t)&&(e.custom=y(e.custom,t));break;case i.Commands.Destination:O(t)&&q(t.push)&&(s=await L(e,t,o));break;case i.Commands.Globals:O(t)&&(e.globals=y(e.globals,t));break;case i.Commands.On:C(t)&&S(e,t,o);break;case i.Commands.Run:s=await $(e,t);break;case i.Commands.User:O(t)&&y(e.user,t,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function P(e,n,t={}){const o=j(n,"")?{event:n,...t}:{...t,...n||{}};if(!o.event)throw new Error("Event name is required");const[i,a]=o.event.split(" ");if(!i||!a)throw new Error("Event name is invalid");if(i===s.Walker)return{command:a};++e.count;const{timestamp:r=Date.now(),group:c=e.group,count:u=e.count}=o,{event:l=`${i} ${a}`,data:d={},context:g={},globals:f=e.globals,custom:m={},user:p=e.user,nested:b=[],consent:w=e.consent,id:h=`${r}-${c}-${u}`,trigger:k="",entity:y=i,action:v=a,timing:q=0,version:C={source:e.version,tagging:e.config.tagging||0},source:O={type:"collector",id:"",previous_id:""}}=o;return{event:{event:l,data:d,context:g,globals:f,custom:m,user:p,nested:b,consent:w,id:h,trigger:k,entity:y,action:v,timestamp:r,timing:q,group:c,count:u,version:C,source:O}}}async function $(e,n){e.allowed=!0,e.count=0,e.group=v(),e.timing=Date.now(),n&&(n.consent&&(e.consent=y(e.consent,n.consent)),n.user&&(e.user=y(e.user,n.user)),n.globals&&(e.globals=y(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=y(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.round++,D(e,"run");return await U(e)}function I(e,n,t){return k(async(o,s,i)=>await h(async()=>{if("string"==typeof o&&o.startsWith("walker ")){const t=o.replace("walker ","");return await n(e,t,s,i)}{const a=t("string"==typeof o?{event:o}:o),{event:r,command:c}=P(e,a.event,a);return c?await n(e,c,s,i):await U(e,r)}},()=>B({ok:!1}))(),"Push",e.hooks)}async function L(e,n,t){const o=t||n.config||{init:!1},s={...n,config:o};let i=o.id;if(!i)do{i=d(4)}while(e.destinations[i]);return e.destinations[i]=s,!1!==o.queue&&(s.queue=[...e.queue]),U(e,void 0,{[i]:s})}async function U(e,n,t){const{allowed:o,consent:s,globals:i,user:a}=e;if(!o)return B({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const u=await Promise.all(Object.entries(t||{}).map(async([t,o])=>{let u=(o.queue||[]).map(e=>({...e,consent:s}));if(o.queue=[],n){let t=c(n);await Promise.all(Object.entries(o.config.policy||[]).map(async([o,s])=>{const i=await m(n,s,{collector:e});t=w(t,o,i)})),u.push(t)}if(!u.length)return{id:t,destination:o,skipped:!0};const l=[],d=u.filter(e=>{const n=g(o.config.consent,s,e.consent);return!n||(e.consent=n,l.push(e),!1)});if(o.queue.concat(d),!l.length)return{id:t,destination:o,queue:u};if(!await h(_)(e,o))return{id:t,destination:o,queue:u};let f=!1;return o.dlq||(o.dlq=[]),await Promise.all(l.map(async n=>(n.globals=r(i,n.globals),n.user=r(a,n.user),await h(A,t=>(e.config.onError&&e.config.onError(t,e),f=!0,o.dlq.push([n,t]),!1))(e,o,n),n))),{id:t,destination:o,error:f}})),l=[],d=[],f=[];for(const e of u){if(e.skipped)continue;const n=e.destination,t={id:e.id,destination:n};e.error?f.push(t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),d.push(t)):l.push(t)}return B({ok:!f.length,event:n,successful:l,queued:d,failed:f})}async function _(e,n){if(n.init&&!n.config.init){const t={collector:e,config:n.config,wrap:G(n,e)},o=await k(n.init,"DestinationInit",e.hooks)(t);if(!1===o)return o;n.config={...o||n.config,init:!0}}return!0}async function A(e,n,t){const{config:o}=n,{eventMapping:s,mappingKey:i}=await f(t,o.mapping);let a=o.data&&await m(t,o.data,{collector:e});if(s){if(s.ignore)return!1;if(s.name&&(t.event=s.name),s.data){const n=s.data&&await m(t,s.data,{collector:e});a=b(a)&&b(n)?r(a,n):n}}const c={collector:e,config:o,data:a,mapping:s,wrap:G(n,e)};if(s?.batch&&n.pushBatch){const r=s.batched||{key:i||"",events:[],data:[]};r.events.push(t),p(a)&&r.data.push(a),s.batchFn=s.batchFn||l((e,n)=>{const t={collector:n,config:o,data:a,mapping:s,wrap:G(e,n)};k(e.pushBatch,"DestinationPushBatch",n.hooks)(r,t),r.events=[],r.data=[]},s.batch),s.batched=r,s.batchFn?.(n,e)}else await k(n.push,"DestinationPush",e.hooks)(t,c);return!0}function B(e){return r({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}function F(e){return Object.entries(e).reduce((e,[n,t])=>(e[n]={...t,config:b(t.config)?t.config:{}},e),{})}function G(e,n){const t=e.config.wrapper||{},o=e.config.dryRun??n?.config.dryRun;return u(e.type||"unknown",{...t,...p(o)&&{dryRun:o}})}async function M(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=a(t,s),D(e,"consent",void 0,s),o?U(e):B({ok:!0})}import{assign as W,onLog as H}from"@walkeros/core";import{tryCatchAsync as K,getId as N}from"@walkeros/core";async function T(e,n,t){const o={disabled:t.disabled??!1,settings:t.settings??{},onError:t.onError};if(o.disabled)return{};const s=await K(n)(e,o);if(!s||!s.source)return{};const i=o.type||s.source.type||"",a=t.id||`${i}_${N(5)}`;if(s.source&&s.elb){s.source.elb=s.elb}return e.sources[a]={type:i,settings:o.settings,mapping:void 0,elb:s.elb},s}async function z(e,n={}){for(const[t,o]of Object.entries(n)){const{code:n,config:s={}}=o,i={id:t,...s},a=await T(e,n,i);if(a.source){if(a.elb){a.source.elb=a.elb}e.sources[t]={type:a.source.type,settings:a.source.config.settings,mapping:void 0,elb:a.elb}}}}async function J(e={}){const n=function(e){const{version:n}=o(),t=W({dryRun:!1,globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:s,run:!0,destinations:{},consent:{},user:{},globals:{},custom:{}},e,{merge:!1,extend:!1});function s(e,n){H({message:e},n||t.verbose)}t.onLog=s;const i={...t.globalsStatic,...t.globals},a={allowed:!1,config:t,consent:t.consent||{},count:0,custom:t.custom||{},destinations:F(t.destinations||{}),globals:i,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:t.user||{},version:n,sources:{},push:void 0};return a.push=I(a,R,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a}(e),{consent:t,user:s,globals:i,custom:a,sources:r}=e;return t&&await n.push("walker consent",t),s&&await n.push("walker user",s),i&&Object.assign(n.globals,i),a&&Object.assign(n.custom,a),r&&await z(n,r),n.config.run&&await n.push("walker run"),{collector:n,elb:n.push}}export{s as Commands,i as Const,L as addDestination,R as commonHandleCommand,J as createCollector,P as createEventOrCommand,I as createPush,B as createPushResult,T as createSource,_ as destinationInit,A as destinationPush,F as initDestinations,z as initSources,S as on,D as onApply,U as pushToDestinations,$ as runCollector,M as setConsent};//# sourceMappingURL=index.mjs.map
1
+ var e,n,t=Object.getOwnPropertyNames,o=(e={"package.json"(e,n){n.exports={name:"@walkeros/collector",description:"Unified platform-agnostic collector for walkerOS",version:"0.1.0",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{"@walkeros/core":"0.1.0"},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/collector"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","collector","event processing"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return n||(0,e[t(e)[0]])((n={exports:{}}).exports,n),n.exports}),s={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},i={Commands:s,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}};import{assign as a}from"@walkeros/core";import{assign as c,clone as r,debounce as u,getId as l,getGrantedConsent as d,getMappingEvent as g,getMappingValue as m,isDefined as f,isObject as p,setByPath as b,tryCatchAsync as h,useHooks as w}from"@walkeros/core";import{assign as k,getId as y,isFunction as v,isString as q}from"@walkeros/core";import{isObject as C,isSameType as O}from"@walkeros/core";import{isArray as j}from"@walkeros/core";import{tryCatch as E}from"@walkeros/core";function x(e,n,t){const o=e.on,s=o[n]||[],i=j(t)?t:[t];i.forEach(e=>{s.push(e)}),o[n]=s,S(e,n,i)}function S(e,n,t,o){let s=t||[];if(t||(s=e.on[n]||[],Object.values(e.destinations).forEach(e=>{const t=e.config.on?.[n];t&&(s=s.concat(t))})),s.length)switch(n){case i.Commands.Consent:!function(e,n,t){const o=t||e.consent;n.forEach(n=>{Object.keys(o).filter(e=>e in n).forEach(t=>{E(n[t])(e,o)})})}(e,s,o);break;case i.Commands.Ready:case i.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{E(n)(e)})}(e,s);break;case i.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{E(n)(e,e.session)})}(e,s)}}async function D(e,n,t,o){let s;switch(n){case i.Commands.Config:C(t)&&k(e.config,t,{shallow:!1});break;case i.Commands.Consent:C(t)&&(s=await G(e,t));break;case i.Commands.Custom:C(t)&&(e.custom=k(e.custom,t));break;case i.Commands.Destination:C(t)&&v(t.push)&&(s=await R(e,t,o));break;case i.Commands.Globals:C(t)&&(e.globals=k(e.globals,t));break;case i.Commands.On:q(t)&&x(e,t,o);break;case i.Commands.Run:s=await $(e,t);break;case i.Commands.User:C(t)&&k(e.user,t,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function P(e,n,t={}){const o=O(n,"")?{name:n,...t}:{...t,...n||{}};if(!o.name)throw new Error("Event name is required");const[i,a]=o.name.split(" ");if(!i||!a)throw new Error("Event name is invalid");if(i===s.Walker)return{command:a};++e.count;const{timestamp:c=Date.now(),group:r=e.group,count:u=e.count}=o,{name:l=`${i} ${a}`,data:d={},context:g={},globals:m=e.globals,custom:f={},user:p=e.user,nested:b=[],consent:h=e.consent,id:w=`${c}-${r}-${u}`,trigger:k="",entity:y=i,action:v=a,timing:q=0,version:C={source:e.version,tagging:e.config.tagging||0},source:j={type:"collector",id:"",previous_id:""}}=o;return{event:{name:l,data:d,context:g,globals:m,custom:f,user:p,nested:b,consent:h,id:w,trigger:k,entity:y,action:v,timestamp:c,timing:q,group:r,count:u,version:C,source:j}}}async function $(e,n){e.allowed=!0,e.count=0,e.group=y(),e.timing=Date.now(),n&&(n.consent&&(e.consent=k(e.consent,n.consent)),n.user&&(e.user=k(e.user,n.user)),n.globals&&(e.globals=k(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=k(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await A(e);return S(e,"run"),t}function I(e,n,t){return w(async(o,s,i)=>await h(async()=>{if("string"==typeof o&&o.startsWith("walker ")){const t=o.replace("walker ","");return await n(e,t,s,i)}{const a=t("string"==typeof o?{name:o}:o),{event:c,command:r}=P(e,a.name,a);return r?await n(e,r,s,i):await A(e,c)}},()=>_({ok:!1}))(),"Push",e.hooks)}async function R(e,n,t){const o=t||n.config||{init:!1},s={...n,config:o};let i=o.id;if(!i)do{i=l(4)}while(e.destinations[i]);return e.destinations[i]=s,!1!==o.queue&&(s.queue=[...e.queue]),A(e,void 0,{[i]:s})}async function A(e,n,t){const{allowed:o,consent:s,globals:i,user:a}=e;if(!o)return _({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const u=await Promise.all(Object.entries(t||{}).map(async([t,o])=>{let u=(o.queue||[]).map(e=>({...e,consent:s}));if(o.queue=[],n){let t=r(n);await Promise.all(Object.entries(o.config.policy||[]).map(async([o,s])=>{const i=await m(n,s,{collector:e});t=b(t,o,i)})),u.push(t)}if(!u.length)return{id:t,destination:o,skipped:!0};const l=[],g=u.filter(e=>{const n=d(o.config.consent,s,e.consent);return!n||(e.consent=n,l.push(e),!1)});if(o.queue.concat(g),!l.length)return{id:t,destination:o,queue:u};if(!await h(L)(e,o))return{id:t,destination:o,queue:u};let f=!1;return o.dlq||(o.dlq=[]),await Promise.all(l.map(async n=>(n.globals=c(i,n.globals),n.user=c(a,n.user),await h(U,t=>(e.config.onError&&e.config.onError(t,e),f=!0,o.dlq.push([n,t]),!1))(e,o,n),n))),{id:t,destination:o,error:f}})),l=[],g=[],f=[];for(const e of u){if(e.skipped)continue;const n=e.destination,t={id:e.id,destination:n};e.error?f.push(t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),g.push(t)):l.push(t)}return _({ok:!f.length,event:n,successful:l,queued:g,failed:f})}async function L(e,n){if(n.init&&!n.config.init){const t={collector:e,config:n.config,env:F(n.env,n.config.env)},o=await w(n.init,"DestinationInit",e.hooks)(t);if(!1===o)return o;n.config={...o||n.config,init:!0}}return!0}async function U(e,n,t){const{config:o}=n,{eventMapping:s,mappingKey:i}=await g(t,o.mapping);let a=o.data&&await m(t,o.data,{collector:e});if(s){if(s.ignore)return!1;if(s.name&&(t.name=s.name),s.data){const n=s.data&&await m(t,s.data,{collector:e});a=p(a)&&p(n)?c(a,n):n}}const r={collector:e,config:o,data:a,mapping:s,env:F(n.env,o.env)};if(s?.batch&&n.pushBatch){const c=s.batched||{key:i||"",events:[],data:[]};c.events.push(t),f(a)&&c.data.push(a),s.batchFn=s.batchFn||u((e,n)=>{const t={collector:n,config:o,data:a,mapping:s,env:F(e.env,o.env)};w(e.pushBatch,"DestinationPushBatch",n.hooks)(c,t),c.events=[],c.data=[]},s.batch),s.batched=c,s.batchFn?.(n,e)}else await w(n.push,"DestinationPush",e.hooks)(t,r);return!0}function _(e){return c({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}function B(e){return Object.entries(e).reduce((e,[n,t])=>(e[n]={...t,config:p(t.config)?t.config:{}},e),{})}function F(e,n){return e||n?n?e&&p(e)&&p(n)?{...e,...n}:n:e:{}}async function G(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=a(t,s),S(e,"consent",void 0,s),o?A(e):_({ok:!0})}import{assign as M,onLog as W}from"@walkeros/core";import{tryCatchAsync as H,getId as K}from"@walkeros/core";async function N(e,n,t){const o={disabled:t.disabled??!1,settings:t.settings??{},onError:t.onError};if(o.disabled)return{};const s=await H(n)(e,o);if(!s||!s.source)return{};const i=o.type||s.source.type||"",a=t.id||`${i}_${K(5)}`;if(s.source&&s.elb){s.source.elb=s.elb}return e.sources||(e.sources={}),e.sources[a]={type:i,settings:o.settings,mapping:void 0,elb:s.elb},s}async function T(e,n={}){for(const[t,o]of Object.entries(n)){const n={id:t},s=await N(e,o,n);if(s.source){if(s.elb){s.source.elb=s.elb}e.sources[t]={type:s.source.type,settings:s.source.config.settings,mapping:void 0,elb:s.elb}}}}async function z(e={}){const n=function(e){const{version:n}=o(),t=M({globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:s,run:!0,destinations:{},consent:{},user:{},globals:{},custom:{}},e,{merge:!1,extend:!1});function s(e,n){W({message:e},n||t.verbose)}t.onLog=s;const i={...t.globalsStatic,...t.globals},a={allowed:!1,config:t,consent:t.consent||{},count:0,custom:t.custom||{},destinations:B(t.destinations||{}),globals:i,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:t.user||{},version:n,sources:{},push:void 0};return a.push=I(a,D,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a}(e),{consent:t,user:s,globals:i,custom:a,sources:c}=e;return t&&await n.push("walker consent",t),s&&await n.push("walker user",s),i&&Object.assign(n.globals,i),a&&Object.assign(n.custom,a),c&&await T(n,c),n.config.run&&await n.push("walker run"),{collector:n,elb:n.push}}export{s as Commands,i as Const,R as addDestination,D as commonHandleCommand,z as createCollector,P as createEventOrCommand,I as createPush,_ as createPushResult,N as createSource,L as destinationInit,U as destinationPush,B as initDestinations,T as initSources,x as on,S as onApply,A as pushToDestinations,$ as runCollector,G as setConsent};//# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/handle.ts","../src/on.ts","../src/collector.ts","../src/source.ts"],"sourcesContent":["{\n \"name\": \"@walkeros/collector\",\n \"description\": \"Unified platform-agnostic collector for walkerOS\",\n \"version\": \"0.0.7\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"files\": [\n \"dist/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup --silent\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist\",\n \"dev\": \"jest --watchAll --colors\",\n \"lint\": \"tsc && eslint \\\"**/*.ts*\\\"\",\n \"test\": \"jest\",\n \"update\": \"npx npm-check-updates -u && npm update\"\n },\n \"dependencies\": {\n \"@walkeros/core\": \"0.0.7\"\n },\n \"devDependencies\": {},\n \"repository\": {\n \"url\": \"git+https://github.com/elbwalker/walkerOS.git\",\n \"directory\": \"packages/collector\"\n },\n \"author\": \"elbwalker <hello@elbwalker.com>\",\n \"homepage\": \"https://github.com/elbwalker/walkerOS#readme\",\n \"bugs\": {\n \"url\": \"https://github.com/elbwalker/walkerOS/issues\"\n },\n \"keywords\": [\n \"walker\",\n \"walkerOS\",\n \"analytics\",\n \"tracking\",\n \"data collection\",\n \"measurement\",\n \"data privacy\",\n \"privacy friendly\",\n \"collector\",\n \"event processing\"\n ],\n \"funding\": [\n {\n \"type\": \"GitHub Sponsors\",\n \"url\": \"https://github.com/sponsors/elbwalker\"\n }\n ]\n}\n","import type { Collector } from '@walkeros/core';\nimport type { WalkerOS } from '@walkeros/core';\n\nexport type CommandTypes =\n | 'Action'\n | 'Config'\n | 'Consent'\n | 'Context'\n | 'Custom'\n | 'Destination'\n | 'Elb'\n | 'Globals'\n | 'Hook'\n | 'Init'\n | 'Link'\n | 'On'\n | 'Prefix'\n | 'Ready'\n | 'Run'\n | 'Session'\n | 'User'\n | 'Walker';\n\nexport const Commands: Record<CommandTypes, Collector.CommandType> = {\n Action: 'action',\n Config: 'config',\n Consent: 'consent',\n Context: 'context',\n Custom: 'custom',\n Destination: 'destination',\n Elb: 'elb',\n Globals: 'globals',\n Hook: 'hook',\n Init: 'init',\n Link: 'link',\n On: 'on',\n Prefix: 'data-elb',\n Ready: 'ready',\n Run: 'run',\n Session: 'session',\n User: 'user',\n Walker: 'walker',\n} as const;\n\nexport type StorageType = 'cookie' | 'local' | 'session';\n\nconst UtilsStorage: { [key: string]: StorageType } = {\n Cookie: 'cookie',\n Local: 'local',\n Session: 'session',\n} as const;\n\nconst Utils = {\n Storage: UtilsStorage,\n};\n\nexport const Const = {\n Commands,\n Utils,\n};\n\nexport default Const;\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport { assign } from '@walkeros/core';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { onApply } from './on';\n\n/**\n * Sets the consent state and processes the queue.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The consent data to set.\n * @returns The result of the push operation.\n */\nexport async function setConsent(\n collector: Collector.Instance,\n data: WalkerOS.Consent,\n): Promise<Elb.PushResult> {\n const { consent } = collector;\n\n let runQueue = false;\n const update: WalkerOS.Consent = {};\n Object.entries(data).forEach(([name, granted]) => {\n const state = !!granted;\n\n update[name] = state;\n\n // Only run queue if state was set to true\n runQueue = runQueue || state;\n });\n\n // Update consent state\n collector.consent = assign(consent, update);\n\n // Run on consent events\n onApply(collector, 'consent', undefined, update);\n\n // Process previous events if not disabled\n return runQueue\n ? pushToDestinations(collector)\n : createPushResult({ ok: true });\n}\n","import type { Collector, WalkerOS, Elb, Destination } from '@walkeros/core';\nimport {\n assign,\n clone,\n createWrapper,\n debounce,\n getId,\n getGrantedConsent,\n getMappingEvent,\n getMappingValue,\n isDefined,\n isObject,\n setByPath,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEventOrCommand } from './handle';\n\nexport type HandleCommandFn<T extends Collector.Instance> = (\n collector: T,\n action: string,\n data?: Elb.PushData,\n options?: unknown,\n) => Promise<Elb.PushResult>;\n\n/**\n * Creates the main push function for the collector.\n *\n * @template T, F\n * @param collector - The walkerOS collector instance.\n * @param handleCommand - TBD.\n * @param prepareEvent - TBD.\n * @returns The push function.\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Elb.Fn {\n return useHooks(\n async (\n eventOrCommand: unknown,\n data?: Elb.PushData,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n // Handle simplified core collector interface\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n // Walker command format: 'walker action', data, options\n const command = eventOrCommand.replace('walker ', '');\n return await handleCommand(collector, command, data, options);\n } else {\n // Event format: event object or string\n const partialEvent =\n typeof eventOrCommand === 'string'\n ? { event: eventOrCommand }\n : (eventOrCommand as WalkerOS.DeepPartialEvent);\n\n const enrichedEvent = prepareEvent(partialEvent);\n\n const { event, command } = createEventOrCommand(\n collector,\n enrichedEvent.event,\n enrichedEvent,\n );\n\n const result = command\n ? await handleCommand(collector, command, data, options)\n : await pushToDestinations(collector, event);\n\n return result;\n }\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Elb.Fn;\n}\n\n/**\n * Adds a new destination to the collector.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The destination's init data.\n * @param options - The destination's config.\n * @returns The result of the push operation.\n */\nexport async function addDestination(\n collector: Collector.Instance,\n data: Destination.Init,\n options?: Destination.Config,\n): Promise<Elb.PushResult> {\n // Prefer explicit given config over default config\n const config = options || data.config || { init: false };\n // @TODO might not be the best solution to use options || data.config\n\n const destination: Destination.Instance = {\n ...data,\n config,\n };\n\n let id = 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 (config.queue !== false) destination.queue = [...collector.queue];\n\n return pushToDestinations(collector, undefined, { [id]: destination });\n}\n\n/**\n * Pushes an event to all or a subset of destinations.\n *\n * @param collector - The walkerOS collector instance.\n * @param event - The event to push.\n * @param destinations - The destinations to push to.\n * @returns The result of the push operation.\n */\nexport async function pushToDestinations(\n collector: Collector.Instance,\n event?: WalkerOS.Event,\n destinations?: Collector.Destinations,\n): Promise<Elb.PushResult> {\n const { allowed, consent, globals, user } = collector;\n\n // Check if collector is allowed to push\n if (!allowed) return createPushResult({ ok: false });\n\n // Add event to the collector queue\n if (event) collector.queue.push(event);\n\n // Use given destinations or use internal destinations\n if (!destinations) destinations = collector.destinations;\n\n const results = await Promise.all(\n // Process all destinations in parallel\n Object.entries(destinations || {}).map(async ([id, destination]) => {\n // Create a queue of events to be processed\n let currentQueue = (destination.queue || []).map((event) => ({\n ...event,\n consent,\n }));\n\n // Reset original queue while processing to enable async processing\n destination.queue = [];\n\n // Add event to queue stack\n if (event) {\n // Clone the event to avoid mutating the original event\n let currentEvent = clone(event);\n\n // Policy check\n await Promise.all(\n Object.entries(destination.config.policy || []).map(\n async ([key, mapping]) => {\n const value = await getMappingValue(event, mapping, {\n collector,\n });\n currentEvent = setByPath(currentEvent, key, value);\n },\n ),\n );\n\n // Add event to queue stack\n currentQueue.push(currentEvent);\n }\n\n // Nothing to do here if the queue is empty\n if (!currentQueue.length) return { id, destination, skipped: true };\n\n const allowedEvents: WalkerOS.Events = [];\n const skippedEvents = currentQueue.filter((queuedEvent) => {\n const grantedConsent = getGrantedConsent(\n destination.config.consent, // Required\n consent, // Current collector state\n queuedEvent.consent, // Individual event state\n );\n\n if (grantedConsent) {\n queuedEvent.consent = grantedConsent; // Save granted consent states only\n\n allowedEvents.push(queuedEvent); // Add to allowed queue\n return false; // Remove from destination queue\n }\n\n return true; // Keep denied events in the queue\n });\n\n // Add skipped events back to the queue\n destination.queue.concat(skippedEvents);\n\n // Execution shall not pass if no events are allowed\n if (!allowedEvents.length) {\n return { id, destination, queue: currentQueue }; // Don't push if not allowed\n }\n\n // Initialize the destination if needed\n const isInitialized = await tryCatchAsync(destinationInit)(\n collector,\n destination,\n );\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error = false;\n if (!destination.dlq) destination.dlq = [];\n\n // Process allowed events and store failed ones in the dead letter queue (DLQ)\n await Promise.all(\n allowedEvents.map(async (event) => {\n // Merge event with collector state, prioritizing event properties\n event.globals = assign(globals, event.globals);\n event.user = assign(user, event.user);\n\n await tryCatchAsync(destinationPush, (err) => {\n // Call custom error handling if available\n if (collector.config.onError)\n collector.config.onError(err, collector);\n error = true; // oh no\n\n // Add failed event to destinations DLQ\n destination.dlq!.push([event, err]);\n\n return false;\n })(collector, destination, event);\n\n return event;\n }),\n );\n\n return { id, destination, error };\n }),\n );\n\n const successful = [];\n const queued = [];\n const failed = [];\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n\n const ref = { id: result.id, destination };\n\n if (result.error) {\n failed.push(ref);\n } else if (result.queue && result.queue.length) {\n // Merge queue with existing queue\n destination.queue = (destination.queue || []).concat(result.queue);\n queued.push(ref);\n } else {\n successful.push(ref);\n }\n }\n\n return createPushResult({\n ok: !failed.length,\n event,\n successful,\n queued,\n failed,\n });\n}\n\n/**\n * Initializes a destination.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to initialize.\n * @returns Whether the destination was initialized successfully.\n */\nexport async function destinationInit<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n const context: Destination.Context = {\n collector,\n config: destination.config,\n wrap: getWrapper(destination, collector),\n };\n\n const configResult = await useHooks(\n destination.init,\n 'DestinationInit',\n collector.hooks,\n )(context);\n\n // Actively check for errors (when false)\n if (configResult === false) return configResult; // don't push if init is false\n\n // Update the destination config if it was returned\n destination.config = {\n ...(configResult || destination.config),\n init: true, // Remember that the destination was initialized\n };\n }\n\n return true; // Destination is ready to push\n}\n\n/**\n * Pushes an event to a single destination.\n * Handles mapping, batching, and consent checks.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to push to.\n * @param event - The event to push.\n * @returns Whether the event was pushed successfully.\n */\nexport async function destinationPush<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n event: WalkerOS.Event,\n): Promise<boolean> {\n const { config } = destination;\n const { eventMapping, mappingKey } = await getMappingEvent(\n event,\n config.mapping,\n );\n\n let data =\n config.data && (await getMappingValue(event, config.data, { collector }));\n\n if (eventMapping) {\n // Check if event should be processed or ignored\n if (eventMapping.ignore) return false;\n\n // Check to use specific event names\n if (eventMapping.name) event.event = eventMapping.name;\n\n // Transform event to a custom data\n if (eventMapping.data) {\n const dataEvent =\n eventMapping.data &&\n (await getMappingValue(event, eventMapping.data, { collector }));\n data =\n isObject(data) && isObject(dataEvent) // Only merge objects\n ? assign(data, dataEvent)\n : dataEvent;\n }\n }\n\n const context: Destination.PushContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n wrap: getWrapper(destination, collector),\n };\n\n if (eventMapping?.batch && destination.pushBatch) {\n const batched = eventMapping.batched || {\n key: mappingKey || '',\n events: [],\n data: [],\n };\n batched.events.push(event);\n if (isDefined(data)) batched.data.push(data);\n\n eventMapping.batchFn =\n eventMapping.batchFn ||\n debounce((destination, collector) => {\n const batchContext: Destination.PushBatchContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n wrap: getWrapper(destination, collector as Collector.Instance),\n };\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n (collector as Collector.Instance).hooks,\n )(batched, batchContext);\n\n // Reset the batched queues\n batched.events = [];\n batched.data = [];\n }, eventMapping.batch);\n\n eventMapping.batched = batched;\n eventMapping.batchFn?.(destination, collector);\n } else {\n // It's time to go to the destination's side now\n await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(event, context);\n }\n\n return true;\n}\n\n/**\n * Creates a standardized result object for push operations.\n *\n * @param partialResult - A partial result to merge with the default result.\n * @returns The push result.\n */\nexport function createPushResult(\n partialResult?: Partial<Elb.PushResult>,\n): Elb.PushResult {\n return assign(\n {\n ok: !partialResult?.failed?.length,\n successful: [],\n queued: [],\n failed: [],\n },\n partialResult,\n );\n}\n\n/**\n * Initializes a map of destinations.\n *\n * @param destinations - The destinations to initialize.\n * @returns The initialized destinations.\n */\nexport function initDestinations(\n destinations: Destination.InitDestinations,\n): Collector.Destinations {\n return Object.entries(destinations).reduce<Collector.Destinations>(\n (acc, [name, destination]) => {\n acc[name] = {\n ...destination,\n config: isObject(destination.config) ? destination.config : {},\n };\n return acc;\n },\n {},\n );\n}\n\nfunction getWrapper(\n destination: Destination.Instance,\n collector?: Collector.Instance,\n) {\n const wrapperConfig = destination.config.wrapper || {};\n const dryRun = destination.config.dryRun ?? collector?.config.dryRun;\n\n return createWrapper(destination.type || 'unknown', {\n ...wrapperConfig,\n ...(isDefined(dryRun) && { dryRun }),\n });\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Commands, Const } from './constants';\nimport { addDestination, pushToDestinations } from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject, isSameType } from '@walkeros/core';\nimport { setConsent } from './consent';\nimport { on, onApply } from './on';\nimport type { RunState } from './types/collector';\n\n/**\n * Handles common commands.\n *\n * @param collector The walkerOS collector instance.\n * @param action The action to handle.\n * @param data The data to handle.\n * @param options The options to handle.\n * @returns A promise that resolves with the push result or undefined.\n */\nexport async function commonHandleCommand(\n collector: Collector.Instance,\n action: string,\n data?: unknown,\n options?: unknown,\n): Promise<Elb.PushResult> {\n let result: Elb.PushResult | undefined;\n switch (action) {\n case Const.Commands.Config:\n if (isObject(data)) {\n assign(collector.config, data as Partial<Collector.Config>, {\n shallow: false,\n });\n }\n break;\n\n case Const.Commands.Consent:\n if (isObject(data)) {\n result = await setConsent(collector, data as WalkerOS.Consent);\n }\n break;\n\n case Const.Commands.Custom:\n if (isObject(data)) {\n collector.custom = assign(\n collector.custom,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.Destination:\n if (isObject(data) && isFunction(data.push)) {\n result = await addDestination(\n collector,\n data as Destination.Init,\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.Run:\n result = await runCollector(collector, data as RunState);\n break;\n\n case Const.Commands.User:\n if (isObject(data)) {\n assign(collector.user, data as WalkerOS.User, { shallow: false });\n }\n break;\n }\n\n return (\n result || {\n ok: true,\n successful: [],\n queued: [],\n failed: [],\n }\n );\n}\n\n/**\n * Creates an event or a command from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param nameOrEvent The name of the event or a partial event.\n * @param defaults The default values for the event.\n * @returns An object with the event or the command.\n */\nexport function createEventOrCommand(\n collector: Collector.Instance,\n nameOrEvent: unknown,\n defaults: WalkerOS.PartialEvent = {},\n): { event?: WalkerOS.Event; command?: string } {\n // Determine the partial event\n const partialEvent: WalkerOS.PartialEvent = isSameType(\n nameOrEvent,\n '' as string,\n )\n ? { event: nameOrEvent, ...defaults }\n : { ...defaults, ...(nameOrEvent || {}) };\n\n if (!partialEvent.event) throw new Error('Event name is required');\n\n // Check for valid entity and action event format\n const [entityValue, actionValue] = partialEvent.event.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n // It's a walker command\n if (entityValue === Commands.Walker) {\n return { command: actionValue };\n }\n\n // Regular event\n ++collector.count;\n\n // Values that are eventually used by other properties\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\n // Extract properties with default fallbacks\n const {\n event = `${entityValue} ${actionValue}`,\n data = {},\n context = {},\n globals = collector.globals,\n custom = {},\n user = collector.user,\n nested = [],\n consent = collector.consent,\n id = `${timestamp}-${group}-${count}`,\n trigger = '',\n entity = entityValue,\n action = actionValue,\n timing = 0,\n version = {\n source: collector.version,\n tagging: collector.config.tagging || 0,\n },\n source = { type: 'collector', id: '', previous_id: '' },\n } = partialEvent;\n\n const fullEvent: WalkerOS.Event = {\n event,\n data,\n context,\n globals,\n custom,\n user,\n nested,\n consent,\n id,\n trigger,\n entity,\n action,\n timestamp,\n timing,\n group,\n count,\n version,\n source,\n };\n\n return { event: fullEvent };\n}\n\n/**\n * Runs the collector by setting it to allowed state and processing queued events.\n *\n * @param collector The walkerOS collector instance.\n * @param state Optional state to merge with the collector (user, globals, consent, custom).\n * @returns A promise that resolves with the push result.\n */\nexport async function runCollector(\n collector: Collector.Instance,\n state?: RunState,\n): Promise<Elb.PushResult> {\n // Set the collector to allowed state\n collector.allowed = true;\n\n // Reset count and generate new group ID\n collector.count = 0;\n collector.group = getId();\n\n // Update timing for this run\n collector.timing = Date.now();\n\n // Update collector state if provided\n if (state) {\n // Update consent if provided\n if (state.consent) {\n collector.consent = assign(collector.consent, state.consent);\n }\n\n // Update user if provided\n if (state.user) {\n collector.user = assign(collector.user, state.user);\n }\n\n // Update globals if provided\n if (state.globals) {\n collector.globals = assign(\n collector.config.globalsStatic || {},\n state.globals,\n );\n }\n\n // Update custom if provided\n if (state.custom) {\n collector.custom = assign(collector.custom, state.custom);\n }\n }\n\n // Reset destination queues\n Object.values(collector.destinations).forEach((destination) => {\n destination.queue = [];\n });\n\n // Increase round counter\n collector.round++;\n\n // Call the predefined run events\n onApply(collector, 'run');\n\n // Process any queued events now that the collector is allowed\n const result = await pushToDestinations(collector);\n\n return result;\n}\n","import type { Collector, On, WalkerOS } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\n\n/**\n * Registers a callback for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to listen for.\n * @param option The callback function or an array of callback functions.\n */\nexport function on(\n collector: Collector.Instance,\n type: On.Types,\n option: WalkerOS.SingleOrArray<On.Options>,\n) {\n const on = collector.on;\n const onType: Array<On.Options> = on[type] || [];\n const options = isArray(option) ? option : [option];\n\n options.forEach((option) => {\n onType.push(option);\n });\n\n // Update collector on state\n (on[type] as typeof onType) = onType;\n\n // Execute the on function directly\n onApply(collector, type, options);\n}\n\n/**\n * Applies all registered callbacks for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to apply the callbacks for.\n * @param options The options for the callbacks.\n * @param config The consent configuration.\n */\nexport function onApply(\n collector: Collector.Instance,\n type: On.Types,\n options?: Array<On.Options>,\n config?: WalkerOS.Consent,\n) {\n // Use the optionally provided options\n let onConfig = options || [];\n\n if (!options) {\n // Get the collector on events\n onConfig = collector.on[type] || [];\n\n // Add all available on events from the destinations\n Object.values(collector.destinations).forEach((destination) => {\n const onTypeConfig = destination.config.on?.[type];\n if (onTypeConfig) onConfig = onConfig.concat(onTypeConfig);\n });\n }\n\n if (!onConfig.length) return; // No on-events registered, nothing to do\n\n switch (type) {\n case Const.Commands.Consent:\n onConsent(collector, onConfig as Array<On.ConsentConfig>, config);\n break;\n case Const.Commands.Ready:\n onReady(collector, onConfig as Array<On.ReadyConfig>);\n break;\n case Const.Commands.Run:\n onRun(collector, onConfig as Array<On.RunConfig>);\n break;\n case Const.Commands.Session:\n onSession(collector, onConfig as Array<On.SessionConfig>);\n break;\n default:\n break;\n }\n}\n\nfunction onConsent(\n collector: Collector.Instance,\n onConfig: Array<On.ConsentConfig>,\n currentConsent?: WalkerOS.Consent,\n): void {\n const consentState = currentConsent || collector.consent;\n\n onConfig.forEach((consentConfig) => {\n // Collect functions whose consent keys match the rule keys directly\n // Directly execute functions whose consent keys match the rule keys\n Object.keys(consentState) // consent keys\n .filter((consent) => consent in consentConfig) // check for matching rule keys\n .forEach((consent) => {\n // Execute the function\n tryCatch(consentConfig[consent])(collector, consentState);\n });\n });\n}\n\nfunction onReady(\n collector: Collector.Instance,\n onConfig: Array<On.ReadyConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onRun(\n collector: Collector.Instance,\n onConfig: Array<On.RunConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onSession(\n collector: Collector.Instance,\n onConfig: Array<On.SessionConfig>,\n): void {\n if (!collector.session) return;\n\n onConfig.forEach((func) => {\n tryCatch(func)(collector, collector.session);\n });\n}\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport type { CreateCollector, CollectorConfig } from './types';\nimport { assign, onLog } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations, createPush } from './destination';\nimport { initSources } from './source';\n\nexport async function createCollector<\n TConfig extends Partial<CollectorConfig> = Partial<CollectorConfig>,\n>(initConfig: TConfig = {} as TConfig): Promise<CreateCollector> {\n const instance = collector(initConfig);\n const { consent, user, globals, custom, sources } = initConfig;\n\n if (consent) await instance.push('walker consent', consent);\n if (user) await instance.push('walker user', user);\n if (globals) Object.assign(instance.globals, globals);\n if (custom) Object.assign(instance.custom, custom);\n\n // Initialize sources if provided\n if (sources) {\n await initSources(instance, sources);\n }\n\n if (instance.config.run) await instance.push('walker run');\n\n return {\n collector: instance,\n elb: instance.push,\n };\n}\n\nfunction collector(initConfig: Partial<CollectorConfig>): Collector.Instance {\n const { version } = require('../package.json');\n\n const defaultConfig: Collector.Config = {\n dryRun: false,\n globalsStatic: {},\n sessionStatic: {},\n tagging: 0,\n verbose: false,\n onLog: log,\n run: true,\n destinations: {},\n consent: {},\n user: {},\n globals: {},\n custom: {},\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n function log(message: string, verbose?: boolean) {\n onLog({ message }, verbose || config.verbose);\n }\n config.onLog = log;\n\n // Enhanced globals with static globals from config\n const finalGlobals = { ...config.globalsStatic, ...config.globals };\n\n const collector: Collector.Instance = {\n allowed: false,\n config,\n consent: config.consent || {},\n count: 0,\n custom: config.custom || {},\n destinations: initDestinations(config.destinations || {}),\n globals: finalGlobals,\n group: '',\n hooks: {},\n on: {},\n queue: [],\n round: 0,\n session: undefined,\n timing: Date.now(),\n user: config.user || {},\n version,\n sources: {},\n push: undefined as unknown as Elb.Fn, // Placeholder, will be set below\n };\n\n // Set the push function with the collector reference\n collector.push = createPush(\n collector,\n commonHandleCommand,\n (event: WalkerOS.DeepPartialEvent): WalkerOS.PartialEvent =>\n ({\n timing: Math.round((Date.now() - collector.timing) / 10) / 100,\n source: { type: 'collector', id: '', previous_id: '' },\n ...event,\n }) as WalkerOS.PartialEvent,\n );\n\n return collector;\n}\n","import type { Collector, WalkerOS, Source } from '@walkeros/core';\nimport { tryCatchAsync, getId } from '@walkeros/core';\n\n/**\n * Core source factory function that creates sources with consistent error handling and lifecycle management.\n *\n * @template T - The source configuration type\n * @param collector - The WalkerOS collector instance\n * @param source - The source function\n * @param config - The source configuration\n * @returns Promise resolving to the created source with its elb function\n */\nexport async function createSource<\n T extends Source.Config,\n E = WalkerOS.AnyFunction,\n>(\n collector: Collector.Instance,\n source: Source.Init<T, E>,\n config: Source.InitConfig,\n): Promise<Source.CreateSource<T, E>> {\n const fullConfig: T = {\n disabled: config.disabled ?? false,\n settings: config.settings ?? {},\n onError: config.onError, // TODO: add default onError\n } as T;\n\n if (fullConfig.disabled) return {};\n\n // Initialize the source\n const result = await tryCatchAsync(source)(collector, fullConfig);\n\n if (!result || !result.source) return {};\n\n const type = fullConfig.type || result.source.type || '';\n const id = config.id || `${type}_${getId(5)}`;\n\n // Store the elb function on the source instance for easy access\n if (result.source && result.elb) {\n const sourceWithElb = result.source as Source.Instance & { elb?: E };\n sourceWithElb.elb = result.elb;\n }\n\n // Register the source in the collector\n collector.sources[id] = {\n type,\n settings: fullConfig.settings,\n mapping: undefined, // Sources handle their own mapping\n elb: result.elb as WalkerOS.AnyFunction | undefined,\n };\n\n return result;\n}\n\n// Types for source initialization\nexport interface SourceInit<\n T extends Source.Config = Source.Config,\n E = WalkerOS.AnyFunction,\n> {\n code: Source.Init<T, E>;\n config?: Partial<T>;\n}\n\nexport interface InitSources {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [sourceId: string]: SourceInit<any, any>;\n}\n\n/**\n * Initialize multiple sources for a collector\n *\n * @param collector - The WalkerOS collector instance\n * @param sources - Map of source configurations\n */\nexport async function initSources(\n collector: Collector.Instance,\n sources: InitSources = {},\n): Promise<void> {\n for (const [sourceId, initSource] of Object.entries(sources)) {\n const { code, config = {} } = initSource;\n\n const fullConfig: Source.InitConfig = {\n id: sourceId,\n ...config,\n };\n\n const result = await createSource(collector, code, fullConfig);\n\n if (result.source) {\n // Store source with elb attached\n if (result.elb) {\n const sourceWithElb = result.source as Source.Instance & {\n elb?: WalkerOS.AnyFunction;\n };\n sourceWithElb.elb = result.elb;\n }\n // Store as CollectorSource format\n collector.sources[sourceId] = {\n type: result.source.type,\n settings: result.source.config.settings,\n mapping: undefined,\n elb: result.elb as WalkerOS.AnyFunction | undefined,\n };\n }\n }\n}\n"],"mappings":";;;;;;AAAA;AAAA;AAAA;AAAA,MACE,MAAQ;AAAA,MACR,aAAe;AAAA,MACf,SAAW;AAAA,MACX,MAAQ;AAAA,MACR,QAAU;AAAA,MACV,OAAS;AAAA,MACT,SAAW;AAAA,MACX,OAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA,SAAW;AAAA,QACT,OAAS;AAAA,QACT,OAAS;AAAA,QACT,KAAO;AAAA,QACP,MAAQ;AAAA,QACR,MAAQ;AAAA,QACR,QAAU;AAAA,MACZ;AAAA,MACA,cAAgB;AAAA,QACd,kBAAkB;AAAA,MACpB;AAAA,MACA,iBAAmB,CAAC;AAAA,MACpB,YAAc;AAAA,QACZ,KAAO;AAAA,QACP,WAAa;AAAA,MACf;AAAA,MACA,QAAU;AAAA,MACV,UAAY;AAAA,MACZ,MAAQ;AAAA,QACN,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,SAAW;AAAA,QACT;AAAA,UACE,MAAQ;AAAA,UACR,KAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAAA;AAAA;;;AC3BO,IAAM,WAAwD;AAAA,EACnE,QAAQ;AAAA,EACR,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;A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AAM,EAAE,QAAQ,GAAG,WAAW,OAAO,OAAO;AAAA,EAC9C;AACA,SAAO,QAAQ;AAGf,QAAM,eAAe,EAAE,GAAG,OAAO,eAAe,GAAG,OAAO,QAAQ;AAElE,QAAMC,aAAgC;AAAA,IACpC,SAAS;AAAA,IACT;AAAA,IACA,SAAS,OAAO,WAAW,CAAC;AAAA,IAC5B,OAAO;AAAA,IACP,QAAQ,OAAO,UAAU,CAAC;AAAA,IAC1B,cAAc,iBAAiB,OAAO,gBAAgB,CAAC,CAAC;AAAA,IACxD,SAAS;AAAA,IACT,OAAO;AAAA,IACP,OAAO,CAAC;AAAA,IACR,IAAI,CAAC;AAAA,IACL,OAAO,CAAC;AAAA,IACR,OAAO;AAAA,IACP,SAAS;AAAA,IACT,QAAQ,KAAK,IAAI;AAAA,IACjB,MAAM,OAAO,QAAQ,CAAC;AAAA,IACtB;AAAA,IACA,SAAS,CAAC;AAAA,IACV,MAAM;AAAA;AAAA,EACR;AAGA,EAAAA,WAAU,OAAO;AAAA,IACfA;AAAA,IACA;AAAA,IACA,CAAC,WACE;AAAA,MACC,QAAQ,KAAK,OAAO,KAAK,IAAI,IAAIA,WAAU,UAAU,EAAE,IAAI;AAAA,MAC3D,QAAQ,EAAE,MAAM,aAAa,IAAI,IAAI,aAAa,GAAG;AAAA,MACrD,GAAG;AAAA,IACL;AAAA,EACJ;AAEA,SAAOA;AACT;","names":["assign","assign","getId","isObject","collector","on","option","collector","collector","getId","event","assign","isObject","destination","collector","assign","assign","tryCatchAsync","getId","collector","assign","collector"]}
1
+ {"version":3,"sources":["../package.json","../src/constants.ts","../src/consent.ts","../src/destination.ts","../src/handle.ts","../src/on.ts","../src/collector.ts","../src/source.ts"],"sourcesContent":["{\n \"name\": \"@walkeros/collector\",\n \"description\": \"Unified platform-agnostic collector for walkerOS\",\n \"version\": \"0.1.0\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"files\": [\n \"dist/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup --silent\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf dist\",\n \"dev\": \"jest --watchAll --colors\",\n \"lint\": \"tsc && eslint \\\"**/*.ts*\\\"\",\n \"test\": \"jest\",\n \"update\": \"npx npm-check-updates -u && npm update\"\n },\n \"dependencies\": {\n \"@walkeros/core\": \"0.1.0\"\n },\n \"devDependencies\": {},\n \"repository\": {\n \"url\": \"git+https://github.com/elbwalker/walkerOS.git\",\n \"directory\": \"packages/collector\"\n },\n \"author\": \"elbwalker <hello@elbwalker.com>\",\n \"homepage\": \"https://github.com/elbwalker/walkerOS#readme\",\n \"bugs\": {\n \"url\": \"https://github.com/elbwalker/walkerOS/issues\"\n },\n \"keywords\": [\n \"walker\",\n \"walkerOS\",\n \"analytics\",\n \"tracking\",\n \"data collection\",\n \"measurement\",\n \"data privacy\",\n \"privacy friendly\",\n \"collector\",\n \"event processing\"\n ],\n \"funding\": [\n {\n \"type\": \"GitHub Sponsors\",\n \"url\": \"https://github.com/sponsors/elbwalker\"\n }\n ]\n}\n","import type { Collector } from '@walkeros/core';\nimport type { WalkerOS } from '@walkeros/core';\n\nexport type CommandTypes =\n | 'Action'\n | 'Actions'\n | 'Config'\n | 'Consent'\n | 'Context'\n | 'Custom'\n | 'Destination'\n | 'Elb'\n | 'Globals'\n | 'Hook'\n | 'Init'\n | 'Link'\n | 'On'\n | 'Prefix'\n | 'Ready'\n | 'Run'\n | 'Session'\n | 'User'\n | 'Walker';\n\nexport const Commands: Record<CommandTypes, Collector.CommandType> = {\n Action: 'action',\n Actions: 'actions',\n Config: 'config',\n Consent: 'consent',\n Context: 'context',\n Custom: 'custom',\n Destination: 'destination',\n Elb: 'elb',\n Globals: 'globals',\n Hook: 'hook',\n Init: 'init',\n Link: 'link',\n On: 'on',\n Prefix: 'data-elb',\n Ready: 'ready',\n Run: 'run',\n Session: 'session',\n User: 'user',\n Walker: 'walker',\n} as const;\n\nexport type StorageType = 'cookie' | 'local' | 'session';\n\nconst UtilsStorage: { [key: string]: StorageType } = {\n Cookie: 'cookie',\n Local: 'local',\n Session: 'session',\n} as const;\n\nconst Utils = {\n Storage: UtilsStorage,\n};\n\nexport const Const = {\n Commands,\n Utils,\n};\n\nexport default Const;\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport { assign } from '@walkeros/core';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { onApply } from './on';\n\n/**\n * Sets the consent state and processes the queue.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The consent data to set.\n * @returns The result of the push operation.\n */\nexport async function setConsent(\n collector: Collector.Instance,\n data: WalkerOS.Consent,\n): Promise<Elb.PushResult> {\n const { consent } = collector;\n\n let runQueue = false;\n const update: WalkerOS.Consent = {};\n Object.entries(data).forEach(([name, granted]) => {\n const state = !!granted;\n\n update[name] = state;\n\n // Only run queue if state was set to true\n runQueue = runQueue || state;\n });\n\n // Update consent state\n collector.consent = assign(consent, update);\n\n // Run on consent events\n onApply(collector, 'consent', undefined, update);\n\n // Process previous events if not disabled\n return runQueue\n ? pushToDestinations(collector)\n : createPushResult({ ok: true });\n}\n","import type { Collector, WalkerOS, Elb, Destination } from '@walkeros/core';\nimport {\n assign,\n clone,\n debounce,\n getId,\n getGrantedConsent,\n getMappingEvent,\n getMappingValue,\n isDefined,\n isObject,\n setByPath,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEventOrCommand } from './handle';\n\nexport type HandleCommandFn<T extends Collector.Instance> = (\n collector: T,\n action: string,\n data?: Elb.PushData,\n options?: unknown,\n) => Promise<Elb.PushResult>;\n\n/**\n * Creates the main push function for the collector.\n *\n * @template T, F\n * @param collector - The walkerOS collector instance.\n * @param handleCommand - TBD.\n * @param prepareEvent - TBD.\n * @returns The push function.\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Elb.Fn {\n return useHooks(\n async (\n eventOrCommand: unknown,\n data?: Elb.PushData,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n // Handle simplified core collector interface\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n // Walker command format: 'walker action', data, options\n const command = eventOrCommand.replace('walker ', '');\n return await handleCommand(collector, command, data, options);\n } else {\n // Event format: event object or string\n const partialEvent =\n typeof eventOrCommand === 'string'\n ? { name: eventOrCommand }\n : (eventOrCommand as WalkerOS.DeepPartialEvent);\n\n const enrichedEvent = prepareEvent(partialEvent);\n\n const { event, command } = createEventOrCommand(\n collector,\n enrichedEvent.name,\n enrichedEvent,\n );\n\n const result = command\n ? await handleCommand(collector, command, data, options)\n : await pushToDestinations(collector, event);\n\n return result;\n }\n },\n () => {\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n ) as Elb.Fn;\n}\n\n/**\n * Adds a new destination to the collector.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The destination's init data.\n * @param options - The destination's config.\n * @returns The result of the push operation.\n */\nexport async function addDestination(\n collector: Collector.Instance,\n data: Destination.Init,\n options?: Destination.Config,\n): Promise<Elb.PushResult> {\n // Prefer explicit given config over default config\n const config = options || data.config || { init: false };\n // @TODO might not be the best solution to use options || data.config\n\n const destination: Destination.Instance = {\n ...data,\n config,\n };\n\n let id = 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 (config.queue !== false) destination.queue = [...collector.queue];\n\n return pushToDestinations(collector, undefined, { [id]: destination });\n}\n\n/**\n * Pushes an event to all or a subset of destinations.\n *\n * @param collector - The walkerOS collector instance.\n * @param event - The event to push.\n * @param destinations - The destinations to push to.\n * @returns The result of the push operation.\n */\nexport async function pushToDestinations(\n collector: Collector.Instance,\n event?: WalkerOS.Event,\n destinations?: Collector.Destinations,\n): Promise<Elb.PushResult> {\n const { allowed, consent, globals, user } = collector;\n\n // Check if collector is allowed to push\n if (!allowed) return createPushResult({ ok: false });\n\n // Add event to the collector queue\n if (event) collector.queue.push(event);\n\n // Use given destinations or use internal destinations\n if (!destinations) destinations = collector.destinations;\n\n const results = await Promise.all(\n // Process all destinations in parallel\n Object.entries(destinations || {}).map(async ([id, destination]) => {\n // Create a queue of events to be processed\n let currentQueue = (destination.queue || []).map((event) => ({\n ...event,\n consent,\n }));\n\n // Reset original queue while processing to enable async processing\n destination.queue = [];\n\n // Add event to queue stack\n if (event) {\n // Clone the event to avoid mutating the original event\n let currentEvent = clone(event);\n\n // Policy check\n await Promise.all(\n Object.entries(destination.config.policy || []).map(\n async ([key, mapping]) => {\n const value = await getMappingValue(event, mapping, {\n collector,\n });\n currentEvent = setByPath(currentEvent, key, value);\n },\n ),\n );\n\n // Add event to queue stack\n currentQueue.push(currentEvent);\n }\n\n // Nothing to do here if the queue is empty\n if (!currentQueue.length) return { id, destination, skipped: true };\n\n const allowedEvents: WalkerOS.Events = [];\n const skippedEvents = currentQueue.filter((queuedEvent) => {\n const grantedConsent = getGrantedConsent(\n destination.config.consent, // Required\n consent, // Current collector state\n queuedEvent.consent, // Individual event state\n );\n\n if (grantedConsent) {\n queuedEvent.consent = grantedConsent; // Save granted consent states only\n\n allowedEvents.push(queuedEvent); // Add to allowed queue\n return false; // Remove from destination queue\n }\n\n return true; // Keep denied events in the queue\n });\n\n // Add skipped events back to the queue\n destination.queue.concat(skippedEvents);\n\n // Execution shall not pass if no events are allowed\n if (!allowedEvents.length) {\n return { id, destination, queue: currentQueue }; // Don't push if not allowed\n }\n\n // Initialize the destination if needed\n const isInitialized = await tryCatchAsync(destinationInit)(\n collector,\n destination,\n );\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error = false;\n if (!destination.dlq) destination.dlq = [];\n\n // Process allowed events and store failed ones in the dead letter queue (DLQ)\n await Promise.all(\n allowedEvents.map(async (event) => {\n // Merge event with collector state, prioritizing event properties\n event.globals = assign(globals, event.globals);\n event.user = assign(user, event.user);\n\n await tryCatchAsync(destinationPush, (err) => {\n // Call custom error handling if available\n if (collector.config.onError)\n collector.config.onError(err, collector);\n error = true; // oh no\n\n // Add failed event to destinations DLQ\n destination.dlq!.push([event, err]);\n\n return false;\n })(collector, destination, event);\n\n return event;\n }),\n );\n\n return { id, destination, error };\n }),\n );\n\n const successful = [];\n const queued = [];\n const failed = [];\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n\n const ref = { id: result.id, destination };\n\n if (result.error) {\n failed.push(ref);\n } else if (result.queue && result.queue.length) {\n // Merge queue with existing queue\n destination.queue = (destination.queue || []).concat(result.queue);\n queued.push(ref);\n } else {\n successful.push(ref);\n }\n }\n\n return createPushResult({\n ok: !failed.length,\n event,\n successful,\n queued,\n failed,\n });\n}\n\n/**\n * Initializes a destination.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to initialize.\n * @returns Whether the destination was initialized successfully.\n */\nexport async function destinationInit<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n const context: Destination.Context = {\n collector,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n const configResult = await useHooks(\n destination.init,\n 'DestinationInit',\n collector.hooks,\n )(context);\n\n // Actively check for errors (when false)\n if (configResult === false) return configResult; // don't push if init is false\n\n // Update the destination config if it was returned\n destination.config = {\n ...(configResult || destination.config),\n init: true, // Remember that the destination was initialized\n };\n }\n\n return true; // Destination is ready to push\n}\n\n/**\n * Pushes an event to a single destination.\n * Handles mapping, batching, and consent checks.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to push to.\n * @param event - The event to push.\n * @returns Whether the event was pushed successfully.\n */\nexport async function destinationPush<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n event: WalkerOS.Event,\n): Promise<boolean> {\n const { config } = destination;\n const { eventMapping, mappingKey } = await getMappingEvent(\n event,\n config.mapping,\n );\n\n let data =\n config.data && (await getMappingValue(event, config.data, { collector }));\n\n if (eventMapping) {\n // Check if event should be processed or ignored\n if (eventMapping.ignore) return false;\n\n // Check to use specific event names\n if (eventMapping.name) event.name = eventMapping.name;\n\n // Transform event to a custom data\n if (eventMapping.data) {\n const dataEvent =\n eventMapping.data &&\n (await getMappingValue(event, eventMapping.data, { collector }));\n data =\n isObject(data) && isObject(dataEvent) // Only merge objects\n ? assign(data, dataEvent)\n : dataEvent;\n }\n }\n\n const context: Destination.PushContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n if (eventMapping?.batch && destination.pushBatch) {\n const batched = eventMapping.batched || {\n key: mappingKey || '',\n events: [],\n data: [],\n };\n batched.events.push(event);\n if (isDefined(data)) batched.data.push(data);\n\n eventMapping.batchFn =\n eventMapping.batchFn ||\n debounce((destination, collector) => {\n const batchContext: Destination.PushBatchContext = {\n collector,\n config,\n data,\n mapping: eventMapping,\n env: mergeEnvironments(destination.env, config.env),\n };\n\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n (collector as Collector.Instance).hooks,\n )(batched, batchContext);\n\n // Reset the batched queues\n batched.events = [];\n batched.data = [];\n }, eventMapping.batch);\n\n eventMapping.batched = batched;\n eventMapping.batchFn?.(destination, collector);\n } else {\n // It's time to go to the destination's side now\n await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n )(event, context);\n }\n\n return true;\n}\n\n/**\n * Creates a standardized result object for push operations.\n *\n * @param partialResult - A partial result to merge with the default result.\n * @returns The push result.\n */\nexport function createPushResult(\n partialResult?: Partial<Elb.PushResult>,\n): Elb.PushResult {\n return assign(\n {\n ok: !partialResult?.failed?.length,\n successful: [],\n queued: [],\n failed: [],\n },\n partialResult,\n );\n}\n\n/**\n * Initializes a map of destinations.\n *\n * @param destinations - The destinations to initialize.\n * @returns The initialized destinations.\n */\nexport function initDestinations(\n destinations: Destination.InitDestinations,\n): Collector.Destinations {\n return Object.entries(destinations).reduce<Collector.Destinations>(\n (acc, [name, destination]) => {\n acc[name] = {\n ...destination,\n config: isObject(destination.config) ? destination.config : {},\n };\n return acc;\n },\n {},\n );\n}\n\n/**\n * Merges destination environment with config environment\n * Config env takes precedence over destination env for overrides\n */\nfunction mergeEnvironments(\n destinationEnv?: Destination.Environment,\n configEnv?: Destination.Environment,\n): Destination.Environment {\n // If neither environment exists, return empty object\n if (!destinationEnv && !configEnv) return {};\n\n // If only one exists, return it\n if (!configEnv) return destinationEnv!;\n if (!destinationEnv) return configEnv;\n\n // Both exist - merge objects with configEnv taking precedence\n if (isObject(destinationEnv) && isObject(configEnv)) {\n return { ...destinationEnv, ...configEnv };\n }\n\n // If they're not both objects, config env overrides destination env\n return configEnv;\n}\n","import type { Collector, WalkerOS, Destination, Elb, On } from '@walkeros/core';\nimport { Commands, Const } from './constants';\nimport { addDestination, pushToDestinations } from './destination';\nimport { assign, getId, isFunction, isString } from '@walkeros/core';\nimport { isObject, isSameType } from '@walkeros/core';\nimport { setConsent } from './consent';\nimport { on, onApply } from './on';\nimport type { RunState } from './types/collector';\n\n/**\n * Handles common commands.\n *\n * @param collector The walkerOS collector instance.\n * @param action The action to handle.\n * @param data The data to handle.\n * @param options The options to handle.\n * @returns A promise that resolves with the push result or undefined.\n */\nexport async function commonHandleCommand(\n collector: Collector.Instance,\n action: string,\n data?: unknown,\n options?: unknown,\n): Promise<Elb.PushResult> {\n let result: Elb.PushResult | undefined;\n switch (action) {\n case Const.Commands.Config:\n if (isObject(data)) {\n assign(collector.config, data as Partial<Collector.Config>, {\n shallow: false,\n });\n }\n break;\n\n case Const.Commands.Consent:\n if (isObject(data)) {\n result = await setConsent(collector, data as WalkerOS.Consent);\n }\n break;\n\n case Const.Commands.Custom:\n if (isObject(data)) {\n collector.custom = assign(\n collector.custom,\n data as WalkerOS.Properties,\n );\n }\n break;\n\n case Const.Commands.Destination:\n if (isObject(data) && isFunction(data.push)) {\n result = await addDestination(\n collector,\n data as Destination.Init,\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.Run:\n result = await runCollector(collector, data as RunState);\n break;\n\n case Const.Commands.User:\n if (isObject(data)) {\n assign(collector.user, data as WalkerOS.User, { shallow: false });\n }\n break;\n }\n\n return (\n result || {\n ok: true,\n successful: [],\n queued: [],\n failed: [],\n }\n );\n}\n\n/**\n * Creates an event or a command from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param nameOrEvent The name of the event or a partial event.\n * @param defaults The default values for the event.\n * @returns An object with the event or the command.\n */\nexport function createEventOrCommand(\n collector: Collector.Instance,\n nameOrEvent: unknown,\n defaults: WalkerOS.PartialEvent = {},\n): { event?: WalkerOS.Event; command?: string } {\n // Determine the partial event\n const partialEvent: WalkerOS.PartialEvent = isSameType(\n nameOrEvent,\n '' as string,\n )\n ? { name: nameOrEvent, ...defaults }\n : { ...defaults, ...(nameOrEvent || {}) };\n\n if (!partialEvent.name) throw new Error('Event name is required');\n\n // Check for valid entity and action event format\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n // It's a walker command\n if (entityValue === Commands.Walker) {\n return { command: actionValue };\n }\n\n // Regular event\n ++collector.count;\n\n // Values that are eventually used by other properties\n const {\n timestamp = Date.now(),\n group = collector.group,\n count = collector.count,\n } = partialEvent;\n\n // Extract properties with default fallbacks\n const {\n name = `${entityValue} ${actionValue}`,\n data = {},\n context = {},\n globals = collector.globals,\n custom = {},\n user = collector.user,\n nested = [],\n consent = collector.consent,\n id = `${timestamp}-${group}-${count}`,\n trigger = '',\n entity = entityValue,\n action = actionValue,\n timing = 0,\n version = {\n source: collector.version,\n tagging: collector.config.tagging || 0,\n },\n source = { type: 'collector', id: '', previous_id: '' },\n } = partialEvent;\n\n const fullEvent: WalkerOS.Event = {\n name,\n data,\n context,\n globals,\n custom,\n user,\n nested,\n consent,\n id,\n trigger,\n entity,\n action,\n timestamp,\n timing,\n group,\n count,\n version,\n source,\n };\n\n return { event: fullEvent };\n}\n\n/**\n * Runs the collector by setting it to allowed state and processing queued events.\n *\n * @param collector The walkerOS collector instance.\n * @param state Optional state to merge with the collector (user, globals, consent, custom).\n * @returns A promise that resolves with the push result.\n */\nexport async function runCollector(\n collector: Collector.Instance,\n state?: RunState,\n): Promise<Elb.PushResult> {\n // Set the collector to allowed state\n collector.allowed = true;\n\n // Reset count and generate new group ID\n collector.count = 0;\n collector.group = getId();\n\n // Update timing for this run\n collector.timing = Date.now();\n\n // Update collector state if provided\n if (state) {\n // Update consent if provided\n if (state.consent) {\n collector.consent = assign(collector.consent, state.consent);\n }\n\n // Update user if provided\n if (state.user) {\n collector.user = assign(collector.user, state.user);\n }\n\n // Update globals if provided\n if (state.globals) {\n collector.globals = assign(\n collector.config.globalsStatic || {},\n state.globals,\n );\n }\n\n // Update custom if provided\n if (state.custom) {\n collector.custom = assign(collector.custom, state.custom);\n }\n }\n\n // Reset destination queues\n Object.values(collector.destinations).forEach((destination) => {\n destination.queue = [];\n });\n\n // Reset collector queue for this run\n collector.queue = [];\n\n // Increase round counter\n collector.round++;\n\n // Process any queued events now that the collector is allowed\n const result = await pushToDestinations(collector);\n\n // Call the predefined run events\n onApply(collector, 'run');\n\n return result;\n}\n","import type { Collector, On, WalkerOS } from '@walkeros/core';\nimport { isArray } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch } from '@walkeros/core';\n\n/**\n * Registers a callback for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to listen for.\n * @param option The callback function or an array of callback functions.\n */\nexport function on(\n collector: Collector.Instance,\n type: On.Types,\n option: WalkerOS.SingleOrArray<On.Options>,\n) {\n const on = collector.on;\n const onType: Array<On.Options> = on[type] || [];\n const options = isArray(option) ? option : [option];\n\n options.forEach((option) => {\n onType.push(option);\n });\n\n // Update collector on state\n (on[type] as typeof onType) = onType;\n\n // Execute the on function directly\n onApply(collector, type, options);\n}\n\n/**\n * Applies all registered callbacks for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to apply the callbacks for.\n * @param options The options for the callbacks.\n * @param config The consent configuration.\n */\nexport function onApply(\n collector: Collector.Instance,\n type: On.Types,\n options?: Array<On.Options>,\n config?: WalkerOS.Consent,\n) {\n // Use the optionally provided options\n let onConfig = options || [];\n\n if (!options) {\n // Get the collector on events\n onConfig = collector.on[type] || [];\n\n // Add all available on events from the destinations\n Object.values(collector.destinations).forEach((destination) => {\n const onTypeConfig = destination.config.on?.[type];\n if (onTypeConfig) onConfig = onConfig.concat(onTypeConfig);\n });\n }\n\n if (!onConfig.length) return; // No on-events registered, nothing to do\n\n switch (type) {\n case Const.Commands.Consent:\n onConsent(collector, onConfig as Array<On.ConsentConfig>, config);\n break;\n case Const.Commands.Ready:\n onReady(collector, onConfig as Array<On.ReadyConfig>);\n break;\n case Const.Commands.Run:\n onRun(collector, onConfig as Array<On.RunConfig>);\n break;\n case Const.Commands.Session:\n onSession(collector, onConfig as Array<On.SessionConfig>);\n break;\n default:\n break;\n }\n}\n\nfunction onConsent(\n collector: Collector.Instance,\n onConfig: Array<On.ConsentConfig>,\n currentConsent?: WalkerOS.Consent,\n): void {\n const consentState = currentConsent || collector.consent;\n\n onConfig.forEach((consentConfig) => {\n // Collect functions whose consent keys match the rule keys directly\n // Directly execute functions whose consent keys match the rule keys\n Object.keys(consentState) // consent keys\n .filter((consent) => consent in consentConfig) // check for matching rule keys\n .forEach((consent) => {\n // Execute the function\n tryCatch(consentConfig[consent])(collector, consentState);\n });\n });\n}\n\nfunction onReady(\n collector: Collector.Instance,\n onConfig: Array<On.ReadyConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onRun(\n collector: Collector.Instance,\n onConfig: Array<On.RunConfig>,\n): void {\n if (collector.allowed)\n onConfig.forEach((func) => {\n tryCatch(func)(collector);\n });\n}\n\nfunction onSession(\n collector: Collector.Instance,\n onConfig: Array<On.SessionConfig>,\n): void {\n if (!collector.session) return;\n\n onConfig.forEach((func) => {\n tryCatch(func)(collector, collector.session);\n });\n}\n","import type { Collector, WalkerOS, Elb } from '@walkeros/core';\nimport type { CreateCollector, CollectorConfig } from './types';\nimport { assign, onLog } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations, createPush } from './destination';\nimport { initSources } from './source';\n\nexport async function createCollector<\n TConfig extends Partial<CollectorConfig> = Partial<CollectorConfig>,\n>(initConfig: TConfig = {} as TConfig): Promise<CreateCollector> {\n const instance = collector(initConfig);\n const { consent, user, globals, custom, sources } = initConfig;\n\n if (consent) await instance.push('walker consent', consent);\n if (user) await instance.push('walker user', user);\n if (globals) Object.assign(instance.globals, globals);\n if (custom) Object.assign(instance.custom, custom);\n\n // Initialize sources if provided\n if (sources) {\n await initSources(instance, sources);\n }\n\n if (instance.config.run) await instance.push('walker run');\n\n return {\n collector: instance,\n elb: instance.push,\n };\n}\n\nfunction collector(initConfig: Partial<CollectorConfig>): Collector.Instance {\n const { version } = require('../package.json');\n\n const defaultConfig: Collector.Config = {\n globalsStatic: {},\n sessionStatic: {},\n tagging: 0,\n verbose: false,\n onLog: log,\n run: true,\n destinations: {},\n consent: {},\n user: {},\n globals: {},\n custom: {},\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n function log(message: string, verbose?: boolean) {\n onLog({ message }, verbose || config.verbose);\n }\n config.onLog = log;\n\n // Enhanced globals with static globals from config\n const finalGlobals = { ...config.globalsStatic, ...config.globals };\n\n const collector: Collector.Instance = {\n allowed: false,\n config,\n consent: config.consent || {},\n count: 0,\n custom: config.custom || {},\n destinations: initDestinations(config.destinations || {}),\n globals: finalGlobals,\n group: '',\n hooks: {},\n on: {},\n queue: [],\n round: 0,\n session: undefined,\n timing: Date.now(),\n user: config.user || {},\n version,\n sources: {},\n push: undefined as unknown as Elb.Fn, // Placeholder, will be set below\n };\n\n // Set the push function with the collector reference\n collector.push = createPush(\n collector,\n commonHandleCommand,\n (event: WalkerOS.DeepPartialEvent): WalkerOS.PartialEvent =>\n ({\n timing: Math.round((Date.now() - collector.timing) / 10) / 100,\n source: { type: 'collector', id: '', previous_id: '' },\n ...event,\n }) as WalkerOS.PartialEvent,\n );\n\n return collector;\n}\n","import type { Collector, WalkerOS, Source } from '@walkeros/core';\nimport { tryCatchAsync, getId } from '@walkeros/core';\n\n/**\n * Core source factory function that creates sources with consistent error handling and lifecycle management.\n *\n * @template T - The source configuration type\n * @param collector - The WalkerOS collector instance\n * @param source - The source function\n * @param config - The source configuration\n * @returns Promise resolving to the created source with its elb function\n */\nexport async function createSource<\n T extends Source.Config,\n E = WalkerOS.AnyFunction,\n>(\n collector: Collector.Instance,\n source: Source.Init<T, E>,\n config: Source.InitConfig,\n): Promise<Source.CreateSource<T, E>> {\n const fullConfig: T = {\n disabled: config.disabled ?? false,\n settings: config.settings ?? {},\n onError: config.onError, // TODO: add default onError\n } as T;\n\n if (fullConfig.disabled) {\n return {};\n }\n\n // Initialize the source\n const result = await tryCatchAsync(source)(collector, fullConfig);\n\n if (!result || !result.source) {\n return {};\n }\n\n const type = fullConfig.type || result.source.type || '';\n const id = config.id || `${type}_${getId(5)}`;\n\n // Store the elb function on the source instance for easy access\n if (result.source && result.elb) {\n const sourceWithElb = result.source as Source.Instance & { elb?: E };\n sourceWithElb.elb = result.elb;\n }\n\n // Register the source in the collector (ensure sources object exists)\n if (!collector.sources) {\n collector.sources = {};\n }\n collector.sources[id] = {\n type,\n settings: fullConfig.settings,\n mapping: undefined, // Sources handle their own mapping\n elb: result.elb as WalkerOS.AnyFunction | undefined,\n };\n\n return result;\n}\n\n// Types for source initialization\nexport interface InitSources {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [sourceId: string]: Source.Init<any, any>;\n}\n\n/**\n * Initialize multiple sources for a collector\n *\n * @param collector - The WalkerOS collector instance\n * @param sources - Map of source configurations\n */\nexport async function initSources(\n collector: Collector.Instance,\n sources: InitSources = {},\n): Promise<void> {\n for (const [sourceId, sourceInit] of Object.entries(sources)) {\n const fullConfig: Source.InitConfig = {\n id: sourceId,\n };\n\n const result = await createSource(collector, sourceInit, fullConfig);\n\n if (result.source) {\n // Store source with elb attached\n if (result.elb) {\n const sourceWithElb = result.source as Source.Instance & {\n elb?: WalkerOS.AnyFunction;\n };\n sourceWithElb.elb = result.elb;\n }\n // Store as CollectorSource format\n collector.sources[sourceId] = {\n type: result.source.type,\n settings: result.source.config.settings,\n mapping: undefined,\n elb: result.elb as WalkerOS.AnyFunction | undefined,\n };\n }\n }\n}\n"],"mappings":";;;;;;AAAA;AAAA;AAAA;AAAA,MACE,MAAQ;AAAA,MACR,aAAe;AAAA,MACf,SAAW;AAAA,MACX,MAAQ;AAAA,MACR,QAAU;AAAA,MACV,OAAS;AAAA,MACT,SAAW;AAAA,MACX,OAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA,SAAW;AAAA,QACT,OAAS;AAAA,QACT,OAAS;AAAA,QACT,KAAO;AAAA,QACP,MAAQ;AAAA,QACR,MAAQ;AAAA,QACR,QAAU;AAAA,MACZ;AAAA,MACA,cAAgB;AAAA,QACd,kBAAkB;AAAA,MACpB;AAAA,MACA,iBAAmB,CAAC;AAAA,MACpB,YAAc;AAAA,QACZ,KAAO;AAAA,QACP,WAAa;AAAA,MACf;AAAA,MACA,QAAU;AAAA,MACV,UAAY;AAAA,MACZ,MAAQ;AAAA,QACN,KAAO;AA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AAQ,CAAC;AAAA,IACtB;AAAA,IACA,SAAS,CAAC;AAAA,IACV,MAAM;AAAA;AAAA,EACR;AAGA,EAAAA,WAAU,OAAO;AAAA,IACfA;AAAA,IACA;AAAA,IACA,CAAC,WACE;AAAA,MACC,QAAQ,KAAK,OAAO,KAAK,IAAI,IAAIA,WAAU,UAAU,EAAE,IAAI;AAAA,MAC3D,QAAQ,EAAE,MAAM,aAAa,IAAI,IAAI,aAAa,GAAG;AAAA,MACrD,GAAG;AAAA,IACL;AAAA,EACJ;AAEA,SAAOA;AACT;","names":["assign","assign","getId","isObject","collector","on","option","collector","collector","getId","event","assign","isObject","destination","collector","assign","assign","tryCatchAsync","getId","collector","assign","collector"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@walkeros/collector",
3
3
  "description": "Unified platform-agnostic collector for walkerOS",
4
- "version": "0.0.7",
4
+ "version": "0.1.0",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "update": "npx npm-check-updates -u && npm update"
19
19
  },
20
20
  "dependencies": {
21
- "@walkeros/core": "0.0.7"
21
+ "@walkeros/core": "0.1.0"
22
22
  },
23
23
  "devDependencies": {},
24
24
  "repository": {