@walkeros/collector 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/__tests__/auto-run.test.d.ts +2 -0
  2. package/dist/__tests__/auto-run.test.d.ts.map +1 -0
  3. package/dist/__tests__/auto-run.test.js +105 -0
  4. package/dist/__tests__/auto-run.test.js.map +1 -0
  5. package/dist/__tests__/consent.test.d.ts +2 -0
  6. package/dist/__tests__/consent.test.d.ts.map +1 -0
  7. package/dist/__tests__/consent.test.js +21 -0
  8. package/dist/__tests__/consent.test.js.map +1 -0
  9. package/dist/__tests__/create-flow.test.d.ts +2 -0
  10. package/dist/__tests__/create-flow.test.d.ts.map +1 -0
  11. package/dist/__tests__/create-flow.test.js +69 -0
  12. package/dist/__tests__/create-flow.test.js.map +1 -0
  13. package/dist/__tests__/destination.test.d.ts +2 -0
  14. package/dist/__tests__/destination.test.d.ts.map +1 -0
  15. package/dist/__tests__/destination.test.js +242 -0
  16. package/dist/__tests__/destination.test.js.map +1 -0
  17. package/dist/__tests__/handle.test.d.ts +2 -0
  18. package/dist/__tests__/handle.test.d.ts.map +1 -0
  19. package/dist/__tests__/handle.test.js +78 -0
  20. package/dist/__tests__/handle.test.js.map +1 -0
  21. package/dist/__tests__/mapping.test.d.ts +2 -0
  22. package/dist/__tests__/mapping.test.d.ts.map +1 -0
  23. package/dist/__tests__/mapping.test.js +310 -0
  24. package/dist/__tests__/mapping.test.js.map +1 -0
  25. package/dist/__tests__/source.test.d.ts +2 -0
  26. package/dist/__tests__/source.test.d.ts.map +1 -0
  27. package/dist/__tests__/source.test.js +306 -0
  28. package/dist/__tests__/source.test.js.map +1 -0
  29. package/dist/__tests__/start-flow.test.d.ts +2 -0
  30. package/dist/__tests__/start-flow.test.d.ts.map +1 -0
  31. package/dist/__tests__/start-flow.test.js +167 -0
  32. package/dist/__tests__/start-flow.test.js.map +1 -0
  33. package/dist/__tests__/walker-entity.test.d.ts +2 -0
  34. package/dist/__tests__/walker-entity.test.d.ts.map +1 -0
  35. package/dist/__tests__/walker-entity.test.js +52 -0
  36. package/dist/__tests__/walker-entity.test.js.map +1 -0
  37. package/dist/collector.d.ts +3 -0
  38. package/dist/collector.d.ts.map +1 -0
  39. package/dist/collector.js +59 -0
  40. package/dist/collector.js.map +1 -0
  41. package/dist/command.d.ts +12 -0
  42. package/dist/command.d.ts.map +1 -0
  43. package/dist/command.js +20 -0
  44. package/dist/command.js.map +1 -0
  45. package/dist/consent.d.ts +10 -0
  46. package/dist/consent.d.ts.map +1 -0
  47. package/dist/consent.js +30 -0
  48. package/dist/consent.js.map +1 -0
  49. package/dist/constants.d.ts +13 -0
  50. package/dist/constants.d.ts.map +1 -0
  51. package/dist/constants.js +35 -0
  52. package/dist/constants.js.map +1 -0
  53. package/dist/destination.d.ts +56 -0
  54. package/dist/destination.d.ts.map +1 -0
  55. package/dist/destination.js +289 -0
  56. package/dist/destination.js.map +1 -0
  57. package/dist/dev.d.ts.map +1 -0
  58. package/dist/elb.d.ts +11 -0
  59. package/dist/elb.d.ts.map +1 -0
  60. package/dist/elb.js +60 -0
  61. package/dist/elb.js.map +1 -0
  62. package/dist/flow.d.ts +4 -0
  63. package/dist/flow.d.ts.map +1 -0
  64. package/dist/flow.js +44 -0
  65. package/dist/flow.js.map +1 -0
  66. package/dist/handle.d.ts +29 -0
  67. package/dist/handle.d.ts.map +1 -0
  68. package/dist/handle.js +161 -0
  69. package/dist/handle.js.map +1 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +1 -1
  72. package/dist/index.mjs +1 -1
  73. package/dist/on.d.ts +19 -0
  74. package/dist/on.d.ts.map +1 -0
  75. package/dist/on.js +116 -0
  76. package/dist/on.js.map +1 -0
  77. package/dist/push.d.ts +11 -0
  78. package/dist/push.d.ts.map +1 -0
  79. package/dist/push.js +43 -0
  80. package/dist/push.js.map +1 -0
  81. package/dist/schemas.d.ts +6 -0
  82. package/dist/schemas.d.ts.map +1 -0
  83. package/dist/schemas.js +37 -0
  84. package/dist/schemas.js.map +1 -0
  85. package/dist/source.d.ts +10 -0
  86. package/dist/source.d.ts.map +1 -0
  87. package/dist/source.js +40 -0
  88. package/dist/source.js.map +1 -0
  89. package/dist/types/collector.d.ts +19 -0
  90. package/dist/types/collector.d.ts.map +1 -0
  91. package/dist/types/collector.js +2 -0
  92. package/dist/types/collector.js.map +1 -0
  93. package/dist/types/index.d.ts +2 -0
  94. package/dist/types/index.d.ts.map +1 -0
  95. package/dist/types/index.js +2 -0
  96. package/dist/types/index.js.map +1 -0
  97. package/package.json +2 -2
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,{Commands:()=>i,Const:()=>c,addDestination:()=>l,commonHandleCommand:()=>O,createEvent:()=>E,createPush:()=>P,createPushResult:()=>m,destinationInit:()=>g,destinationPush:()=>f,initDestinations:()=>p,initSources:()=>H,on:()=>k,onApply:()=>v,pushToDestinations:()=>d,runCollector:()=>A,setConsent:()=>w,startFlow:()=>F}),module.exports=(e=a,((e,a,i,c)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of o(a))s.call(e,r)||r===i||n(e,r,{get:()=>a[r],enumerable:!(c=t(a,r))||c.enumerable});return e})(n({},"__esModule",{value:!0}),e));var i={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},c={Commands:i,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},r=require("@walkeros/core"),u=require("@walkeros/core");async function l(e,n,t){const{code:o,config:s={},env:a={}}=n,i=t||s||{init:!1},c={...o,config:i,env:b(o.env,a)};let r=c.config.id;if(!r)do{r=(0,u.getId)(4)}while(e.destinations[r]);return e.destinations[r]=c,!1!==c.config.queue&&(c.queue=[...e.queue]),d(e,void 0,{[r]:c})}async function d(e,n,t){const{allowed:o,consent:s,globals:a,user:i}=e;if(!o)return m({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const c=await Promise.all(Object.entries(t||{}).map(async([t,o])=>{let c=(o.queue||[]).map(e=>({...e,consent:s}));if(o.queue=[],n){const e=(0,u.clone)(n);c.push(e)}if(!c.length)return{id:t,destination:o,skipped:!0};const r=[],l=c.filter(e=>{const n=(0,u.getGrantedConsent)(o.config.consent,s,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(o.queue.concat(l),!r.length)return{id:t,destination:o,queue:c};if(!await(0,u.tryCatchAsync)(g)(e,o))return{id:t,destination:o,queue:c};let d=!1;return o.dlq||(o.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,u.assign)(a,n.globals),n.user=(0,u.assign)(i,n.user),await(0,u.tryCatchAsync)(f,t=>(e.config.onError&&e.config.onError(t,e),d=!0,o.dlq.push([n,t]),!1))(e,o,n),n))),{id:t,destination:o,error:d}})),r=[],l=[],d=[];for(const e of c){if(e.skipped)continue;const n=e.destination,t={id:e.id,destination:n};e.error?d.push(t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),l.push(t)):r.push(t)}return m({ok:!d.length,event:n,successful:r,queued:l,failed:d})}async function g(e,n){if(n.init&&!n.config.init){const t={collector:e,config:n.config,env:b(n.env,n.config.env)},o=await(0,u.useHooks)(n.init,"DestinationInit",e.hooks)(t);if(!1===o)return o;n.config={...o||n.config,init:!0}}return!0}async function f(e,n,t){const{config:o}=n,s=await(0,u.processEventMapping)(t,o,e);if(s.ignore)return!1;const a={collector:e,config:o,data:s.data,mapping:s.mapping,env:b(n.env,o.env)},i=s.mapping;if(i?.batch&&n.pushBatch){const t=i.batched||{key:s.mappingKey||"",events:[],data:[]};t.events.push(s.event),(0,u.isDefined)(s.data)&&t.data.push(s.data),i.batchFn=i.batchFn||(0,u.debounce)((e,n)=>{const a={collector:n,config:o,data:s.data,mapping:i,env:b(e.env,o.env)};(0,u.useHooks)(e.pushBatch,"DestinationPushBatch",n.hooks)(t,a),t.events=[],t.data=[]},i.batch),i.batched=t,i.batchFn?.(n,e)}else await(0,u.useHooks)(n.push,"DestinationPush",e.hooks)(s.event,a);return!0}function m(e){return(0,u.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function p(e,n={}){const t={};for(const[e,o]of Object.entries(n)){const{code:n,config:s={},env:a={}}=o,i={...n.config,...s},c=b(n.env,a);t[e]={...n,config:i,env:c}}return t}function b(e,n){return e||n?n?e&&(0,u.isObject)(e)&&(0,u.isObject)(n)?{...e,...n}:n:e:{}}var h=require("@walkeros/core"),y=require("@walkeros/core");function k(e,n,t){const o=e.on,s=o[n]||[],a=(0,h.isArray)(t)?t:[t];a.forEach(e=>{s.push(e)}),o[n]=s,v(e,n,a)}function v(e,n,t,o){let s,a=t||[];switch(t||(a=e.on[n]||[]),n){case c.Commands.Consent:s=o||e.consent;break;case c.Commands.Session:s=e.session;break;case c.Commands.Ready:case c.Commands.Run:default:s=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,y.tryCatch)(e.on)(n,s)}),Object.values(e.destinations).forEach(e=>{if(e.on){const t=e.on;(0,y.tryCatch)(t)(n,s)}}),a.length)switch(n){case c.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,y.tryCatch)(n[t])(e,o)})})}(e,a,o);break;case c.Commands.Ready:case c.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,y.tryCatch)(n)(e)})}(e,a);break;case c.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,y.tryCatch)(n)(e,e.session)})}(e,a)}}async function w(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,r.assign)(t,s),v(e,"consent",void 0,s),o?d(e):m({ok:!0})}var C=require("@walkeros/core"),q=require("@walkeros/core"),j=require("@walkeros/core");async function O(e,n,t,o){let s;switch(n){case c.Commands.Config:(0,j.isObject)(t)&&(0,q.assign)(e.config,t,{shallow:!1});break;case c.Commands.Consent:(0,j.isObject)(t)&&(s=await w(e,t));break;case c.Commands.Custom:(0,j.isObject)(t)&&(e.custom=(0,q.assign)(e.custom,t));break;case c.Commands.Destination:(0,j.isObject)(t)&&(0,q.isFunction)(t.push)&&(s=await l(e,{code:t},o));break;case c.Commands.Globals:(0,j.isObject)(t)&&(e.globals=(0,q.assign)(e.globals,t));break;case c.Commands.On:(0,q.isString)(t)&&k(e,t,o);break;case c.Commands.Ready:v(e,"ready");break;case c.Commands.Run:s=await A(e,t);break;case c.Commands.Session:v(e,"session");break;case c.Commands.User:(0,j.isObject)(t)&&(0,q.assign)(e.user,t,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function E(e,n){if(!n.name)throw new Error("Event name is required");const[t,o]=n.name.split(" ");if(!t||!o)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:i=e.count}=n,{name:c=`${t} ${o}`,data:r={},context:u={},globals:l=e.globals,custom:d={},user:g=e.user,nested:f=[],consent:m=e.consent,id:p=`${s}-${a}-${i}`,trigger:b="",entity:h=t,action:y=o,timing:k=0,version:v={source:e.version,tagging:e.config.tagging||0},source:w={type:"collector",id:"",previous_id:""}}=n;return{name:c,data:r,context:u,globals:l,custom:d,user:g,nested:f,consent:m,id:p,trigger:b,entity:h,action:y,timestamp:s,timing:k,group:a,count:i,version:v,source:w}}async function A(e,n){e.allowed=!0,e.count=0,e.group=(0,q.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,q.assign)(e.consent,n.consent)),n.user&&(e.user=(0,q.assign)(e.user,n.user)),n.globals&&(e.globals=(0,q.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,q.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await d(e);return v(e,"run"),t}var D=require("@walkeros/core");function P(e,n){return(0,D.useHooks)(async(t,o={})=>await(0,D.tryCatchAsync)(async()=>{let s=t;if(o.mapping){const n=await(0,D.processEventMapping)(s,o.mapping,e);if(n.ignore)return m({ok:!0});if(o.mapping.consent){if(!(0,D.getGrantedConsent)(o.mapping.consent,e.consent,n.event.consent))return m({ok:!0})}s=n.event}const a=n(s),i=E(e,a);return await d(e,i)},()=>m({ok:!1}))(),"Push",e.hooks)}var S=require("@walkeros/core");async function R(e){const n={globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0},t=(0,C.assign)(n,e,{merge:!1,extend:!1});function o(e,n){(0,C.onLog)({message:e},n||t.verbose)}t.onLog=o;const s={...t.globalsStatic,...e.globals},a={allowed:!1,config:t,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.3.1",sources:{},push:void 0,command:void 0};return a.push=P(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,S.useHooks)(async(t,o,s)=>await(0,S.tryCatchAsync)(async()=>await n(e,t,o,s),()=>m({ok:!1}))(),"Command",e.hooks)}(a,O),a.destinations=await p(0,e.destinations||{}),a}var x=require("@walkeros/core");async function H(e,n={}){const t={};for(const[o,s]of Object.entries(n)){const{code:n,config:a={},env:i={},primary:c}=s,r={push:(n,t={})=>e.push(n,{...t,mapping:a}),command:e.command,sources:e.sources,elb:e.sources.elb.push,...i},u=await(0,x.tryCatchAsync)(n)(a,r);u&&(c&&(u.config={...u.config,primary:c}),t[o]=u)}return t}async function F(e){e=e||{};const n=await R(e),t=(o=n,{type:"elb",config:{},push:async(e,n,t,s,a,i)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return o.command(s,n,t)}let c;if("string"==typeof e)c={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(c.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};c=e,n&&"object"==typeof n&&!Array.isArray(n)&&(c.data={...c.data||{},...n})}return s&&"object"==typeof s&&(c.context=s),a&&Array.isArray(a)&&(c.nested=a),i&&"object"==typeof i&&(c.custom=i),o.push(c)}});var o;n.sources.elb=t;const s=await H(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:i,globals:c,custom:r}=e;a&&await n.command("consent",a),i&&await n.command("user",i),c&&Object.assign(n.globals,c),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=t.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),d=l.find(e=>e.config.primary);return d?u=d.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}//# sourceMappingURL=index.js.map
1
+ "use strict";var e,n=Object.defineProperty,t=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,a={};((e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})})(a,{Commands:()=>i,Const:()=>c,addDestination:()=>l,commonHandleCommand:()=>O,createEvent:()=>E,createPush:()=>P,createPushResult:()=>m,destinationInit:()=>g,destinationPush:()=>f,initDestinations:()=>p,initSources:()=>H,on:()=>k,onApply:()=>v,pushToDestinations:()=>d,runCollector:()=>A,setConsent:()=>w,startFlow:()=>F}),module.exports=(e=a,((e,a,i,c)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of o(a))s.call(e,r)||r===i||n(e,r,{get:()=>a[r],enumerable:!(c=t(a,r))||c.enumerable});return e})(n({},"__esModule",{value:!0}),e));var i={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},c={Commands:i,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},r=require("@walkeros/core"),u=require("@walkeros/core");async function l(e,n,t){const{code:o,config:s={},env:a={}}=n,i=t||s||{init:!1},c={...o,config:i,env:b(o.env,a)};let r=c.config.id;if(!r)do{r=(0,u.getId)(4)}while(e.destinations[r]);return e.destinations[r]=c,!1!==c.config.queue&&(c.queue=[...e.queue]),d(e,void 0,{[r]:c})}async function d(e,n,t){const{allowed:o,consent:s,globals:a,user:i}=e;if(!o)return m({ok:!1});n&&e.queue.push(n),t||(t=e.destinations);const c=await Promise.all(Object.entries(t||{}).map(async([t,o])=>{let c=(o.queue||[]).map(e=>({...e,consent:s}));if(o.queue=[],n){const e=(0,u.clone)(n);c.push(e)}if(!c.length)return{id:t,destination:o,skipped:!0};const r=[],l=c.filter(e=>{const n=(0,u.getGrantedConsent)(o.config.consent,s,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(o.queue.concat(l),!r.length)return{id:t,destination:o,queue:c};if(!await(0,u.tryCatchAsync)(g)(e,o))return{id:t,destination:o,queue:c};let d=!1;return o.dlq||(o.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,u.assign)(a,n.globals),n.user=(0,u.assign)(i,n.user),await(0,u.tryCatchAsync)(f,t=>(e.config.onError&&e.config.onError(t,e),d=!0,o.dlq.push([n,t]),!1))(e,o,n),n))),{id:t,destination:o,error:d}})),r=[],l=[],d=[];for(const e of c){if(e.skipped)continue;const n=e.destination,t={id:e.id,destination:n};e.error?d.push(t):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),l.push(t)):r.push(t)}return m({ok:!d.length,event:n,successful:r,queued:l,failed:d})}async function g(e,n){if(n.init&&!n.config.init){const t={collector:e,config:n.config,env:b(n.env,n.config.env)},o=await(0,u.useHooks)(n.init,"DestinationInit",e.hooks)(t);if(!1===o)return o;n.config={...o||n.config,init:!0}}return!0}async function f(e,n,t){const{config:o}=n,s=await(0,u.processEventMapping)(t,o,e);if(s.ignore)return!1;const a={collector:e,config:o,data:s.data,mapping:s.mapping,env:b(n.env,o.env)},i=s.mapping;if(i?.batch&&n.pushBatch){const t=i.batched||{key:s.mappingKey||"",events:[],data:[]};t.events.push(s.event),(0,u.isDefined)(s.data)&&t.data.push(s.data),i.batchFn=i.batchFn||(0,u.debounce)((e,n)=>{const a={collector:n,config:o,data:s.data,mapping:i,env:b(e.env,o.env)};(0,u.useHooks)(e.pushBatch,"DestinationPushBatch",n.hooks)(t,a),t.events=[],t.data=[]},i.batch),i.batched=t,i.batchFn?.(n,e)}else await(0,u.useHooks)(n.push,"DestinationPush",e.hooks)(s.event,a);return!0}function m(e){return(0,u.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function p(e,n={}){const t={};for(const[e,o]of Object.entries(n)){const{code:n,config:s={},env:a={}}=o,i={...n.config,...s},c=b(n.env,a);t[e]={...n,config:i,env:c}}return t}function b(e,n){return e||n?n?e&&(0,u.isObject)(e)&&(0,u.isObject)(n)?{...e,...n}:n:e:{}}var h=require("@walkeros/core"),y=require("@walkeros/core");function k(e,n,t){const o=e.on,s=o[n]||[],a=(0,h.isArray)(t)?t:[t];a.forEach(e=>{s.push(e)}),o[n]=s,v(e,n,a)}function v(e,n,t,o){let s,a=t||[];switch(t||(a=e.on[n]||[]),n){case c.Commands.Consent:s=o||e.consent;break;case c.Commands.Session:s=e.session;break;case c.Commands.Ready:case c.Commands.Run:default:s=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,y.tryCatch)(e.on)(n,s)}),Object.values(e.destinations).forEach(e=>{if(e.on){const t=e.on;(0,y.tryCatch)(t)(n,s)}}),a.length)switch(n){case c.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,y.tryCatch)(n[t])(e,o)})})}(e,a,o);break;case c.Commands.Ready:case c.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,y.tryCatch)(n)(e)})}(e,a);break;case c.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,y.tryCatch)(n)(e,e.session)})}(e,a)}}async function w(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,r.assign)(t,s),v(e,"consent",void 0,s),o?d(e):m({ok:!0})}var C=require("@walkeros/core"),q=require("@walkeros/core"),j=require("@walkeros/core");async function O(e,n,t,o){let s;switch(n){case c.Commands.Config:(0,j.isObject)(t)&&(0,q.assign)(e.config,t,{shallow:!1});break;case c.Commands.Consent:(0,j.isObject)(t)&&(s=await w(e,t));break;case c.Commands.Custom:(0,j.isObject)(t)&&(e.custom=(0,q.assign)(e.custom,t));break;case c.Commands.Destination:(0,j.isObject)(t)&&(0,q.isFunction)(t.push)&&(s=await l(e,{code:t},o));break;case c.Commands.Globals:(0,j.isObject)(t)&&(e.globals=(0,q.assign)(e.globals,t));break;case c.Commands.On:(0,q.isString)(t)&&k(e,t,o);break;case c.Commands.Ready:v(e,"ready");break;case c.Commands.Run:s=await A(e,t);break;case c.Commands.Session:v(e,"session");break;case c.Commands.User:(0,j.isObject)(t)&&(0,q.assign)(e.user,t,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function E(e,n){if(!n.name)throw new Error("Event name is required");const[t,o]=n.name.split(" ");if(!t||!o)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:i=e.count}=n,{name:c=`${t} ${o}`,data:r={},context:u={},globals:l=e.globals,custom:d={},user:g=e.user,nested:f=[],consent:m=e.consent,id:p=`${s}-${a}-${i}`,trigger:b="",entity:h=t,action:y=o,timing:k=0,version:v={source:e.version,tagging:e.config.tagging||0},source:w={type:"collector",id:"",previous_id:""}}=n;return{name:c,data:r,context:u,globals:l,custom:d,user:g,nested:f,consent:m,id:p,trigger:b,entity:h,action:y,timestamp:s,timing:k,group:a,count:i,version:v,source:w}}async function A(e,n){e.allowed=!0,e.count=0,e.group=(0,q.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,q.assign)(e.consent,n.consent)),n.user&&(e.user=(0,q.assign)(e.user,n.user)),n.globals&&(e.globals=(0,q.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,q.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const t=await d(e);return v(e,"run"),t}var D=require("@walkeros/core");function P(e,n){return(0,D.useHooks)(async(t,o={})=>await(0,D.tryCatchAsync)(async()=>{let s=t;if(o.mapping){const n=await(0,D.processEventMapping)(s,o.mapping,e);if(n.ignore)return m({ok:!0});if(o.mapping.consent){if(!(0,D.getGrantedConsent)(o.mapping.consent,e.consent,n.event.consent))return m({ok:!0})}s=n.event}const a=n(s),i=E(e,a);return await d(e,i)},()=>m({ok:!1}))(),"Push",e.hooks)}var S=require("@walkeros/core");async function R(e){const n={globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0},t=(0,C.assign)(n,e,{merge:!1,extend:!1});function o(e,n){(0,C.onLog)({message:e},n||t.verbose)}t.onLog=o;const s={...t.globalsStatic,...e.globals},a={allowed:!1,config:t,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.4.1",sources:{},push:void 0,command:void 0};return a.push=P(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,S.useHooks)(async(t,o,s)=>await(0,S.tryCatchAsync)(async()=>await n(e,t,o,s),()=>m({ok:!1}))(),"Command",e.hooks)}(a,O),a.destinations=await p(0,e.destinations||{}),a}var x=require("@walkeros/core");async function H(e,n={}){const t={};for(const[o,s]of Object.entries(n)){const{code:n,config:a={},env:i={},primary:c}=s,r={push:(n,t={})=>e.push(n,{...t,mapping:a}),command:e.command,sources:e.sources,elb:e.sources.elb.push,...i},u=await(0,x.tryCatchAsync)(n)(a,r);u&&(c&&(u.config={...u.config,primary:c}),t[o]=u)}return t}async function F(e){e=e||{};const n=await R(e),t=(o=n,{type:"elb",config:{},push:async(e,n,t,s,a,i)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return o.command(s,n,t)}let c;if("string"==typeof e)c={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(c.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};c=e,n&&"object"==typeof n&&!Array.isArray(n)&&(c.data={...c.data||{},...n})}return s&&"object"==typeof s&&(c.context=s),a&&Array.isArray(a)&&(c.nested=a),i&&"object"==typeof i&&(c.custom=i),o.push(c)}});var o;n.sources.elb=t;const s=await H(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:i,globals:c,custom:r}=e;a&&await n.command("consent",a),i&&await n.command("user",i),c&&Object.assign(n.globals,c),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=t.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),d=l.find(e=>e.config.primary);return d?u=d.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}//# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var n={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},e={Commands:n,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}};import{assign as o}from"@walkeros/core";import{assign as s,clone as t,debounce as a,getId as i,getGrantedConsent as c,isDefined as r,isObject as u,processEventMapping as l,tryCatchAsync as m,useHooks as f}from"@walkeros/core";async function d(n,e,o){const{code:s,config:t={},env:a={}}=e,c=o||t||{init:!1},r={...s,config:c,env:y(s.env,a)};let u=r.config.id;if(!u)do{u=i(4)}while(n.destinations[u]);return n.destinations[u]=r,!1!==r.config.queue&&(r.queue=[...n.queue]),g(n,void 0,{[u]:r})}async function g(n,e,o){const{allowed:a,consent:i,globals:r,user:u}=n;if(!a)return b({ok:!1});e&&n.queue.push(e),o||(o=n.destinations);const l=await Promise.all(Object.entries(o||{}).map(async([o,a])=>{let l=(a.queue||[]).map(n=>({...n,consent:i}));if(a.queue=[],e){const n=t(e);l.push(n)}if(!l.length)return{id:o,destination:a,skipped:!0};const f=[],d=l.filter(n=>{const e=c(a.config.consent,i,n.consent);return!e||(n.consent=e,f.push(n),!1)});if(a.queue.concat(d),!f.length)return{id:o,destination:a,queue:l};if(!await m(p)(n,a))return{id:o,destination:a,queue:l};let g=!1;return a.dlq||(a.dlq=[]),await Promise.all(f.map(async e=>(e.globals=s(r,e.globals),e.user=s(u,e.user),await m(h,o=>(n.config.onError&&n.config.onError(o,n),g=!0,a.dlq.push([e,o]),!1))(n,a,e),e))),{id:o,destination:a,error:g}})),f=[],d=[],g=[];for(const n of l){if(n.skipped)continue;const e=n.destination,o={id:n.id,destination:e};n.error?g.push(o):n.queue&&n.queue.length?(e.queue=(e.queue||[]).concat(n.queue),d.push(o)):f.push(o)}return b({ok:!g.length,event:e,successful:f,queued:d,failed:g})}async function p(n,e){if(e.init&&!e.config.init){const o={collector:n,config:e.config,env:y(e.env,e.config.env)},s=await f(e.init,"DestinationInit",n.hooks)(o);if(!1===s)return s;e.config={...s||e.config,init:!0}}return!0}async function h(n,e,o){const{config:s}=e,t=await l(o,s,n);if(t.ignore)return!1;const i={collector:n,config:s,data:t.data,mapping:t.mapping,env:y(e.env,s.env)},c=t.mapping;if(c?.batch&&e.pushBatch){const o=c.batched||{key:t.mappingKey||"",events:[],data:[]};o.events.push(t.event),r(t.data)&&o.data.push(t.data),c.batchFn=c.batchFn||a((n,e)=>{const a={collector:e,config:s,data:t.data,mapping:c,env:y(n.env,s.env)};f(n.pushBatch,"DestinationPushBatch",e.hooks)(o,a),o.events=[],o.data=[]},c.batch),c.batched=o,c.batchFn?.(e,n)}else await f(e.push,"DestinationPush",n.hooks)(t.event,i);return!0}function b(n){return s({ok:!n?.failed?.length,successful:[],queued:[],failed:[]},n)}async function k(n,e={}){const o={};for(const[n,s]of Object.entries(e)){const{code:e,config:t={},env:a={}}=s,i={...e.config,...t},c=y(e.env,a);o[n]={...e,config:i,env:c}}return o}function y(n,e){return n||e?e?n&&u(n)&&u(e)?{...n,...e}:e:n:{}}import{isArray as w}from"@walkeros/core";import{tryCatch as v}from"@walkeros/core";function C(n,e,o){const s=n.on,t=s[e]||[],a=w(o)?o:[o];a.forEach(n=>{t.push(n)}),s[e]=t,q(n,e,a)}function q(n,o,s,t){let a,i=s||[];switch(s||(i=n.on[o]||[]),o){case e.Commands.Consent:a=t||n.consent;break;case e.Commands.Session:a=n.session;break;case e.Commands.Ready:case e.Commands.Run:default:a=void 0}if(Object.values(n.sources).forEach(n=>{n.on&&v(n.on)(o,a)}),Object.values(n.destinations).forEach(n=>{if(n.on){const e=n.on;v(e)(o,a)}}),i.length)switch(o){case e.Commands.Consent:!function(n,e,o){const s=o||n.consent;e.forEach(e=>{Object.keys(s).filter(n=>n in e).forEach(o=>{v(e[o])(n,s)})})}(n,i,t);break;case e.Commands.Ready:case e.Commands.Run:!function(n,e){n.allowed&&e.forEach(e=>{v(e)(n)})}(n,i);break;case e.Commands.Session:!function(n,e){if(!n.session)return;e.forEach(e=>{v(e)(n,n.session)})}(n,i)}}async function j(n,e){const{consent:s}=n;let t=!1;const a={};return Object.entries(e).forEach(([n,e])=>{const o=!!e;a[n]=o,t=t||o}),n.consent=o(s,a),q(n,"consent",void 0,a),t?g(n):b({ok:!0})}import{assign as E,onLog as O}from"@walkeros/core";import{assign as A,getId as S,isFunction as D,isString as x}from"@walkeros/core";import{isObject as R}from"@walkeros/core";async function P(n,o,s,t){let a;switch(o){case e.Commands.Config:R(s)&&A(n.config,s,{shallow:!1});break;case e.Commands.Consent:R(s)&&(a=await j(n,s));break;case e.Commands.Custom:R(s)&&(n.custom=A(n.custom,s));break;case e.Commands.Destination:R(s)&&D(s.push)&&(a=await d(n,{code:s},t));break;case e.Commands.Globals:R(s)&&(n.globals=A(n.globals,s));break;case e.Commands.On:x(s)&&C(n,s,t);break;case e.Commands.Ready:q(n,"ready");break;case e.Commands.Run:a=await L(n,s);break;case e.Commands.Session:q(n,"session");break;case e.Commands.User:R(s)&&A(n.user,s,{shallow:!1})}return a||{ok:!0,successful:[],queued:[],failed:[]}}function $(n,e){if(!e.name)throw new Error("Event name is required");const[o,s]=e.name.split(" ");if(!o||!s)throw new Error("Event name is invalid");++n.count;const{timestamp:t=Date.now(),group:a=n.group,count:i=n.count}=e,{name:c=`${o} ${s}`,data:r={},context:u={},globals:l=n.globals,custom:m={},user:f=n.user,nested:d=[],consent:g=n.consent,id:p=`${t}-${a}-${i}`,trigger:h="",entity:b=o,action:k=s,timing:y=0,version:w={source:n.version,tagging:n.config.tagging||0},source:v={type:"collector",id:"",previous_id:""}}=e;return{name:c,data:r,context:u,globals:l,custom:m,user:f,nested:d,consent:g,id:p,trigger:h,entity:b,action:k,timestamp:t,timing:y,group:a,count:i,version:w,source:v}}async function L(n,e){n.allowed=!0,n.count=0,n.group=S(),n.timing=Date.now(),e&&(e.consent&&(n.consent=A(n.consent,e.consent)),e.user&&(n.user=A(n.user,e.user)),e.globals&&(n.globals=A(n.config.globalsStatic||{},e.globals)),e.custom&&(n.custom=A(n.custom,e.custom))),Object.values(n.destinations).forEach(n=>{n.queue=[]}),n.queue=[],n.round++;const o=await g(n);return q(n,"run"),o}import{getGrantedConsent as B,processEventMapping as F,tryCatchAsync as G,useHooks as H}from"@walkeros/core";function I(n,e){return H(async(o,s={})=>await G(async()=>{let t=o;if(s.mapping){const e=await F(t,s.mapping,n);if(e.ignore)return b({ok:!0});if(s.mapping.consent){if(!B(s.mapping.consent,n.consent,e.event.consent))return b({ok:!0})}t=e.event}const a=e(t),i=$(n,a);return await g(n,i)},()=>b({ok:!1}))(),"Push",n.hooks)}import{useHooks as U,tryCatchAsync as M}from"@walkeros/core";async function W(n){const e=E({globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0},n,{merge:!1,extend:!1});function o(n,o){O({message:n},o||e.verbose)}e.onLog=o;const s={...e.globalsStatic,...n.globals},t={allowed:!1,config:e,consent:n.consent||{},count:0,custom:n.custom||{},destinations:{},globals:s,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:n.user||{},version:"0.3.1",sources:{},push:void 0,command:void 0};return t.push=I(t,n=>({timing:Math.round((Date.now()-t.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...n})),t.command=function(n,e){return U(async(o,s,t)=>await M(async()=>await e(n,o,s,t),()=>b({ok:!1}))(),"Command",n.hooks)}(t,P),t.destinations=await k(0,n.destinations||{}),t}import{tryCatchAsync as _}from"@walkeros/core";async function K(n,e={}){const o={};for(const[s,t]of Object.entries(e)){const{code:e,config:a={},env:i={},primary:c}=t,r={push:(e,o={})=>n.push(e,{...o,mapping:a}),command:n.command,sources:n.sources,elb:n.sources.elb.push,...i},u=await _(e)(a,r);u&&(c&&(u.config={...u.config,primary:c}),o[s]=u)}return o}async function z(n){n=n||{};const e=await W(n),o=(s=e,{type:"elb",config:{},push:async(n,e,o,t,a,i)=>{if("string"==typeof n&&n.startsWith("walker ")){const t=n.replace("walker ","");return s.command(t,e,o)}let c;if("string"==typeof n)c={name:n},e&&"object"==typeof e&&!Array.isArray(e)&&(c.data=e);else{if(!n||"object"!=typeof n)return{ok:!1,successful:[],queued:[],failed:[]};c=n,e&&"object"==typeof e&&!Array.isArray(e)&&(c.data={...c.data||{},...e})}return t&&"object"==typeof t&&(c.context=t),a&&Array.isArray(a)&&(c.nested=a),i&&"object"==typeof i&&(c.custom=i),s.push(c)}});var s;e.sources.elb=o;const t=await K(e,n.sources||{});Object.assign(e.sources,t);const{consent:a,user:i,globals:c,custom:r}=n;a&&await e.command("consent",a),i&&await e.command("user",i),c&&Object.assign(e.globals,c),r&&Object.assign(e.custom,r),e.config.run&&await e.command("run");let u=o.push;const l=Object.values(e.sources).filter(n=>"elb"!==n.type),m=l.find(n=>n.config.primary);return m?u=m.push:l.length>0&&(u=l[0].push),{collector:e,elb:u}}export{n as Commands,e as Const,d as addDestination,P as commonHandleCommand,$ as createEvent,I as createPush,b as createPushResult,p as destinationInit,h as destinationPush,k as initDestinations,K as initSources,C as on,q as onApply,g as pushToDestinations,L as runCollector,j as setConsent,z as startFlow};//# sourceMappingURL=index.mjs.map
1
+ var n={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},e={Commands:n,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}};import{assign as o}from"@walkeros/core";import{assign as s,clone as t,debounce as a,getId as i,getGrantedConsent as c,isDefined as r,isObject as u,processEventMapping as l,tryCatchAsync as m,useHooks as f}from"@walkeros/core";async function d(n,e,o){const{code:s,config:t={},env:a={}}=e,c=o||t||{init:!1},r={...s,config:c,env:y(s.env,a)};let u=r.config.id;if(!u)do{u=i(4)}while(n.destinations[u]);return n.destinations[u]=r,!1!==r.config.queue&&(r.queue=[...n.queue]),g(n,void 0,{[u]:r})}async function g(n,e,o){const{allowed:a,consent:i,globals:r,user:u}=n;if(!a)return b({ok:!1});e&&n.queue.push(e),o||(o=n.destinations);const l=await Promise.all(Object.entries(o||{}).map(async([o,a])=>{let l=(a.queue||[]).map(n=>({...n,consent:i}));if(a.queue=[],e){const n=t(e);l.push(n)}if(!l.length)return{id:o,destination:a,skipped:!0};const f=[],d=l.filter(n=>{const e=c(a.config.consent,i,n.consent);return!e||(n.consent=e,f.push(n),!1)});if(a.queue.concat(d),!f.length)return{id:o,destination:a,queue:l};if(!await m(p)(n,a))return{id:o,destination:a,queue:l};let g=!1;return a.dlq||(a.dlq=[]),await Promise.all(f.map(async e=>(e.globals=s(r,e.globals),e.user=s(u,e.user),await m(h,o=>(n.config.onError&&n.config.onError(o,n),g=!0,a.dlq.push([e,o]),!1))(n,a,e),e))),{id:o,destination:a,error:g}})),f=[],d=[],g=[];for(const n of l){if(n.skipped)continue;const e=n.destination,o={id:n.id,destination:e};n.error?g.push(o):n.queue&&n.queue.length?(e.queue=(e.queue||[]).concat(n.queue),d.push(o)):f.push(o)}return b({ok:!g.length,event:e,successful:f,queued:d,failed:g})}async function p(n,e){if(e.init&&!e.config.init){const o={collector:n,config:e.config,env:y(e.env,e.config.env)},s=await f(e.init,"DestinationInit",n.hooks)(o);if(!1===s)return s;e.config={...s||e.config,init:!0}}return!0}async function h(n,e,o){const{config:s}=e,t=await l(o,s,n);if(t.ignore)return!1;const i={collector:n,config:s,data:t.data,mapping:t.mapping,env:y(e.env,s.env)},c=t.mapping;if(c?.batch&&e.pushBatch){const o=c.batched||{key:t.mappingKey||"",events:[],data:[]};o.events.push(t.event),r(t.data)&&o.data.push(t.data),c.batchFn=c.batchFn||a((n,e)=>{const a={collector:e,config:s,data:t.data,mapping:c,env:y(n.env,s.env)};f(n.pushBatch,"DestinationPushBatch",e.hooks)(o,a),o.events=[],o.data=[]},c.batch),c.batched=o,c.batchFn?.(e,n)}else await f(e.push,"DestinationPush",n.hooks)(t.event,i);return!0}function b(n){return s({ok:!n?.failed?.length,successful:[],queued:[],failed:[]},n)}async function k(n,e={}){const o={};for(const[n,s]of Object.entries(e)){const{code:e,config:t={},env:a={}}=s,i={...e.config,...t},c=y(e.env,a);o[n]={...e,config:i,env:c}}return o}function y(n,e){return n||e?e?n&&u(n)&&u(e)?{...n,...e}:e:n:{}}import{isArray as w}from"@walkeros/core";import{tryCatch as v}from"@walkeros/core";function C(n,e,o){const s=n.on,t=s[e]||[],a=w(o)?o:[o];a.forEach(n=>{t.push(n)}),s[e]=t,q(n,e,a)}function q(n,o,s,t){let a,i=s||[];switch(s||(i=n.on[o]||[]),o){case e.Commands.Consent:a=t||n.consent;break;case e.Commands.Session:a=n.session;break;case e.Commands.Ready:case e.Commands.Run:default:a=void 0}if(Object.values(n.sources).forEach(n=>{n.on&&v(n.on)(o,a)}),Object.values(n.destinations).forEach(n=>{if(n.on){const e=n.on;v(e)(o,a)}}),i.length)switch(o){case e.Commands.Consent:!function(n,e,o){const s=o||n.consent;e.forEach(e=>{Object.keys(s).filter(n=>n in e).forEach(o=>{v(e[o])(n,s)})})}(n,i,t);break;case e.Commands.Ready:case e.Commands.Run:!function(n,e){n.allowed&&e.forEach(e=>{v(e)(n)})}(n,i);break;case e.Commands.Session:!function(n,e){if(!n.session)return;e.forEach(e=>{v(e)(n,n.session)})}(n,i)}}async function j(n,e){const{consent:s}=n;let t=!1;const a={};return Object.entries(e).forEach(([n,e])=>{const o=!!e;a[n]=o,t=t||o}),n.consent=o(s,a),q(n,"consent",void 0,a),t?g(n):b({ok:!0})}import{assign as E,onLog as O}from"@walkeros/core";import{assign as A,getId as S,isFunction as D,isString as x}from"@walkeros/core";import{isObject as R}from"@walkeros/core";async function P(n,o,s,t){let a;switch(o){case e.Commands.Config:R(s)&&A(n.config,s,{shallow:!1});break;case e.Commands.Consent:R(s)&&(a=await j(n,s));break;case e.Commands.Custom:R(s)&&(n.custom=A(n.custom,s));break;case e.Commands.Destination:R(s)&&D(s.push)&&(a=await d(n,{code:s},t));break;case e.Commands.Globals:R(s)&&(n.globals=A(n.globals,s));break;case e.Commands.On:x(s)&&C(n,s,t);break;case e.Commands.Ready:q(n,"ready");break;case e.Commands.Run:a=await L(n,s);break;case e.Commands.Session:q(n,"session");break;case e.Commands.User:R(s)&&A(n.user,s,{shallow:!1})}return a||{ok:!0,successful:[],queued:[],failed:[]}}function $(n,e){if(!e.name)throw new Error("Event name is required");const[o,s]=e.name.split(" ");if(!o||!s)throw new Error("Event name is invalid");++n.count;const{timestamp:t=Date.now(),group:a=n.group,count:i=n.count}=e,{name:c=`${o} ${s}`,data:r={},context:u={},globals:l=n.globals,custom:m={},user:f=n.user,nested:d=[],consent:g=n.consent,id:p=`${t}-${a}-${i}`,trigger:h="",entity:b=o,action:k=s,timing:y=0,version:w={source:n.version,tagging:n.config.tagging||0},source:v={type:"collector",id:"",previous_id:""}}=e;return{name:c,data:r,context:u,globals:l,custom:m,user:f,nested:d,consent:g,id:p,trigger:h,entity:b,action:k,timestamp:t,timing:y,group:a,count:i,version:w,source:v}}async function L(n,e){n.allowed=!0,n.count=0,n.group=S(),n.timing=Date.now(),e&&(e.consent&&(n.consent=A(n.consent,e.consent)),e.user&&(n.user=A(n.user,e.user)),e.globals&&(n.globals=A(n.config.globalsStatic||{},e.globals)),e.custom&&(n.custom=A(n.custom,e.custom))),Object.values(n.destinations).forEach(n=>{n.queue=[]}),n.queue=[],n.round++;const o=await g(n);return q(n,"run"),o}import{getGrantedConsent as B,processEventMapping as F,tryCatchAsync as G,useHooks as H}from"@walkeros/core";function I(n,e){return H(async(o,s={})=>await G(async()=>{let t=o;if(s.mapping){const e=await F(t,s.mapping,n);if(e.ignore)return b({ok:!0});if(s.mapping.consent){if(!B(s.mapping.consent,n.consent,e.event.consent))return b({ok:!0})}t=e.event}const a=e(t),i=$(n,a);return await g(n,i)},()=>b({ok:!1}))(),"Push",n.hooks)}import{useHooks as U,tryCatchAsync as M}from"@walkeros/core";async function W(n){const e=E({globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0},n,{merge:!1,extend:!1});function o(n,o){O({message:n},o||e.verbose)}e.onLog=o;const s={...e.globalsStatic,...n.globals},t={allowed:!1,config:e,consent:n.consent||{},count:0,custom:n.custom||{},destinations:{},globals:s,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:n.user||{},version:"0.4.1",sources:{},push:void 0,command:void 0};return t.push=I(t,n=>({timing:Math.round((Date.now()-t.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...n})),t.command=function(n,e){return U(async(o,s,t)=>await M(async()=>await e(n,o,s,t),()=>b({ok:!1}))(),"Command",n.hooks)}(t,P),t.destinations=await k(0,n.destinations||{}),t}import{tryCatchAsync as _}from"@walkeros/core";async function K(n,e={}){const o={};for(const[s,t]of Object.entries(e)){const{code:e,config:a={},env:i={},primary:c}=t,r={push:(e,o={})=>n.push(e,{...o,mapping:a}),command:n.command,sources:n.sources,elb:n.sources.elb.push,...i},u=await _(e)(a,r);u&&(c&&(u.config={...u.config,primary:c}),o[s]=u)}return o}async function z(n){n=n||{};const e=await W(n),o=(s=e,{type:"elb",config:{},push:async(n,e,o,t,a,i)=>{if("string"==typeof n&&n.startsWith("walker ")){const t=n.replace("walker ","");return s.command(t,e,o)}let c;if("string"==typeof n)c={name:n},e&&"object"==typeof e&&!Array.isArray(e)&&(c.data=e);else{if(!n||"object"!=typeof n)return{ok:!1,successful:[],queued:[],failed:[]};c=n,e&&"object"==typeof e&&!Array.isArray(e)&&(c.data={...c.data||{},...e})}return t&&"object"==typeof t&&(c.context=t),a&&Array.isArray(a)&&(c.nested=a),i&&"object"==typeof i&&(c.custom=i),s.push(c)}});var s;e.sources.elb=o;const t=await K(e,n.sources||{});Object.assign(e.sources,t);const{consent:a,user:i,globals:c,custom:r}=n;a&&await e.command("consent",a),i&&await e.command("user",i),c&&Object.assign(e.globals,c),r&&Object.assign(e.custom,r),e.config.run&&await e.command("run");let u=o.push;const l=Object.values(e.sources).filter(n=>"elb"!==n.type),m=l.find(n=>n.config.primary);return m?u=m.push:l.length>0&&(u=l[0].push),{collector:e,elb:u}}export{n as Commands,e as Const,d as addDestination,P as commonHandleCommand,$ as createEvent,I as createPush,b as createPushResult,p as destinationInit,h as destinationPush,k as initDestinations,K as initSources,C as on,q as onApply,g as pushToDestinations,L as runCollector,j as setConsent,z 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
@@ -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;AAK9D;;;;;;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,QA2D1B"}
package/dist/on.js ADDED
@@ -0,0 +1,116 @@
1
+ import { isArray } from '@walkeros/core';
2
+ import { Const } from './constants';
3
+ import { tryCatch } from '@walkeros/core';
4
+ /**
5
+ * Registers a callback for a specific event type.
6
+ *
7
+ * @param collector The walkerOS collector instance.
8
+ * @param type The type of the event to listen for.
9
+ * @param option The callback function or an array of callback functions.
10
+ */
11
+ export function on(collector, type, option) {
12
+ const on = collector.on;
13
+ const onType = on[type] || [];
14
+ const options = isArray(option) ? option : [option];
15
+ options.forEach((option) => {
16
+ onType.push(option);
17
+ });
18
+ // Update collector on state
19
+ on[type] = onType;
20
+ // Execute the on function directly
21
+ onApply(collector, type, options);
22
+ }
23
+ /**
24
+ * Applies all registered callbacks for a specific event type.
25
+ *
26
+ * @param collector The walkerOS collector instance.
27
+ * @param type The type of the event to apply the callbacks for.
28
+ * @param options The options for the callbacks.
29
+ * @param config The consent configuration.
30
+ */
31
+ export function onApply(collector, type, options, config) {
32
+ // Use the optionally provided options
33
+ let onConfig = options || [];
34
+ if (!options) {
35
+ // Get the collector on events
36
+ onConfig = collector.on[type] || [];
37
+ }
38
+ // Calculate context data once for all sources and destinations
39
+ let contextData;
40
+ switch (type) {
41
+ case Const.Commands.Consent:
42
+ contextData = config || collector.consent;
43
+ break;
44
+ case Const.Commands.Session:
45
+ contextData = collector.session;
46
+ break;
47
+ case Const.Commands.Ready:
48
+ case Const.Commands.Run:
49
+ default:
50
+ contextData = undefined;
51
+ break;
52
+ }
53
+ Object.values(collector.sources).forEach((source) => {
54
+ if (source.on) {
55
+ tryCatch(source.on)(type, contextData);
56
+ }
57
+ });
58
+ Object.values(collector.destinations).forEach((destination) => {
59
+ if (destination.on) {
60
+ // Cast to runtime-compatible version for type safety
61
+ const onFn = destination.on;
62
+ tryCatch(onFn)(type, contextData);
63
+ }
64
+ });
65
+ if (!onConfig.length)
66
+ return; // No on-events registered, nothing to do
67
+ switch (type) {
68
+ case Const.Commands.Consent:
69
+ onConsent(collector, onConfig, config);
70
+ break;
71
+ case Const.Commands.Ready:
72
+ onReady(collector, onConfig);
73
+ break;
74
+ case Const.Commands.Run:
75
+ onRun(collector, onConfig);
76
+ break;
77
+ case Const.Commands.Session:
78
+ onSession(collector, onConfig);
79
+ break;
80
+ default:
81
+ break;
82
+ }
83
+ }
84
+ function onConsent(collector, onConfig, currentConsent) {
85
+ const consentState = currentConsent || collector.consent;
86
+ onConfig.forEach((consentConfig) => {
87
+ // Collect functions whose consent keys match the rule keys directly
88
+ // Directly execute functions whose consent keys match the rule keys
89
+ Object.keys(consentState) // consent keys
90
+ .filter((consent) => consent in consentConfig) // check for matching rule keys
91
+ .forEach((consent) => {
92
+ // Execute the function
93
+ tryCatch(consentConfig[consent])(collector, consentState);
94
+ });
95
+ });
96
+ }
97
+ function onReady(collector, onConfig) {
98
+ if (collector.allowed)
99
+ onConfig.forEach((func) => {
100
+ tryCatch(func)(collector);
101
+ });
102
+ }
103
+ function onRun(collector, onConfig) {
104
+ if (collector.allowed)
105
+ onConfig.forEach((func) => {
106
+ tryCatch(func)(collector);
107
+ });
108
+ }
109
+ function onSession(collector, onConfig) {
110
+ if (!collector.session)
111
+ return;
112
+ onConfig.forEach((func) => {
113
+ tryCatch(func)(collector, collector.session);
114
+ });
115
+ }
116
+ //# 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;AAE1C;;;;;;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;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAEpD,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACzB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAA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AAO,CAAC,CAAC,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CACd,SAA6B,EAC7B,QAA+B;IAE/B,IAAI,SAAS,CAAC,OAAO;QACnB,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACxB,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,KAAK,CACZ,SAA6B,EAC7B,QAA6B;IAE7B,IAAI,SAAS,CAAC,OAAO;QACnB,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACxB,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,SAAS,CAChB,SAA6B,EAC7B,QAAiC;IAEjC,IAAI,CAAC,SAAS,CAAC,OAAO;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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1C,MAAM,aAAa,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;YAEjD,oBAAoB;YACpB,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;YAExD,uBAAuB;YACvB,OAAO,MAAM,kBAAkB,CAAC,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"}
@@ -0,0 +1,6 @@
1
+ import type { RJSFSchema } from '@rjsf/utils';
2
+ export declare const settingsSchema: RJSFSchema;
3
+ export declare const schemas: {
4
+ settings: RJSFSchema;
5
+ };
6
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAO,MAAM,cAAc,EAAE,UAmC5B,CAAC;AAEF,eAAO,MAAM,OAAO;;CAEnB,CAAC"}
@@ -0,0 +1,37 @@
1
+ export const settingsSchema = {
2
+ type: 'object',
3
+ properties: {
4
+ run: {
5
+ type: 'boolean',
6
+ description: 'Automatically start the collector pipeline on initialization',
7
+ },
8
+ sources: {
9
+ type: 'object',
10
+ description: 'Configurations for sources providing events to the collector',
11
+ },
12
+ destinations: {
13
+ type: 'object',
14
+ description: 'Configurations for destinations receiving processed events',
15
+ },
16
+ consent: {
17
+ type: 'object',
18
+ description: 'Initial consent state to control routing of events',
19
+ },
20
+ verbose: {
21
+ type: 'boolean',
22
+ description: 'Enable verbose logging for debugging',
23
+ },
24
+ onError: {
25
+ type: 'string',
26
+ description: 'Error handler triggered when the collector encounters failures',
27
+ },
28
+ onLog: {
29
+ type: 'string',
30
+ description: 'Custom log handler for collector messages',
31
+ },
32
+ },
33
+ };
34
+ export const schemas = {
35
+ settings: settingsSchema,
36
+ };
37
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAe;IACxC,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,GAAG,EAAE;YACH,IAAI,EAAE,SAAS;YACf,WAAW,EACT,8DAA8D;SACjE;QACD,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,8DAA8D;SACjE;QACD,YAAY,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,4DAA4D;SAC1E;QACD,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,oDAAoD;SAClE;QACD,OAAO,EAAE;YACP,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,sCAAsC;SACpD;QACD,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,gEAAgE;SACnE;QACD,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,2CAA2C;SACzD;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,QAAQ,EAAE,cAAc;CACzB,CAAC"}
@@ -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,CAwC5B"}
package/dist/source.js ADDED
@@ -0,0 +1,40 @@
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
+ const cleanEnv = {
22
+ push: wrappedPush,
23
+ command: collector.command,
24
+ sources: collector.sources, // Provide access to all sources for chaining
25
+ elb: collector.sources.elb.push, // ELB source is always available
26
+ ...env,
27
+ };
28
+ // Call source function with config and environment separately
29
+ const sourceInstance = await tryCatchAsync(code)(config, cleanEnv);
30
+ if (!sourceInstance)
31
+ continue; // Skip failed source initialization
32
+ // Store the primary flag in the source config for later access
33
+ if (primary) {
34
+ sourceInstance.config = { ...sourceInstance.config, primary };
35
+ }
36
+ result[sourceId] = sourceInstance;
37
+ }
38
+ return result;
39
+ }
40
+ //# 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,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,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3
+ consent?: WalkerOS.Consent;
4
+ user?: WalkerOS.User;
5
+ globals?: WalkerOS.Properties;
6
+ custom?: WalkerOS.Properties;
7
+ }
8
+ export type HandleCommandFn<T extends Collector.Instance> = (collector: T, action: string, data?: unknown, options?: unknown) => Promise<Elb.PushResult>;
9
+ export type CommandTypes = 'Action' | 'Actions' | 'Config' | 'Consent' | 'Context' | 'Custom' | 'Destination' | 'Elb' | 'Globals' | 'Hook' | 'Init' | 'Link' | 'On' | 'Prefix' | 'Ready' | 'Run' | 'Session' | 'User' | 'Walker';
10
+ export type StorageType = 'cookie' | 'local' | 'session';
11
+ export interface CreateCollector {
12
+ collector: Collector.Instance;
13
+ elb: WalkerOS.Elb;
14
+ }
15
+ export interface StartFlow<ElbPush extends WalkerOS.Elb = WalkerOS.Elb> {
16
+ collector: Collector.Instance;
17
+ elb: ElbPush;
18
+ }
19
+ //# sourceMappingURL=collector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../../src/types/collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAG/D,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC;IAC3B,IAAI,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC;IAC9B,MAAM,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC;CAC9B;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,SAAS,CAAC,QAAQ,IAAI,CAC1D,SAAS,EAAE,CAAC,EACZ,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,OAAO,KACd,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAE7B,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,SAAS,GACT,SAAS,GACT,QAAQ,GACR,aAAa,GACb,KAAK,GACL,SAAS,GACT,MAAM,GACN,MAAM,GACN,MAAM,GACN,IAAI,GACJ,QAAQ,GACR,OAAO,GACP,KAAK,GACL,SAAS,GACT,MAAM,GACN,QAAQ,CAAC;AAEb,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,SAAS,CAAC,QAAQ,CAAC;IAC9B,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC;CACnB;AAED,MAAM,WAAW,SAAS,CAAC,OAAO,SAAS,QAAQ,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG;IACpE,SAAS,EAAE,SAAS,CAAC,QAAQ,CAAC;IAC9B,GAAG,EAAE,OAAO,CAAC;CACd"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=collector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collector.js","sourceRoot":"","sources":["../../src/types/collector.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from './collector';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './collector';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
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.4.0",
4
+ "version": "0.4.1",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  "update": "npx npm-check-updates -u && npm update"
31
31
  },
32
32
  "dependencies": {
33
- "@walkeros/core": "0.4.0"
33
+ "@walkeros/core": "0.4.1"
34
34
  },
35
35
  "devDependencies": {},
36
36
  "repository": {