@walkeros/collector 0.5.1-next.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/auto-run.test.d.ts +2 -0
- package/dist/__tests__/auto-run.test.d.ts.map +1 -0
- package/dist/__tests__/auto-run.test.js +102 -0
- package/dist/__tests__/auto-run.test.js.map +1 -0
- package/dist/__tests__/consent.test.d.ts +2 -0
- package/dist/__tests__/consent.test.d.ts.map +1 -0
- package/dist/__tests__/consent.test.js +21 -0
- package/dist/__tests__/consent.test.js.map +1 -0
- package/dist/__tests__/create-flow.test.d.ts +2 -0
- package/dist/__tests__/create-flow.test.d.ts.map +1 -0
- package/dist/__tests__/create-flow.test.js +69 -0
- package/dist/__tests__/create-flow.test.js.map +1 -0
- package/dist/__tests__/destination-code.test.d.ts +2 -0
- package/dist/__tests__/destination-code.test.d.ts.map +1 -0
- package/dist/__tests__/destination-code.test.js +396 -0
- package/dist/__tests__/destination-code.test.js.map +1 -0
- package/dist/__tests__/destination.test.d.ts +2 -0
- package/dist/__tests__/destination.test.d.ts.map +1 -0
- package/dist/__tests__/destination.test.js +471 -0
- package/dist/__tests__/destination.test.js.map +1 -0
- package/dist/__tests__/handle.test.d.ts +2 -0
- package/dist/__tests__/handle.test.d.ts.map +1 -0
- package/dist/__tests__/handle.test.js +78 -0
- package/dist/__tests__/handle.test.js.map +1 -0
- package/dist/__tests__/mapping.test.d.ts +2 -0
- package/dist/__tests__/mapping.test.d.ts.map +1 -0
- package/dist/__tests__/mapping.test.js +310 -0
- package/dist/__tests__/mapping.test.js.map +1 -0
- package/dist/__tests__/source.test.d.ts +2 -0
- package/dist/__tests__/source.test.d.ts.map +1 -0
- package/dist/__tests__/source.test.js +306 -0
- package/dist/__tests__/source.test.js.map +1 -0
- package/dist/__tests__/start-flow.test.d.ts +2 -0
- package/dist/__tests__/start-flow.test.d.ts.map +1 -0
- package/dist/__tests__/start-flow.test.js +167 -0
- package/dist/__tests__/start-flow.test.js.map +1 -0
- package/dist/__tests__/walker-entity.test.d.ts +2 -0
- package/dist/__tests__/walker-entity.test.d.ts.map +1 -0
- package/dist/__tests__/walker-entity.test.js +52 -0
- package/dist/__tests__/walker-entity.test.js.map +1 -0
- package/dist/collector.d.ts +3 -0
- package/dist/collector.d.ts.map +1 -0
- package/dist/collector.js +60 -0
- package/dist/collector.js.map +1 -0
- package/dist/command.d.ts +12 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +20 -0
- package/dist/command.js.map +1 -0
- package/dist/consent.d.ts +10 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.js +30 -0
- package/dist/consent.js.map +1 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +35 -0
- package/dist/constants.js.map +1 -0
- package/dist/destination-code.d.ts +4 -0
- package/dist/destination-code.d.ts.map +1 -0
- package/dist/destination-code.js +72 -0
- package/dist/destination-code.js.map +1 -0
- package/dist/destination.d.ts +61 -0
- package/dist/destination.d.ts.map +1 -0
- package/dist/destination.js +325 -0
- package/dist/destination.js.map +1 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/elb.d.ts +11 -0
- package/dist/elb.d.ts.map +1 -0
- package/dist/elb.js +60 -0
- package/dist/elb.js.map +1 -0
- package/dist/flow.d.ts +4 -0
- package/dist/flow.d.ts.map +1 -0
- package/dist/flow.js +44 -0
- package/dist/flow.js.map +1 -0
- package/dist/handle.d.ts +29 -0
- package/dist/handle.d.ts.map +1 -0
- package/dist/handle.js +161 -0
- package/dist/handle.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/on.d.ts +19 -0
- package/dist/on.d.ts.map +1 -0
- package/dist/on.js +127 -0
- package/dist/on.js.map +1 -0
- package/dist/push.d.ts +11 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +43 -0
- package/dist/push.js.map +1 -0
- package/dist/source.d.ts +10 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +47 -0
- package/dist/source.js.map +1 -0
- package/dist/types/code.d.ts +23 -0
- package/dist/types/code.d.ts.map +1 -0
- package/dist/types/code.js +2 -0
- package/dist/types/code.js.map +1 -0
- package/dist/types/collector.d.ts +19 -0
- package/dist/types/collector.d.ts.map +1 -0
- package/dist/types/collector.js +2 -0
- package/dist/types/collector.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +2 -2
package/dist/handle.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Const } from './constants';
|
|
2
|
+
import { addDestination, pushToDestinations } from './destination';
|
|
3
|
+
import { assign, getId, isFunction, isString } from '@walkeros/core';
|
|
4
|
+
import { isObject } from '@walkeros/core';
|
|
5
|
+
import { setConsent } from './consent';
|
|
6
|
+
import { on, onApply } from './on';
|
|
7
|
+
/**
|
|
8
|
+
* Handles common commands.
|
|
9
|
+
*
|
|
10
|
+
* @param collector The walkerOS collector instance.
|
|
11
|
+
* @param action The action to handle.
|
|
12
|
+
* @param data The data to handle.
|
|
13
|
+
* @param options The options to handle.
|
|
14
|
+
* @returns A promise that resolves with the push result or undefined.
|
|
15
|
+
*/
|
|
16
|
+
export async function commonHandleCommand(collector, action, data, options) {
|
|
17
|
+
let result;
|
|
18
|
+
switch (action) {
|
|
19
|
+
case Const.Commands.Config:
|
|
20
|
+
if (isObject(data)) {
|
|
21
|
+
assign(collector.config, data, {
|
|
22
|
+
shallow: false,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
case Const.Commands.Consent:
|
|
27
|
+
if (isObject(data)) {
|
|
28
|
+
result = await setConsent(collector, data);
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
case Const.Commands.Custom:
|
|
32
|
+
if (isObject(data)) {
|
|
33
|
+
collector.custom = assign(collector.custom, data);
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
case Const.Commands.Destination:
|
|
37
|
+
if (isObject(data) && isFunction(data.push)) {
|
|
38
|
+
result = await addDestination(collector, { code: data }, options);
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case Const.Commands.Globals:
|
|
42
|
+
if (isObject(data)) {
|
|
43
|
+
collector.globals = assign(collector.globals, data);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case Const.Commands.On:
|
|
47
|
+
if (isString(data)) {
|
|
48
|
+
on(collector, data, options);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case Const.Commands.Ready:
|
|
52
|
+
onApply(collector, 'ready');
|
|
53
|
+
break;
|
|
54
|
+
case Const.Commands.Run:
|
|
55
|
+
result = await runCollector(collector, data);
|
|
56
|
+
break;
|
|
57
|
+
case Const.Commands.Session:
|
|
58
|
+
onApply(collector, 'session');
|
|
59
|
+
break;
|
|
60
|
+
case Const.Commands.User:
|
|
61
|
+
if (isObject(data)) {
|
|
62
|
+
assign(collector.user, data, { shallow: false });
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
return (result || {
|
|
67
|
+
ok: true,
|
|
68
|
+
successful: [],
|
|
69
|
+
queued: [],
|
|
70
|
+
failed: [],
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a full event from a partial event.
|
|
75
|
+
*
|
|
76
|
+
* @param collector The walkerOS collector instance.
|
|
77
|
+
* @param partialEvent The partial event to transform.
|
|
78
|
+
* @returns The full event.
|
|
79
|
+
*/
|
|
80
|
+
export function createEvent(collector, partialEvent) {
|
|
81
|
+
if (!partialEvent.name)
|
|
82
|
+
throw new Error('Event name is required');
|
|
83
|
+
const [entityValue, actionValue] = partialEvent.name.split(' ');
|
|
84
|
+
if (!entityValue || !actionValue)
|
|
85
|
+
throw new Error('Event name is invalid');
|
|
86
|
+
++collector.count;
|
|
87
|
+
const { timestamp = Date.now(), group = collector.group, count = collector.count, } = partialEvent;
|
|
88
|
+
const { name = `${entityValue} ${actionValue}`, data = {}, context = {}, globals = collector.globals, custom = {}, user = collector.user, nested = [], consent = collector.consent, id = `${timestamp}-${group}-${count}`, trigger = '', entity = entityValue, action = actionValue, timing = 0, version = {
|
|
89
|
+
source: collector.version,
|
|
90
|
+
tagging: collector.config.tagging || 0,
|
|
91
|
+
}, source = { type: 'collector', id: '', previous_id: '' }, } = partialEvent;
|
|
92
|
+
return {
|
|
93
|
+
name,
|
|
94
|
+
data,
|
|
95
|
+
context,
|
|
96
|
+
globals,
|
|
97
|
+
custom,
|
|
98
|
+
user,
|
|
99
|
+
nested,
|
|
100
|
+
consent,
|
|
101
|
+
id,
|
|
102
|
+
trigger,
|
|
103
|
+
entity,
|
|
104
|
+
action,
|
|
105
|
+
timestamp,
|
|
106
|
+
timing,
|
|
107
|
+
group,
|
|
108
|
+
count,
|
|
109
|
+
version,
|
|
110
|
+
source,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Runs the collector by setting it to allowed state and processing queued events.
|
|
115
|
+
*
|
|
116
|
+
* @param collector The walkerOS collector instance.
|
|
117
|
+
* @param state Optional state to merge with the collector (user, globals, consent, custom).
|
|
118
|
+
* @returns A promise that resolves with the push result.
|
|
119
|
+
*/
|
|
120
|
+
export async function runCollector(collector, state) {
|
|
121
|
+
// Set the collector to allowed state
|
|
122
|
+
collector.allowed = true;
|
|
123
|
+
// Reset count and generate new group ID
|
|
124
|
+
collector.count = 0;
|
|
125
|
+
collector.group = getId();
|
|
126
|
+
// Update timing for this run
|
|
127
|
+
collector.timing = Date.now();
|
|
128
|
+
// Update collector state if provided
|
|
129
|
+
if (state) {
|
|
130
|
+
// Update consent if provided
|
|
131
|
+
if (state.consent) {
|
|
132
|
+
collector.consent = assign(collector.consent, state.consent);
|
|
133
|
+
}
|
|
134
|
+
// Update user if provided
|
|
135
|
+
if (state.user) {
|
|
136
|
+
collector.user = assign(collector.user, state.user);
|
|
137
|
+
}
|
|
138
|
+
// Update globals if provided
|
|
139
|
+
if (state.globals) {
|
|
140
|
+
collector.globals = assign(collector.config.globalsStatic || {}, state.globals);
|
|
141
|
+
}
|
|
142
|
+
// Update custom if provided
|
|
143
|
+
if (state.custom) {
|
|
144
|
+
collector.custom = assign(collector.custom, state.custom);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Reset destination queues
|
|
148
|
+
Object.values(collector.destinations).forEach((destination) => {
|
|
149
|
+
destination.queue = [];
|
|
150
|
+
});
|
|
151
|
+
// Reset collector queue for this run
|
|
152
|
+
collector.queue = [];
|
|
153
|
+
// Increase round counter
|
|
154
|
+
collector.round++;
|
|
155
|
+
// Process any queued events now that the collector is allowed
|
|
156
|
+
const result = await pushToDestinations(collector);
|
|
157
|
+
// Call the predefined run events
|
|
158
|
+
onApply(collector, 'run');
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGnC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,SAA6B,EAC7B,MAAc,EACd,IAAc,EACd,OAAiB;IAEjB,IAAI,MAAkC,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,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AAExB,cAAc,aAAa,CAAC;AAE5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,n=Object.defineProperty,t=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,a={};((e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})})(a,{Code:()=>c,Commands:()=>i,Const:()=>r,addDestination:()=>f,commonHandleCommand:()=>D,createEvent:()=>P,createPush:()=>R,createPushResult:()=>b,destinationCode:()=>g,destinationInit:()=>m,destinationPush:()=>h,initDestinations:()=>y,initSources:()=>I,mergeEnvironments:()=>v,on:()=>C,onApply:()=>q,pushToDestinations:()=>p,runCollector:()=>x,setConsent:()=>j,startFlow:()=>$}),module.exports=(e=a,((e,a,c,i)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of o(a))s.call(e,r)||r===c||n(e,r,{get:()=>a[r],enumerable:!(i=t(a,r))||i.enumerable});return e})(n({},"__esModule",{value:!0}),e));var c={},i={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},r={Commands:i,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},u=require("@walkeros/core"),l=require("@walkeros/core"),g={type:"code",config:{},init(e){const{config:n,logger:t}=e,o=n.settings,s=o?.scripts;if(s&&"undefined"!=typeof document)for(const e of s){const n=document.createElement("script");n.src=e,n.async=!0,document.head.appendChild(n)}const a=o?.init;if(a)try{new Function("context",a)(e)}catch(e){t.error("Code destination init error:",e)}},push(e,n){const{mapping:t,config:o,logger:s}=n,a=t?.push??o.settings?.push;if(a)try{new Function("event","context",a)(e,n)}catch(e){s.error("Code destination push error:",e)}},pushBatch(e,n){const{mapping:t,config:o,logger:s}=n,a=t?.pushBatch??o.settings?.pushBatch;if(a)try{new Function("batch","context",a)(e,n)}catch(e){s.error("Code destination pushBatch error:",e)}},on(e,n){const{config:t,logger:o}=n,s=t.settings?.on;if(s)try{new Function("type","context",s)(e,n)}catch(e){o.error("Code destination on error:",e)}}};function d(e){return!0===e?g:e}async function f(e,n,t){const{code:o,config:s={},env:a={}}=n,c=t||s||{init:!1},i=d(o),r={...i,config:c,env:v(i.env,a)};let u=r.config.id;if(!u)do{u=(0,l.getId)(4)}while(e.destinations[u]);return e.destinations[u]=r,!1!==r.config.queue&&(r.queue=[...e.queue]),p(e,void 0,{[u]:r})}async function p(e,n,t){const{allowed:o,consent:s,globals:a,user:c}=e;if(!o)return b({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const i=await Promise.all(Object.entries(t||{}).map(async([t,o])=>{let i=(o.queue||[]).map(e=>({...e,consent:s}));if(o.queue=[],n){const e=(0,l.clone)(n);i.push(e)}if(!i.length)return{id:t,destination:o,skipped:!0};const r=[],u=i.filter(e=>{const n=(0,l.getGrantedConsent)(o.config.consent,s,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(o.queue.concat(u),!r.length)return{id:t,destination:o,queue:i};if(!await(0,l.tryCatchAsync)(m)(e,o))return{id:t,destination:o,queue:i};let g=!1;return o.dlq||(o.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,l.assign)(a,n.globals),n.user=(0,l.assign)(c,n.user),await(0,l.tryCatchAsync)(h,t=>{const s=o.type||"unknown";return e.logger.scope(s).error("Push failed",{error:t,event:n.name}),g=!0,o.dlq.push([n,t]),!1})(e,o,n),n))),{id:t,destination:o,error:g}})),r=[],u=[],g=[];for(const e of i){if(e.skipped)continue;const n=e.destination,t={id:e.id,destination:n};e.error?g.push(t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),u.push(t)):r.push(t)}return b({ok:!g.length,event:n,successful:r,queued:u,failed:g})}async function m(e,n){if(n.init&&!n.config.init){const t=n.type||"unknown",o=e.logger.scope(t),s={collector:e,config:n.config,env:v(n.env,n.config.env),logger:o};o.debug("init");const a=await(0,l.useHooks)(n.init,"DestinationInit",e.hooks)(s);if(!1===a)return a;n.config={...a||n.config,init:!0},o.debug("init done")}return!0}async function h(e,n,t){const{config:o}=n,s=await(0,l.processEventMapping)(t,o,e);if(s.ignore)return!1;const a=n.type||"unknown",c=e.logger.scope(a),i={collector:e,config:o,data:s.data,mapping:s.mapping,env:v(n.env,o.env),logger:c},r=s.mapping,u=s.mappingKey||"* *";if(r?.batch&&n.pushBatch){if(n.batches=n.batches||{},!n.batches[u]){const t={key:u,events:[],data:[]};n.batches[u]={batched:t,batchFn:(0,l.debounce)(()=>{const t=n.batches[u].batched,s={collector:e,config:o,data:void 0,mapping:r,env:v(n.env,o.env),logger:c};c.debug("push batch",{events:t.events.length}),(0,l.useHooks)(n.pushBatch,"DestinationPushBatch",e.hooks)(t,s),c.debug("push batch done"),t.events=[],t.data=[]},r.batch)}}const t=n.batches[u];t.batched.events.push(s.event),(0,l.isDefined)(s.data)&&t.batched.data.push(s.data),t.batchFn()}else c.debug("push",{event:s.event.name}),await(0,l.useHooks)(n.push,"DestinationPush",e.hooks)(s.event,i),c.debug("push done");return!0}function b(e){return(0,l.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function y(e,n={}){const t={};for(const[e,o]of Object.entries(n)){const{code:n,config:s={},env:a={}}=o,c=d(n),i={...c.config,...s},r=v(c.env,a);t[e]={...c,config:i,env:r}}return t}function v(e,n){return e||n?n?e&&(0,l.isObject)(e)&&(0,l.isObject)(n)?{...e,...n}:n:e:{}}var w=require("@walkeros/core"),k=require("@walkeros/core");function C(e,n,t){const o=e.on,s=o[n]||[],a=(0,w.isArray)(t)?t:[t];a.forEach(e=>{s.push(e)}),o[n]=s,q(e,n,a)}function q(e,n,t,o){let s,a=t||[];switch(t||(a=e.on[n]||[]),n){case r.Commands.Consent:s=o||e.consent;break;case r.Commands.Session:s=e.session;break;case r.Commands.Ready:case r.Commands.Run:default:s=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,k.tryCatch)(e.on)(n,s)}),Object.values(e.destinations).forEach(t=>{if(t.on){const o=t.type||"unknown",a=e.logger.scope(o).scope("on").scope(n),c={collector:e,config:t.config,data:s,env:v(t.env,t.config.env),logger:a};(0,k.tryCatch)(t.on)(n,c)}}),a.length)switch(n){case r.Commands.Consent:!function(e,n,t){const o=t||e.consent;n.forEach(n=>{Object.keys(o).filter(e=>e in n).forEach(t=>{(0,k.tryCatch)(n[t])(e,o)})})}(e,a,o);break;case r.Commands.Ready:case r.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,k.tryCatch)(n)(e)})}(e,a);break;case r.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,k.tryCatch)(n)(e,e.session)})}(e,a)}}async function j(e,n){const{consent:t}=e;let o=!1;const s={};return Object.entries(n).forEach(([e,n])=>{const t=!!n;s[e]=t,o=o||t}),e.consent=(0,u.assign)(t,s),q(e,"consent",void 0,s),o?p(e):b({ok:!0})}var O=require("@walkeros/core"),E=require("@walkeros/core"),A=require("@walkeros/core");async function D(e,n,t,o){let s;switch(n){case r.Commands.Config:(0,A.isObject)(t)&&(0,E.assign)(e.config,t,{shallow:!1});break;case r.Commands.Consent:(0,A.isObject)(t)&&(s=await j(e,t));break;case r.Commands.Custom:(0,A.isObject)(t)&&(e.custom=(0,E.assign)(e.custom,t));break;case r.Commands.Destination:(0,A.isObject)(t)&&(0,E.isFunction)(t.push)&&(s=await f(e,{code:t},o));break;case r.Commands.Globals:(0,A.isObject)(t)&&(e.globals=(0,E.assign)(e.globals,t));break;case r.Commands.On:(0,E.isString)(t)&&C(e,t,o);break;case r.Commands.Ready:q(e,"ready");break;case r.Commands.Run:s=await x(e,t);break;case r.Commands.Session:q(e,"session");break;case r.Commands.User:(0,A.isObject)(t)&&(0,E.assign)(e.user,t,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function P(e,n){if(!n.name)throw new Error("Event name is required");const[t,o]=n.name.split(" ");if(!t||!o)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:c=e.count}=n,{name:i=`${t} ${o}`,data:r={},context:u={},globals:l=e.globals,custom:g={},user:d=e.user,nested:f=[],consent:p=e.consent,id:m=`${s}-${a}-${c}`,trigger:h="",entity:b=t,action:y=o,timing:v=0,version:w={source:e.version,tagging:e.config.tagging||0},source:k={type:"collector",id:"",previous_id:""}}=n;return{name:i,data:r,context:u,globals:l,custom:g,user:d,nested:f,consent:p,id:m,trigger:h,entity:b,action:y,timestamp:s,timing:v,group:a,count:c,version:w,source:k}}async function x(e,n){e.allowed=!0,e.count=0,e.group=(0,E.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,E.assign)(e.consent,n.consent)),n.user&&(e.user=(0,E.assign)(e.user,n.user)),n.globals&&(e.globals=(0,E.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,E.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await p(e);return q(e,"run"),t}var S=require("@walkeros/core");function R(e,n){return(0,S.useHooks)(async(t,o={})=>await(0,S.tryCatchAsync)(async()=>{let s=t;if(o.mapping){const n=await(0,S.processEventMapping)(s,o.mapping,e);if(n.ignore)return b({ok:!0});if(o.mapping.consent){if(!(0,S.getGrantedConsent)(o.mapping.consent,e.consent,n.event.consent))return b({ok:!0})}s=n.event}const a=n(s),c=P(e,a);return await p(e,c)},()=>b({ok:!1}))(),"Push",e.hooks)}var F=require("@walkeros/core");async function B(e){const n=(0,O.assign)({globalsStatic:{},sessionStatic:{},tagging:0,run:!0},e,{merge:!1,extend:!1}),t={level:e.logger?.level,handler:e.logger?.handler},o=(0,O.createLogger)(t),s={...n.globalsStatic,...e.globals},a={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},logger:o,on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.5.0",sources:{},push:void 0,command:void 0};return a.push=R(a,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.command=function(e,n){return(0,F.useHooks)(async(t,o,s)=>await(0,F.tryCatchAsync)(async()=>await n(e,t,o,s),()=>b({ok:!1}))(),"Command",e.hooks)}(a,D),a.destinations=await y(0,e.destinations||{}),a}var H=require("@walkeros/core");async function I(e,n={}){const t={};for(const[o,s]of Object.entries(n)){const{code:n,config:a={},env:c={},primary:i}=s,r=(n,t={})=>e.push(n,{...t,mapping:a}),u=e.logger.scope("source").scope(o),l={push:r,command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:u,...c},g=await(0,H.tryCatchAsync)(n)(a,l);if(!g)continue;const d=g.type||"unknown",f=e.logger.scope(d).scope(o);l.logger=f,i&&(g.config={...g.config,primary:i}),t[o]=g}return t}async function $(e){e=e||{};const n=await B(e),t=(o=n,{type:"elb",config:{},push:async(e,n,t,s,a,c)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return o.command(s,n,t)}let i;if("string"==typeof e)i={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(i.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};i=e,n&&"object"==typeof n&&!Array.isArray(n)&&(i.data={...i.data||{},...n})}return s&&"object"==typeof s&&(i.context=s),a&&Array.isArray(a)&&(i.nested=a),c&&"object"==typeof c&&(i.custom=c),o.push(i)}});var o;n.sources.elb=t;const s=await I(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:c,globals:i,custom:r}=e;a&&await n.command("consent",a),c&&await n.command("user",c),i&&Object.assign(n.globals,i),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=t.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),g=l.find(e=>e.config.primary);return g?u=g.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";var e,n=Object.defineProperty,t=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,a={};((e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})})(a,{Code:()=>c,Commands:()=>i,Const:()=>r,addDestination:()=>f,commonHandleCommand:()=>D,createEvent:()=>P,createPush:()=>R,createPushResult:()=>b,destinationCode:()=>g,destinationInit:()=>m,destinationPush:()=>h,initDestinations:()=>y,initSources:()=>I,mergeEnvironments:()=>v,on:()=>C,onApply:()=>q,pushToDestinations:()=>p,runCollector:()=>x,setConsent:()=>j,startFlow:()=>$}),module.exports=(e=a,((e,a,c,i)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of o(a))s.call(e,r)||r===c||n(e,r,{get:()=>a[r],enumerable:!(i=t(a,r))||i.enumerable});return e})(n({},"__esModule",{value:!0}),e));var c={},i={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},r={Commands:i,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},u=require("@walkeros/core"),l=require("@walkeros/core"),g={type:"code",config:{},init(e){const{config:n,logger:t}=e,o=n.settings,s=o?.scripts;if(s&&"undefined"!=typeof document)for(const e of s){const n=document.createElement("script");n.src=e,n.async=!0,document.head.appendChild(n)}const a=o?.init;if(a)try{new Function("context",a)(e)}catch(e){t.error("Code destination init error:",e)}},push(e,n){const{mapping:t,config:o,logger:s}=n,a=t?.push??o.settings?.push;if(a)try{new Function("event","context",a)(e,n)}catch(e){s.error("Code destination push error:",e)}},pushBatch(e,n){const{mapping:t,config:o,logger:s}=n,a=t?.pushBatch??o.settings?.pushBatch;if(a)try{new Function("batch","context",a)(e,n)}catch(e){s.error("Code destination pushBatch error:",e)}},on(e,n){const{config:t,logger:o}=n,s=t.settings?.on;if(s)try{new Function("type","context",s)(e,n)}catch(e){o.error("Code destination on error:",e)}}};function d(e){return!0===e?g:e}async function f(e,n,t){const{code:o,config:s={},env:a={}}=n,c=t||s||{init:!1},i=d(o),r={...i,config:c,env:v(i.env,a)};let u=r.config.id;if(!u)do{u=(0,l.getId)(4)}while(e.destinations[u]);return e.destinations[u]=r,!1!==r.config.queue&&(r.queue=[...e.queue]),p(e,void 0,{[u]:r})}async function p(e,n,t){const{allowed:o,consent:s,globals:a,user:c}=e;if(!o)return b({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const i=await Promise.all(Object.entries(t||{}).map(async([t,o])=>{let i=(o.queue||[]).map(e=>({...e,consent:s}));if(o.queue=[],n){const e=(0,l.clone)(n);i.push(e)}if(!i.length)return{id:t,destination:o,skipped:!0};const r=[],u=i.filter(e=>{const n=(0,l.getGrantedConsent)(o.config.consent,s,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(o.queue.concat(u),!r.length)return{id:t,destination:o,queue:i};if(!await(0,l.tryCatchAsync)(m)(e,o))return{id:t,destination:o,queue:i};let g=!1;return o.dlq||(o.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,l.assign)(a,n.globals),n.user=(0,l.assign)(c,n.user),await(0,l.tryCatchAsync)(h,t=>{const s=o.type||"unknown";return e.logger.scope(s).error("Push failed",{error:t,event:n.name}),g=!0,o.dlq.push([n,t]),!1})(e,o,n),n))),{id:t,destination:o,error:g}})),r=[],u=[],g=[];for(const e of i){if(e.skipped)continue;const n=e.destination,t={id:e.id,destination:n};e.error?g.push(t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),u.push(t)):r.push(t)}return b({ok:!g.length,event:n,successful:r,queued:u,failed:g})}async function m(e,n){if(n.init&&!n.config.init){const t=n.type||"unknown",o=e.logger.scope(t),s={collector:e,config:n.config,env:v(n.env,n.config.env),logger:o};o.debug("init");const a=await(0,l.useHooks)(n.init,"DestinationInit",e.hooks)(s);if(!1===a)return a;n.config={...a||n.config,init:!0},o.debug("init done")}return!0}async function h(e,n,t){const{config:o}=n,s=await(0,l.processEventMapping)(t,o,e);if(s.ignore)return!1;const a=n.type||"unknown",c=e.logger.scope(a),i={collector:e,config:o,data:s.data,mapping:s.mapping,env:v(n.env,o.env),logger:c},r=s.mapping,u=s.mappingKey||"* *";if(r?.batch&&n.pushBatch){if(n.batches=n.batches||{},!n.batches[u]){const t={key:u,events:[],data:[]};n.batches[u]={batched:t,batchFn:(0,l.debounce)(()=>{const t=n.batches[u].batched,s={collector:e,config:o,data:void 0,mapping:r,env:v(n.env,o.env),logger:c};c.debug("push batch",{events:t.events.length}),(0,l.useHooks)(n.pushBatch,"DestinationPushBatch",e.hooks)(t,s),c.debug("push batch done"),t.events=[],t.data=[]},r.batch)}}const t=n.batches[u];t.batched.events.push(s.event),(0,l.isDefined)(s.data)&&t.batched.data.push(s.data),t.batchFn()}else c.debug("push",{event:s.event.name}),await(0,l.useHooks)(n.push,"DestinationPush",e.hooks)(s.event,i),c.debug("push done");return!0}function b(e){return(0,l.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function y(e,n={}){const t={};for(const[e,o]of Object.entries(n)){const{code:n,config:s={},env:a={}}=o,c=d(n),i={...c.config,...s},r=v(c.env,a);t[e]={...c,config:i,env:r}}return t}function v(e,n){return e||n?n?e&&(0,l.isObject)(e)&&(0,l.isObject)(n)?{...e,...n}:n:e:{}}var w=require("@walkeros/core"),k=require("@walkeros/core");function C(e,n,t){const o=e.on,s=o[n]||[],a=(0,w.isArray)(t)?t:[t];a.forEach(e=>{s.push(e)}),o[n]=s,q(e,n,a)}function q(e,n,t,o){let s,a=t||[];switch(t||(a=e.on[n]||[]),n){case r.Commands.Consent:s=o||e.consent;break;case r.Commands.Session:s=e.session;break;case r.Commands.Ready:case r.Commands.Run:default:s=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,k.tryCatch)(e.on)(n,s)}),Object.values(e.destinations).forEach(t=>{if(t.on){const o=t.type||"unknown",a=e.logger.scope(o).scope("on").scope(n),c={collector:e,config:t.config,data:s,env:v(t.env,t.config.env),logger:a};(0,k.tryCatch)(t.on)(n,c)}}),a.length)switch(n){case r.Commands.Consent:!function(e,n,t){const o=t||e.consent;n.forEach(n=>{Object.keys(o).filter(e=>e in n).forEach(t=>{(0,k.tryCatch)(n[t])(e,o)})})}(e,a,o);break;case r.Commands.Ready:case r.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,k.tryCatch)(n)(e)})}(e,a);break;case r.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,k.tryCatch)(n)(e,e.session)})}(e,a)}}async function j(e,n){const{consent:t}=e;let o=!1;const s={};return Object.entries(n).forEach(([e,n])=>{const t=!!n;s[e]=t,o=o||t}),e.consent=(0,u.assign)(t,s),q(e,"consent",void 0,s),o?p(e):b({ok:!0})}var O=require("@walkeros/core"),E=require("@walkeros/core"),A=require("@walkeros/core");async function D(e,n,t,o){let s;switch(n){case r.Commands.Config:(0,A.isObject)(t)&&(0,E.assign)(e.config,t,{shallow:!1});break;case r.Commands.Consent:(0,A.isObject)(t)&&(s=await j(e,t));break;case r.Commands.Custom:(0,A.isObject)(t)&&(e.custom=(0,E.assign)(e.custom,t));break;case r.Commands.Destination:(0,A.isObject)(t)&&(0,E.isFunction)(t.push)&&(s=await f(e,{code:t},o));break;case r.Commands.Globals:(0,A.isObject)(t)&&(e.globals=(0,E.assign)(e.globals,t));break;case r.Commands.On:(0,E.isString)(t)&&C(e,t,o);break;case r.Commands.Ready:q(e,"ready");break;case r.Commands.Run:s=await x(e,t);break;case r.Commands.Session:q(e,"session");break;case r.Commands.User:(0,A.isObject)(t)&&(0,E.assign)(e.user,t,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function P(e,n){if(!n.name)throw new Error("Event name is required");const[t,o]=n.name.split(" ");if(!t||!o)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:c=e.count}=n,{name:i=`${t} ${o}`,data:r={},context:u={},globals:l=e.globals,custom:g={},user:d=e.user,nested:f=[],consent:p=e.consent,id:m=`${s}-${a}-${c}`,trigger:h="",entity:b=t,action:y=o,timing:v=0,version:w={source:e.version,tagging:e.config.tagging||0},source:k={type:"collector",id:"",previous_id:""}}=n;return{name:i,data:r,context:u,globals:l,custom:g,user:d,nested:f,consent:p,id:m,trigger:h,entity:b,action:y,timestamp:s,timing:v,group:a,count:c,version:w,source:k}}async function x(e,n){e.allowed=!0,e.count=0,e.group=(0,E.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,E.assign)(e.consent,n.consent)),n.user&&(e.user=(0,E.assign)(e.user,n.user)),n.globals&&(e.globals=(0,E.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,E.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await p(e);return q(e,"run"),t}var S=require("@walkeros/core");function R(e,n){return(0,S.useHooks)(async(t,o={})=>await(0,S.tryCatchAsync)(async()=>{let s=t;if(o.mapping){const n=await(0,S.processEventMapping)(s,o.mapping,e);if(n.ignore)return b({ok:!0});if(o.mapping.consent){if(!(0,S.getGrantedConsent)(o.mapping.consent,e.consent,n.event.consent))return b({ok:!0})}s=n.event}const a=n(s),c=P(e,a);return await p(e,c)},()=>b({ok:!1}))(),"Push",e.hooks)}var F=require("@walkeros/core");async function B(e){const n=(0,O.assign)({globalsStatic:{},sessionStatic:{},tagging:0,run:!0},e,{merge:!1,extend:!1}),t={level:e.logger?.level,handler:e.logger?.handler},o=(0,O.createLogger)(t),s={...n.globalsStatic,...e.globals},a={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},logger:o,on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.6.0",sources:{},push:void 0,command:void 0};return a.push=R(a,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.command=function(e,n){return(0,F.useHooks)(async(t,o,s)=>await(0,F.tryCatchAsync)(async()=>await n(e,t,o,s),()=>b({ok:!1}))(),"Command",e.hooks)}(a,D),a.destinations=await y(0,e.destinations||{}),a}var H=require("@walkeros/core");async function I(e,n={}){const t={};for(const[o,s]of Object.entries(n)){const{code:n,config:a={},env:c={},primary:i}=s,r=(n,t={})=>e.push(n,{...t,mapping:a}),u=e.logger.scope("source").scope(o),l={push:r,command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:u,...c},g=await(0,H.tryCatchAsync)(n)(a,l);if(!g)continue;const d=g.type||"unknown",f=e.logger.scope(d).scope(o);l.logger=f,i&&(g.config={...g.config,primary:i}),t[o]=g}return t}async function $(e){e=e||{};const n=await B(e),t=(o=n,{type:"elb",config:{},push:async(e,n,t,s,a,c)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return o.command(s,n,t)}let i;if("string"==typeof e)i={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(i.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};i=e,n&&"object"==typeof n&&!Array.isArray(n)&&(i.data={...i.data||{},...n})}return s&&"object"==typeof s&&(i.context=s),a&&Array.isArray(a)&&(i.nested=a),c&&"object"==typeof c&&(i.custom=c),o.push(i)}});var o;n.sources.elb=t;const s=await I(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:c,globals:i,custom:r}=e;a&&await n.command("consent",a),c&&await n.command("user",c),i&&Object.assign(n.globals,i),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=t.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),g=l.find(e=>e.config.primary);return g?u=g.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e={},n={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},o={Commands:n,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}};import{assign as t}from"@walkeros/core";import{assign as s,clone as a,debounce as c,getId as i,getGrantedConsent as r,isDefined as u,isObject as l,processEventMapping as g,tryCatchAsync as d,useHooks as f}from"@walkeros/core";var m={type:"code",config:{},init(e){const{config:n,logger:o}=e,t=n.settings,s=t?.scripts;if(s&&"undefined"!=typeof document)for(const e of s){const n=document.createElement("script");n.src=e,n.async=!0,document.head.appendChild(n)}const a=t?.init;if(a)try{new Function("context",a)(e)}catch(e){o.error("Code destination init error:",e)}},push(e,n){const{mapping:o,config:t,logger:s}=n,a=o?.push??t.settings?.push;if(a)try{new Function("event","context",a)(e,n)}catch(e){s.error("Code destination push error:",e)}},pushBatch(e,n){const{mapping:o,config:t,logger:s}=n,a=o?.pushBatch??t.settings?.pushBatch;if(a)try{new Function("batch","context",a)(e,n)}catch(e){s.error("Code destination pushBatch error:",e)}},on(e,n){const{config:o,logger:t}=n,s=o.settings?.on;if(s)try{new Function("type","context",s)(e,n)}catch(e){t.error("Code destination on error:",e)}}};function p(e){return!0===e?m:e}async function h(e,n,o){const{code:t,config:s={},env:a={}}=n,c=o||s||{init:!1},r=p(t),u={...r,config:c,env:C(r.env,a)};let l=u.config.id;if(!l)do{l=i(4)}while(e.destinations[l]);return e.destinations[l]=u,!1!==u.config.queue&&(u.queue=[...e.queue]),b(e,void 0,{[l]:u})}async function b(e,n,o){const{allowed:t,consent:c,globals:i,user:u}=e;if(!t)return k({ok:!1});n&&e.queue.push(n),o||(o=e.destinations);const l=await Promise.all(Object.entries(o||{}).map(async([o,t])=>{let l=(t.queue||[]).map(e=>({...e,consent:c}));if(t.queue=[],n){const e=a(n);l.push(e)}if(!l.length)return{id:o,destination:t,skipped:!0};const g=[],f=l.filter(e=>{const n=r(t.config.consent,c,e.consent);return!n||(e.consent=n,g.push(e),!1)});if(t.queue.concat(f),!g.length)return{id:o,destination:t,queue:l};if(!await d(y)(e,t))return{id:o,destination:t,queue:l};let m=!1;return t.dlq||(t.dlq=[]),await Promise.all(g.map(async n=>(n.globals=s(i,n.globals),n.user=s(u,n.user),await d(w,o=>{const s=t.type||"unknown";return e.logger.scope(s).error("Push failed",{error:o,event:n.name}),m=!0,t.dlq.push([n,o]),!1})(e,t,n),n))),{id:o,destination:t,error:m}})),g=[],f=[],m=[];for(const e of l){if(e.skipped)continue;const n=e.destination,o={id:e.id,destination:n};e.error?m.push(o):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),f.push(o)):g.push(o)}return k({ok:!m.length,event:n,successful:g,queued:f,failed:m})}async function y(e,n){if(n.init&&!n.config.init){const o=n.type||"unknown",t=e.logger.scope(o),s={collector:e,config:n.config,env:C(n.env,n.config.env),logger:t};t.debug("init");const a=await f(n.init,"DestinationInit",e.hooks)(s);if(!1===a)return a;n.config={...a||n.config,init:!0},t.debug("init done")}return!0}async function w(e,n,o){const{config:t}=n,s=await g(o,t,e);if(s.ignore)return!1;const a=n.type||"unknown",i=e.logger.scope(a),r={collector:e,config:t,data:s.data,mapping:s.mapping,env:C(n.env,t.env),logger:i},l=s.mapping,d=s.mappingKey||"* *";if(l?.batch&&n.pushBatch){if(n.batches=n.batches||{},!n.batches[d]){const o={key:d,events:[],data:[]};n.batches[d]={batched:o,batchFn:c(()=>{const o=n.batches[d].batched,s={collector:e,config:t,data:void 0,mapping:l,env:C(n.env,t.env),logger:i};i.debug("push batch",{events:o.events.length}),f(n.pushBatch,"DestinationPushBatch",e.hooks)(o,s),i.debug("push batch done"),o.events=[],o.data=[]},l.batch)}}const o=n.batches[d];o.batched.events.push(s.event),u(s.data)&&o.batched.data.push(s.data),o.batchFn()}else i.debug("push",{event:s.event.name}),await f(n.push,"DestinationPush",e.hooks)(s.event,r),i.debug("push done");return!0}function k(e){return s({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function v(e,n={}){const o={};for(const[e,t]of Object.entries(n)){const{code:n,config:s={},env:a={}}=t,c=p(n),i={...c.config,...s},r=C(c.env,a);o[e]={...c,config:i,env:r}}return o}function C(e,n){return e||n?n?e&&l(e)&&l(n)?{...e,...n}:n:e:{}}import{isArray as q}from"@walkeros/core";import{tryCatch as j}from"@walkeros/core";function E(e,n,o){const t=e.on,s=t[n]||[],a=q(o)?o:[o];a.forEach(e=>{s.push(e)}),t[n]=s,O(e,n,a)}function O(e,n,t,s){let a,c=t||[];switch(t||(c=e.on[n]||[]),n){case o.Commands.Consent:a=s||e.consent;break;case o.Commands.Session:a=e.session;break;case o.Commands.Ready:case o.Commands.Run:default:a=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&j(e.on)(n,a)}),Object.values(e.destinations).forEach(o=>{if(o.on){const t=o.type||"unknown",s=e.logger.scope(t).scope("on").scope(n),c={collector:e,config:o.config,data:a,env:C(o.env,o.config.env),logger:s};j(o.on)(n,c)}}),c.length)switch(n){case o.Commands.Consent:!function(e,n,o){const t=o||e.consent;n.forEach(n=>{Object.keys(t).filter(e=>e in n).forEach(o=>{j(n[o])(e,t)})})}(e,c,s);break;case o.Commands.Ready:case o.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{j(n)(e)})}(e,c);break;case o.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{j(n)(e,e.session)})}(e,c)}}async function x(e,n){const{consent:o}=e;let s=!1;const a={};return Object.entries(n).forEach(([e,n])=>{const o=!!n;a[e]=o,s=s||o}),e.consent=t(o,a),O(e,"consent",void 0,a),s?b(e):k({ok:!0})}import{assign as A,createLogger as S}from"@walkeros/core";import{assign as D,getId as R,isFunction as B,isString as P}from"@walkeros/core";import{isObject as F}from"@walkeros/core";async function $(e,n,t,s){let a;switch(n){case o.Commands.Config:F(t)&&D(e.config,t,{shallow:!1});break;case o.Commands.Consent:F(t)&&(a=await x(e,t));break;case o.Commands.Custom:F(t)&&(e.custom=D(e.custom,t));break;case o.Commands.Destination:F(t)&&B(t.push)&&(a=await h(e,{code:t},s));break;case o.Commands.Globals:F(t)&&(e.globals=D(e.globals,t));break;case o.Commands.On:P(t)&&E(e,t,s);break;case o.Commands.Ready:O(e,"ready");break;case o.Commands.Run:a=await H(e,t);break;case o.Commands.Session:O(e,"session");break;case o.Commands.User:F(t)&&D(e.user,t,{shallow:!1})}return a||{ok:!0,successful:[],queued:[],failed:[]}}function G(e,n){if(!n.name)throw new Error("Event name is required");const[o,t]=n.name.split(" ");if(!o||!t)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:c=e.count}=n,{name:i=`${o} ${t}`,data:r={},context:u={},globals:l=e.globals,custom:g={},user:d=e.user,nested:f=[],consent:m=e.consent,id:p=`${s}-${a}-${c}`,trigger:h="",entity:b=o,action:y=t,timing:w=0,version:k={source:e.version,tagging:e.config.tagging||0},source:v={type:"collector",id:"",previous_id:""}}=n;return{name:i,data:r,context:u,globals:l,custom:g,user:d,nested:f,consent:m,id:p,trigger:h,entity:b,action:y,timestamp:s,timing:w,group:a,count:c,version:k,source:v}}async function H(e,n){e.allowed=!0,e.count=0,e.group=R(),e.timing=Date.now(),n&&(n.consent&&(e.consent=D(e.consent,n.consent)),n.user&&(e.user=D(e.user,n.user)),n.globals&&(e.globals=D(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=D(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const o=await b(e);return O(e,"run"),o}import{getGrantedConsent as I,processEventMapping as U,tryCatchAsync as L,useHooks as M}from"@walkeros/core";function W(e,n){return M(async(o,t={})=>await L(async()=>{let s=o;if(t.mapping){const n=await U(s,t.mapping,e);if(n.ignore)return k({ok:!0});if(t.mapping.consent){if(!I(t.mapping.consent,e.consent,n.event.consent))return k({ok:!0})}s=n.event}const a=n(s),c=G(e,a);return await b(e,c)},()=>k({ok:!1}))(),"Push",e.hooks)}import{useHooks as _,tryCatchAsync as K}from"@walkeros/core";async function z(e){const n=A({globalsStatic:{},sessionStatic:{},tagging:0,run:!0},e,{merge:!1,extend:!1}),o={level:e.logger?.level,handler:e.logger?.handler},t=S(o),s={...n.globalsStatic,...e.globals},a={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},logger:t,on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.5.0",sources:{},push:void 0,command:void 0};return a.push=W(a,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.command=function(e,n){return _(async(o,t,s)=>await K(async()=>await n(e,o,t,s),()=>k({ok:!1}))(),"Command",e.hooks)}(a,$),a.destinations=await v(0,e.destinations||{}),a}import{tryCatchAsync as J}from"@walkeros/core";async function N(e,n={}){const o={};for(const[t,s]of Object.entries(n)){const{code:n,config:a={},env:c={},primary:i}=s,r=(n,o={})=>e.push(n,{...o,mapping:a}),u=e.logger.scope("source").scope(t),l={push:r,command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:u,...c},g=await J(n)(a,l);if(!g)continue;const d=g.type||"unknown",f=e.logger.scope(d).scope(t);l.logger=f,i&&(g.config={...g.config,primary:i}),o[t]=g}return o}async function Q(e){e=e||{};const n=await z(e),o=(t=n,{type:"elb",config:{},push:async(e,n,o,s,a,c)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return t.command(s,n,o)}let i;if("string"==typeof e)i={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(i.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};i=e,n&&"object"==typeof n&&!Array.isArray(n)&&(i.data={...i.data||{},...n})}return s&&"object"==typeof s&&(i.context=s),a&&Array.isArray(a)&&(i.nested=a),c&&"object"==typeof c&&(i.custom=c),t.push(i)}});var t;n.sources.elb=o;const s=await N(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:c,globals:i,custom:r}=e;a&&await n.command("consent",a),c&&await n.command("user",c),i&&Object.assign(n.globals,i),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=o.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),g=l.find(e=>e.config.primary);return g?u=g.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}export{e as Code,n as Commands,o as Const,h as addDestination,$ as commonHandleCommand,G as createEvent,W as createPush,k as createPushResult,m as destinationCode,y as destinationInit,w as destinationPush,v as initDestinations,N as initSources,C as mergeEnvironments,E as on,O as onApply,b as pushToDestinations,H as runCollector,x as setConsent,Q as startFlow};//# sourceMappingURL=index.mjs.map
|
|
1
|
+
var e={},n={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},o={Commands:n,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}};import{assign as t}from"@walkeros/core";import{assign as s,clone as a,debounce as c,getId as i,getGrantedConsent as r,isDefined as u,isObject as l,processEventMapping as g,tryCatchAsync as d,useHooks as f}from"@walkeros/core";var m={type:"code",config:{},init(e){const{config:n,logger:o}=e,t=n.settings,s=t?.scripts;if(s&&"undefined"!=typeof document)for(const e of s){const n=document.createElement("script");n.src=e,n.async=!0,document.head.appendChild(n)}const a=t?.init;if(a)try{new Function("context",a)(e)}catch(e){o.error("Code destination init error:",e)}},push(e,n){const{mapping:o,config:t,logger:s}=n,a=o?.push??t.settings?.push;if(a)try{new Function("event","context",a)(e,n)}catch(e){s.error("Code destination push error:",e)}},pushBatch(e,n){const{mapping:o,config:t,logger:s}=n,a=o?.pushBatch??t.settings?.pushBatch;if(a)try{new Function("batch","context",a)(e,n)}catch(e){s.error("Code destination pushBatch error:",e)}},on(e,n){const{config:o,logger:t}=n,s=o.settings?.on;if(s)try{new Function("type","context",s)(e,n)}catch(e){t.error("Code destination on error:",e)}}};function p(e){return!0===e?m:e}async function h(e,n,o){const{code:t,config:s={},env:a={}}=n,c=o||s||{init:!1},r=p(t),u={...r,config:c,env:C(r.env,a)};let l=u.config.id;if(!l)do{l=i(4)}while(e.destinations[l]);return e.destinations[l]=u,!1!==u.config.queue&&(u.queue=[...e.queue]),b(e,void 0,{[l]:u})}async function b(e,n,o){const{allowed:t,consent:c,globals:i,user:u}=e;if(!t)return k({ok:!1});n&&e.queue.push(n),o||(o=e.destinations);const l=await Promise.all(Object.entries(o||{}).map(async([o,t])=>{let l=(t.queue||[]).map(e=>({...e,consent:c}));if(t.queue=[],n){const e=a(n);l.push(e)}if(!l.length)return{id:o,destination:t,skipped:!0};const g=[],f=l.filter(e=>{const n=r(t.config.consent,c,e.consent);return!n||(e.consent=n,g.push(e),!1)});if(t.queue.concat(f),!g.length)return{id:o,destination:t,queue:l};if(!await d(y)(e,t))return{id:o,destination:t,queue:l};let m=!1;return t.dlq||(t.dlq=[]),await Promise.all(g.map(async n=>(n.globals=s(i,n.globals),n.user=s(u,n.user),await d(w,o=>{const s=t.type||"unknown";return e.logger.scope(s).error("Push failed",{error:o,event:n.name}),m=!0,t.dlq.push([n,o]),!1})(e,t,n),n))),{id:o,destination:t,error:m}})),g=[],f=[],m=[];for(const e of l){if(e.skipped)continue;const n=e.destination,o={id:e.id,destination:n};e.error?m.push(o):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),f.push(o)):g.push(o)}return k({ok:!m.length,event:n,successful:g,queued:f,failed:m})}async function y(e,n){if(n.init&&!n.config.init){const o=n.type||"unknown",t=e.logger.scope(o),s={collector:e,config:n.config,env:C(n.env,n.config.env),logger:t};t.debug("init");const a=await f(n.init,"DestinationInit",e.hooks)(s);if(!1===a)return a;n.config={...a||n.config,init:!0},t.debug("init done")}return!0}async function w(e,n,o){const{config:t}=n,s=await g(o,t,e);if(s.ignore)return!1;const a=n.type||"unknown",i=e.logger.scope(a),r={collector:e,config:t,data:s.data,mapping:s.mapping,env:C(n.env,t.env),logger:i},l=s.mapping,d=s.mappingKey||"* *";if(l?.batch&&n.pushBatch){if(n.batches=n.batches||{},!n.batches[d]){const o={key:d,events:[],data:[]};n.batches[d]={batched:o,batchFn:c(()=>{const o=n.batches[d].batched,s={collector:e,config:t,data:void 0,mapping:l,env:C(n.env,t.env),logger:i};i.debug("push batch",{events:o.events.length}),f(n.pushBatch,"DestinationPushBatch",e.hooks)(o,s),i.debug("push batch done"),o.events=[],o.data=[]},l.batch)}}const o=n.batches[d];o.batched.events.push(s.event),u(s.data)&&o.batched.data.push(s.data),o.batchFn()}else i.debug("push",{event:s.event.name}),await f(n.push,"DestinationPush",e.hooks)(s.event,r),i.debug("push done");return!0}function k(e){return s({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function v(e,n={}){const o={};for(const[e,t]of Object.entries(n)){const{code:n,config:s={},env:a={}}=t,c=p(n),i={...c.config,...s},r=C(c.env,a);o[e]={...c,config:i,env:r}}return o}function C(e,n){return e||n?n?e&&l(e)&&l(n)?{...e,...n}:n:e:{}}import{isArray as q}from"@walkeros/core";import{tryCatch as j}from"@walkeros/core";function E(e,n,o){const t=e.on,s=t[n]||[],a=q(o)?o:[o];a.forEach(e=>{s.push(e)}),t[n]=s,O(e,n,a)}function O(e,n,t,s){let a,c=t||[];switch(t||(c=e.on[n]||[]),n){case o.Commands.Consent:a=s||e.consent;break;case o.Commands.Session:a=e.session;break;case o.Commands.Ready:case o.Commands.Run:default:a=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&j(e.on)(n,a)}),Object.values(e.destinations).forEach(o=>{if(o.on){const t=o.type||"unknown",s=e.logger.scope(t).scope("on").scope(n),c={collector:e,config:o.config,data:a,env:C(o.env,o.config.env),logger:s};j(o.on)(n,c)}}),c.length)switch(n){case o.Commands.Consent:!function(e,n,o){const t=o||e.consent;n.forEach(n=>{Object.keys(t).filter(e=>e in n).forEach(o=>{j(n[o])(e,t)})})}(e,c,s);break;case o.Commands.Ready:case o.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{j(n)(e)})}(e,c);break;case o.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{j(n)(e,e.session)})}(e,c)}}async function x(e,n){const{consent:o}=e;let s=!1;const a={};return Object.entries(n).forEach(([e,n])=>{const o=!!n;a[e]=o,s=s||o}),e.consent=t(o,a),O(e,"consent",void 0,a),s?b(e):k({ok:!0})}import{assign as A,createLogger as S}from"@walkeros/core";import{assign as D,getId as R,isFunction as B,isString as P}from"@walkeros/core";import{isObject as F}from"@walkeros/core";async function $(e,n,t,s){let a;switch(n){case o.Commands.Config:F(t)&&D(e.config,t,{shallow:!1});break;case o.Commands.Consent:F(t)&&(a=await x(e,t));break;case o.Commands.Custom:F(t)&&(e.custom=D(e.custom,t));break;case o.Commands.Destination:F(t)&&B(t.push)&&(a=await h(e,{code:t},s));break;case o.Commands.Globals:F(t)&&(e.globals=D(e.globals,t));break;case o.Commands.On:P(t)&&E(e,t,s);break;case o.Commands.Ready:O(e,"ready");break;case o.Commands.Run:a=await H(e,t);break;case o.Commands.Session:O(e,"session");break;case o.Commands.User:F(t)&&D(e.user,t,{shallow:!1})}return a||{ok:!0,successful:[],queued:[],failed:[]}}function G(e,n){if(!n.name)throw new Error("Event name is required");const[o,t]=n.name.split(" ");if(!o||!t)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:c=e.count}=n,{name:i=`${o} ${t}`,data:r={},context:u={},globals:l=e.globals,custom:g={},user:d=e.user,nested:f=[],consent:m=e.consent,id:p=`${s}-${a}-${c}`,trigger:h="",entity:b=o,action:y=t,timing:w=0,version:k={source:e.version,tagging:e.config.tagging||0},source:v={type:"collector",id:"",previous_id:""}}=n;return{name:i,data:r,context:u,globals:l,custom:g,user:d,nested:f,consent:m,id:p,trigger:h,entity:b,action:y,timestamp:s,timing:w,group:a,count:c,version:k,source:v}}async function H(e,n){e.allowed=!0,e.count=0,e.group=R(),e.timing=Date.now(),n&&(n.consent&&(e.consent=D(e.consent,n.consent)),n.user&&(e.user=D(e.user,n.user)),n.globals&&(e.globals=D(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=D(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const o=await b(e);return O(e,"run"),o}import{getGrantedConsent as I,processEventMapping as U,tryCatchAsync as L,useHooks as M}from"@walkeros/core";function W(e,n){return M(async(o,t={})=>await L(async()=>{let s=o;if(t.mapping){const n=await U(s,t.mapping,e);if(n.ignore)return k({ok:!0});if(t.mapping.consent){if(!I(t.mapping.consent,e.consent,n.event.consent))return k({ok:!0})}s=n.event}const a=n(s),c=G(e,a);return await b(e,c)},()=>k({ok:!1}))(),"Push",e.hooks)}import{useHooks as _,tryCatchAsync as K}from"@walkeros/core";async function z(e){const n=A({globalsStatic:{},sessionStatic:{},tagging:0,run:!0},e,{merge:!1,extend:!1}),o={level:e.logger?.level,handler:e.logger?.handler},t=S(o),s={...n.globalsStatic,...e.globals},a={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},logger:t,on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.6.0",sources:{},push:void 0,command:void 0};return a.push=W(a,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.command=function(e,n){return _(async(o,t,s)=>await K(async()=>await n(e,o,t,s),()=>k({ok:!1}))(),"Command",e.hooks)}(a,$),a.destinations=await v(0,e.destinations||{}),a}import{tryCatchAsync as J}from"@walkeros/core";async function N(e,n={}){const o={};for(const[t,s]of Object.entries(n)){const{code:n,config:a={},env:c={},primary:i}=s,r=(n,o={})=>e.push(n,{...o,mapping:a}),u=e.logger.scope("source").scope(t),l={push:r,command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:u,...c},g=await J(n)(a,l);if(!g)continue;const d=g.type||"unknown",f=e.logger.scope(d).scope(t);l.logger=f,i&&(g.config={...g.config,primary:i}),o[t]=g}return o}async function Q(e){e=e||{};const n=await z(e),o=(t=n,{type:"elb",config:{},push:async(e,n,o,s,a,c)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return t.command(s,n,o)}let i;if("string"==typeof e)i={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(i.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};i=e,n&&"object"==typeof n&&!Array.isArray(n)&&(i.data={...i.data||{},...n})}return s&&"object"==typeof s&&(i.context=s),a&&Array.isArray(a)&&(i.nested=a),c&&"object"==typeof c&&(i.custom=c),t.push(i)}});var t;n.sources.elb=o;const s=await N(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:c,globals:i,custom:r}=e;a&&await n.command("consent",a),c&&await n.command("user",c),i&&Object.assign(n.globals,i),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=o.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),g=l.find(e=>e.config.primary);return g?u=g.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}export{e as Code,n as Commands,o as Const,h as addDestination,$ as commonHandleCommand,G as createEvent,W as createPush,k as createPushResult,m as destinationCode,y as destinationInit,w as destinationPush,v as initDestinations,N as initSources,C as mergeEnvironments,E as on,O as onApply,b as pushToDestinations,H as runCollector,x as setConsent,Q as startFlow};//# sourceMappingURL=index.mjs.map
|
package/dist/on.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Collector, On, WalkerOS } from '@walkeros/core';
|
|
2
|
+
/**
|
|
3
|
+
* Registers a callback for a specific event type.
|
|
4
|
+
*
|
|
5
|
+
* @param collector The walkerOS collector instance.
|
|
6
|
+
* @param type The type of the event to listen for.
|
|
7
|
+
* @param option The callback function or an array of callback functions.
|
|
8
|
+
*/
|
|
9
|
+
export declare function on(collector: Collector.Instance, type: On.Types, option: WalkerOS.SingleOrArray<On.Options>): void;
|
|
10
|
+
/**
|
|
11
|
+
* Applies all registered callbacks for a specific event type.
|
|
12
|
+
*
|
|
13
|
+
* @param collector The walkerOS collector instance.
|
|
14
|
+
* @param type The type of the event to apply the callbacks for.
|
|
15
|
+
* @param options The options for the callbacks.
|
|
16
|
+
* @param config The consent configuration.
|
|
17
|
+
*/
|
|
18
|
+
export declare function onApply(collector: Collector.Instance, type: On.Types, options?: Array<On.Options>, config?: WalkerOS.Consent): void;
|
|
19
|
+
//# sourceMappingURL=on.d.ts.map
|
package/dist/on.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on.d.ts","sourceRoot":"","sources":["../src/on.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,QAAQ,EAAe,MAAM,gBAAgB,CAAC;AAM3E;;;;;;GAMG;AACH,wBAAgB,EAAE,CAChB,SAAS,EAAE,SAAS,CAAC,QAAQ,EAC7B,IAAI,EAAE,EAAE,CAAC,KAAK,EACd,MAAM,EAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,OAAO,CAAC,QAe3C;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CACrB,SAAS,EAAE,SAAS,CAAC,QAAQ,EAC7B,IAAI,EAAE,EAAE,CAAC,KAAK,EACd,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,EAC3B,MAAM,CAAC,EAAE,QAAQ,CAAC,OAAO,QAuE1B"}
|
package/dist/on.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { isArray } from '@walkeros/core';
|
|
2
|
+
import { Const } from './constants';
|
|
3
|
+
import { tryCatch } from '@walkeros/core';
|
|
4
|
+
import { mergeEnvironments } from './destination';
|
|
5
|
+
/**
|
|
6
|
+
* Registers a callback for a specific event type.
|
|
7
|
+
*
|
|
8
|
+
* @param collector The walkerOS collector instance.
|
|
9
|
+
* @param type The type of the event to listen for.
|
|
10
|
+
* @param option The callback function or an array of callback functions.
|
|
11
|
+
*/
|
|
12
|
+
export function on(collector, type, option) {
|
|
13
|
+
const on = collector.on;
|
|
14
|
+
const onType = on[type] || [];
|
|
15
|
+
const options = isArray(option) ? option : [option];
|
|
16
|
+
options.forEach((option) => {
|
|
17
|
+
onType.push(option);
|
|
18
|
+
});
|
|
19
|
+
// Update collector on state
|
|
20
|
+
on[type] = onType;
|
|
21
|
+
// Execute the on function directly
|
|
22
|
+
onApply(collector, type, options);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Applies all registered callbacks for a specific event type.
|
|
26
|
+
*
|
|
27
|
+
* @param collector The walkerOS collector instance.
|
|
28
|
+
* @param type The type of the event to apply the callbacks for.
|
|
29
|
+
* @param options The options for the callbacks.
|
|
30
|
+
* @param config The consent configuration.
|
|
31
|
+
*/
|
|
32
|
+
export function onApply(collector, type, options, config) {
|
|
33
|
+
// Use the optionally provided options
|
|
34
|
+
let onConfig = options || [];
|
|
35
|
+
if (!options) {
|
|
36
|
+
// Get the collector on events
|
|
37
|
+
onConfig = collector.on[type] || [];
|
|
38
|
+
}
|
|
39
|
+
// Calculate context data once for all sources and destinations
|
|
40
|
+
let contextData;
|
|
41
|
+
switch (type) {
|
|
42
|
+
case Const.Commands.Consent:
|
|
43
|
+
contextData = config || collector.consent;
|
|
44
|
+
break;
|
|
45
|
+
case Const.Commands.Session:
|
|
46
|
+
contextData = collector.session;
|
|
47
|
+
break;
|
|
48
|
+
case Const.Commands.Ready:
|
|
49
|
+
case Const.Commands.Run:
|
|
50
|
+
default:
|
|
51
|
+
contextData = undefined;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
Object.values(collector.sources).forEach((source) => {
|
|
55
|
+
if (source.on) {
|
|
56
|
+
tryCatch(source.on)(type, contextData);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
Object.values(collector.destinations).forEach((destination) => {
|
|
60
|
+
if (destination.on) {
|
|
61
|
+
const destType = destination.type || 'unknown';
|
|
62
|
+
const destLogger = collector.logger
|
|
63
|
+
.scope(destType)
|
|
64
|
+
.scope('on')
|
|
65
|
+
.scope(type);
|
|
66
|
+
const context = {
|
|
67
|
+
collector,
|
|
68
|
+
config: destination.config,
|
|
69
|
+
data: contextData,
|
|
70
|
+
env: mergeEnvironments(destination.env, destination.config.env),
|
|
71
|
+
logger: destLogger,
|
|
72
|
+
};
|
|
73
|
+
tryCatch(destination.on)(type, context);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (!onConfig.length)
|
|
77
|
+
return; // No on-events registered, nothing to do
|
|
78
|
+
switch (type) {
|
|
79
|
+
case Const.Commands.Consent:
|
|
80
|
+
onConsent(collector, onConfig, config);
|
|
81
|
+
break;
|
|
82
|
+
case Const.Commands.Ready:
|
|
83
|
+
onReady(collector, onConfig);
|
|
84
|
+
break;
|
|
85
|
+
case Const.Commands.Run:
|
|
86
|
+
onRun(collector, onConfig);
|
|
87
|
+
break;
|
|
88
|
+
case Const.Commands.Session:
|
|
89
|
+
onSession(collector, onConfig);
|
|
90
|
+
break;
|
|
91
|
+
default:
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function onConsent(collector, onConfig, currentConsent) {
|
|
96
|
+
const consentState = currentConsent || collector.consent;
|
|
97
|
+
onConfig.forEach((consentConfig) => {
|
|
98
|
+
// Collect functions whose consent keys match the rule keys directly
|
|
99
|
+
// Directly execute functions whose consent keys match the rule keys
|
|
100
|
+
Object.keys(consentState) // consent keys
|
|
101
|
+
.filter((consent) => consent in consentConfig) // check for matching rule keys
|
|
102
|
+
.forEach((consent) => {
|
|
103
|
+
// Execute the function
|
|
104
|
+
tryCatch(consentConfig[consent])(collector, consentState);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function onReady(collector, onConfig) {
|
|
109
|
+
if (collector.allowed)
|
|
110
|
+
onConfig.forEach((func) => {
|
|
111
|
+
tryCatch(func)(collector);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function onRun(collector, onConfig) {
|
|
115
|
+
if (collector.allowed)
|
|
116
|
+
onConfig.forEach((func) => {
|
|
117
|
+
tryCatch(func)(collector);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function onSession(collector, onConfig) {
|
|
121
|
+
if (!collector.session)
|
|
122
|
+
return;
|
|
123
|
+
onConfig.forEach((func) => {
|
|
124
|
+
tryCatch(func)(collector, collector.session);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=on.js.map
|
package/dist/on.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on.js","sourceRoot":"","sources":["../src/on.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,EAAE,CAChB,SAA6B,EAC7B,IAAc,EACd,MAA0C;IAE1C,MAAM,EAAE,GAAG,SAAS,CAAC,EAAE,CAAC;IACxB,MAAM,MAAM,GAAsB,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;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AAO;QAAE,OAAO;IAE/B,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACxB,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/push.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Collector, WalkerOS } from '@walkeros/core';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the push function for the collector.
|
|
4
|
+
* Handles source mapping, event creation, and routing to destinations.
|
|
5
|
+
*
|
|
6
|
+
* @param collector - The walkerOS collector instance
|
|
7
|
+
* @param prepareEvent - Function to enrich partial events
|
|
8
|
+
* @returns The push function
|
|
9
|
+
*/
|
|
10
|
+
export declare function createPush<T extends Collector.Instance>(collector: T, prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent): Collector.PushFn;
|
|
11
|
+
//# sourceMappingURL=push.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../src/push.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAO,MAAM,gBAAgB,CAAC;AAU/D;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,SAAS,CAAC,QAAQ,EACrD,SAAS,EAAE,CAAC,EACZ,YAAY,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,gBAAgB,KAAK,QAAQ,CAAC,YAAY,GACxE,SAAS,CAAC,MAAM,CAwDlB"}
|
package/dist/push.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getGrantedConsent, processEventMapping, tryCatchAsync, useHooks, } from '@walkeros/core';
|
|
2
|
+
import { createEvent } from './handle';
|
|
3
|
+
import { pushToDestinations, createPushResult } from './destination';
|
|
4
|
+
/**
|
|
5
|
+
* Creates the push function for the collector.
|
|
6
|
+
* Handles source mapping, event creation, and routing to destinations.
|
|
7
|
+
*
|
|
8
|
+
* @param collector - The walkerOS collector instance
|
|
9
|
+
* @param prepareEvent - Function to enrich partial events
|
|
10
|
+
* @returns The push function
|
|
11
|
+
*/
|
|
12
|
+
export function createPush(collector, prepareEvent) {
|
|
13
|
+
return useHooks(async (event, context = {}) => {
|
|
14
|
+
return await tryCatchAsync(async () => {
|
|
15
|
+
let partialEvent = event;
|
|
16
|
+
// Apply source mapping if provided in context
|
|
17
|
+
if (context.mapping) {
|
|
18
|
+
const processed = await processEventMapping(partialEvent, context.mapping, collector);
|
|
19
|
+
// Check ignore flag
|
|
20
|
+
if (processed.ignore) {
|
|
21
|
+
return createPushResult({ ok: true });
|
|
22
|
+
}
|
|
23
|
+
// Check consent requirements
|
|
24
|
+
if (context.mapping.consent) {
|
|
25
|
+
const grantedConsent = getGrantedConsent(context.mapping.consent, collector.consent, processed.event.consent);
|
|
26
|
+
if (!grantedConsent) {
|
|
27
|
+
return createPushResult({ ok: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
partialEvent = processed.event;
|
|
31
|
+
}
|
|
32
|
+
// Prepare event (add timing, source info)
|
|
33
|
+
const enrichedEvent = prepareEvent(partialEvent);
|
|
34
|
+
// Create full event
|
|
35
|
+
const fullEvent = createEvent(collector, enrichedEvent);
|
|
36
|
+
// Push to destinations
|
|
37
|
+
return await pushToDestinations(collector, fullEvent);
|
|
38
|
+
}, () => {
|
|
39
|
+
return createPushResult({ ok: false });
|
|
40
|
+
})();
|
|
41
|
+
}, 'Push', collector.hooks);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=push.js.map
|
package/dist/push.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push.js","sourceRoot":"","sources":["../src/push.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,QAAQ,GACT,MAAM,gBAAgB,CAAC;A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AAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACxD,CAAC,EACD,GAAG,EAAE;YACH,OAAO,gBAAgB,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACzC,CAAC,CACF,EAAE,CAAC;IACN,CAAC,EACD,MAAM,EACN,SAAS,CAAC,KAAK,CACI,CAAC;AACxB,CAAC"}
|
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Collector, Source } from '@walkeros/core';
|
|
2
|
+
/**
|
|
3
|
+
* Initialize sources using the code/config/env pattern
|
|
4
|
+
*
|
|
5
|
+
* @param collector - The WalkerOS collector instance
|
|
6
|
+
* @param sources - Map of source definitions with code/config/env
|
|
7
|
+
* @returns Initialized sources
|
|
8
|
+
*/
|
|
9
|
+
export declare function initSources(collector: Collector.Instance, sources?: Source.InitSources): Promise<Collector.Sources>;
|
|
10
|
+
//# sourceMappingURL=source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAY,MAAM,gBAAgB,CAAC;AAGlE;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,SAAS,CAAC,QAAQ,EAC7B,OAAO,GAAE,MAAM,CAAC,WAAgB,GAC/B,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAiD5B"}
|
package/dist/source.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { tryCatchAsync } from '@walkeros/core';
|
|
2
|
+
/**
|
|
3
|
+
* Initialize sources using the code/config/env pattern
|
|
4
|
+
*
|
|
5
|
+
* @param collector - The WalkerOS collector instance
|
|
6
|
+
* @param sources - Map of source definitions with code/config/env
|
|
7
|
+
* @returns Initialized sources
|
|
8
|
+
*/
|
|
9
|
+
export async function initSources(collector, sources = {}) {
|
|
10
|
+
const result = {};
|
|
11
|
+
for (const [sourceId, sourceDefinition] of Object.entries(sources)) {
|
|
12
|
+
const { code, config = {}, env = {}, primary } = sourceDefinition;
|
|
13
|
+
// Create wrapped push that auto-applies source mapping config
|
|
14
|
+
const wrappedPush = (event, context = {}) => {
|
|
15
|
+
// Pass source config as mapping in context
|
|
16
|
+
return collector.push(event, {
|
|
17
|
+
...context,
|
|
18
|
+
mapping: config,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
// Create initial logger scoped to sourceId (type will be added after init)
|
|
22
|
+
const initialLogger = collector.logger.scope('source').scope(sourceId);
|
|
23
|
+
const cleanEnv = {
|
|
24
|
+
push: wrappedPush,
|
|
25
|
+
command: collector.command,
|
|
26
|
+
sources: collector.sources, // Provide access to all sources for chaining
|
|
27
|
+
elb: collector.sources.elb.push, // ELB source is always available
|
|
28
|
+
logger: initialLogger,
|
|
29
|
+
...env,
|
|
30
|
+
};
|
|
31
|
+
// Call source function with config and environment separately
|
|
32
|
+
const sourceInstance = await tryCatchAsync(code)(config, cleanEnv);
|
|
33
|
+
if (!sourceInstance)
|
|
34
|
+
continue; // Skip failed source initialization
|
|
35
|
+
// Update logger with actual source type: [type:sourceId] or [unknown:sourceId]
|
|
36
|
+
const sourceType = sourceInstance.type || 'unknown';
|
|
37
|
+
const sourceLogger = collector.logger.scope(sourceType).scope(sourceId);
|
|
38
|
+
cleanEnv.logger = sourceLogger;
|
|
39
|
+
// Store the primary flag in the source config for later access
|
|
40
|
+
if (primary) {
|
|
41
|
+
sourceInstance.config = { ...sourceInstance.config, primary };
|
|
42
|
+
}
|
|
43
|
+
result[sourceId] = sourceInstance;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CA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S,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACxE,QAAQ,CAAC,MAAM,GAAG,YAAY,CAAC;QAE/B,+DAA+D;QAC/D,IAAI,OAAO,EAAE,CAAC;YACZ,cAAc,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;QAChE,CAAC;QAED,MAAM,CAAC,QAAQ,CAAC,GAAG,cAAc,CAAC;IACpC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Destination, Mapping, On, WalkerOS } from '@walkeros/core';
|
|
2
|
+
export interface Settings {
|
|
3
|
+
scripts?: string[];
|
|
4
|
+
init?: string;
|
|
5
|
+
on?: string;
|
|
6
|
+
push?: string;
|
|
7
|
+
pushBatch?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface CodeMapping extends Mapping.Rule<CodeMapping> {
|
|
10
|
+
push?: string;
|
|
11
|
+
pushBatch?: string;
|
|
12
|
+
}
|
|
13
|
+
export type Types = Destination.Types<Settings, CodeMapping>;
|
|
14
|
+
export type Config = Destination.Config<Types>;
|
|
15
|
+
export type Context = Destination.Context<Types>;
|
|
16
|
+
export type InitContext = Destination.InitContext<Types>;
|
|
17
|
+
export type PushContext = Destination.PushContext<Types>;
|
|
18
|
+
export type PushBatchContext = Destination.PushBatchContext<Types>;
|
|
19
|
+
export type InitFn = (context: InitContext) => void;
|
|
20
|
+
export type OnFn = (type: On.Types, context: Context) => void;
|
|
21
|
+
export type PushFn = (event: WalkerOS.Event, context: PushContext) => void;
|
|
22
|
+
export type PushBatchFn = (batch: Destination.Batch<CodeMapping>, context: PushBatchContext) => void;
|
|
23
|
+
//# sourceMappingURL=code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/types/code.ts"],"names":[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