@walkeros/server-source-aws 4.2.1-next-1781715165983 → 4.2.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.
- package/CHANGELOG.md +2 -2
- package/dist/dev.js +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/walkerOS.json +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @walkeros/server-source-aws
|
|
2
2
|
|
|
3
|
-
## 4.2.1
|
|
3
|
+
## 4.2.1
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
- Updated dependencies [d1b41ca]
|
|
10
10
|
- Updated dependencies [0a8a08b]
|
|
11
11
|
- Updated dependencies [8afb7cc]
|
|
12
|
-
- @walkeros/core@4.2.1
|
|
12
|
+
- @walkeros/core@4.2.1
|
|
13
13
|
|
|
14
14
|
## 4.2.0
|
|
15
15
|
|
package/dist/dev.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,s=(e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})},i={};s(i,{examples:()=>I,schemas:()=>a,sqsExamples:()=>dt}),module.exports=(e=i,((e,s,i,a)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let c of o(s))r.call(e,c)||c===i||t(e,c,{get:()=>s[c],enumerable:!(a=n(s,c))||a.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a={};s(a,{CorsOptionsSchema:()=>f,CorsOrigin:()=>p,HttpMethod:()=>l,SettingsSchema:()=>g,settings:()=>h,sqsSettings:()=>S,sqsSetup:()=>q});var c=require("@walkeros/core/dev"),u=require("@walkeros/core/dev"),d=require("@walkeros/core/dev"),l=d.z.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),p=d.z.union([d.z.string(),d.z.array(d.z.string()),d.z.literal("*")]),f=d.z.object({origin:p.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:d.z.array(l).describe("Allowed HTTP methods").optional(),headers:d.z.array(d.z.string()).describe("Allowed request headers").optional(),credentials:d.z.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:d.z.number().int().positive().describe("Preflight cache duration in seconds").optional()}),g=u.z.object({cors:u.z.union([u.z.boolean(),f]).describe("CORS configuration: false = disabled, true = allow all origins, object = custom configuration").default(!0),timeout:u.z.number().int().positive().max(9e5).describe("Request timeout in milliseconds (max: 900000 for Lambda)").default(3e4),enablePixelTracking:u.z.boolean().describe("Enable GET requests with 1x1 transparent GIF response for pixel tracking").default(!0),healthPath:u.z.string().describe("Health check endpoint path (e.g., /health)").default("/health")}),h=(0,c.zodToSchema)(g),m=require("@walkeros/core/dev"),y=require("@walkeros/core/dev"),v=y.z.object({queueName:y.z.string().min(1).describe("SQS queue short name (like walkeros-events). Required for both setup and runtime poll."),region:y.z.string().describe("AWS region (like eu-central-1). Default: eu-central-1.").optional(),queueUrl:y.z.string().url().describe("Optional pre-resolved queue URL. When set, init skips the GetQueueUrl lookup.").optional(),client:y.z.any().describe("Pre-configured AWS SQSClient instance. Bypasses construction when supplied.").optional(),config:y.z.any().describe("AWS SDK SQSClientConfig (credentials, endpoint overrides, retries).").optional(),decoder:y.z.enum(["json","text","raw"]).describe("Decoder for the message body. json (default) parses JSON, text forwards UTF-8, raw forwards a Buffer.").optional(),maxMessages:y.z.number().int().min(1).max(10).describe("SQS receive batch size. Cap 10. Default: 10.").optional(),waitTimeSeconds:y.z.number().int().min(0).max(20).describe("Long-poll duration in seconds. Cap 20. Default: 20.").optional(),visibilityTimeout:y.z.number().int().nonnegative().describe("Per-receive visibility timeout override. Default: queue-configured value.").optional(),shutdownTimeoutMs:y.z.number().int().positive().describe("Graceful shutdown timeout in milliseconds. Default: 30000. After this window, destroy() force-closes.").optional(),onPushError:y.z.enum(["nack","ack"]).describe("Behavior when forwarding to the collector throws. nack (default) skips DeleteMessage so the message redelivers; ack drops it.").optional()}),w=require("@walkeros/core/dev"),b=w.z.record(w.z.string(),w.z.string()),k=w.z.object({region:w.z.string().min(1).describe("AWS region.").optional(),fifoQueue:w.z.boolean().describe("FIFO queue with content-based deduplication. Auto-appends .fifo suffix to the queue name.").optional(),visibilityTimeoutSeconds:w.z.number().int().nonnegative().describe("Visibility timeout in seconds. Default: 30.").optional(),messageRetentionSeconds:w.z.number().int().positive().describe("Message retention period in seconds. Default: 345600 (4 days).").optional(),maximumMessageSize:w.z.number().int().min(1024).max(262144).describe("Max message size in bytes. Default: 262144 (256 KB).").optional(),kmsMasterKeyId:w.z.string().describe("KMS key alias or ID for at-rest encryption.").optional(),deadLetterQueue:w.z.object({arn:w.z.string().describe("ARN of an existing DLQ. Mutually exclusive with create: true.").optional(),create:w.z.boolean().describe("Create a sibling DLQ named <queueName>-dlq. Default: false.").optional(),maxReceiveCount:w.z.number().int().min(1).max(1e3).describe("Max receive count before message goes to DLQ. Default: 5.").optional()}).describe("Optional dead-letter queue.").optional(),tags:b.describe("Tags applied to the queue (and inherited by an auto-created DLQ).").optional(),subscribeToSnsTopic:w.z.object({topicArn:w.z.string().min(1).describe("Topic ARN to subscribe to."),rawMessageDelivery:w.z.boolean().describe("Deliver SNS messages without the SNS envelope.").optional(),filterPolicy:w.z.record(w.z.string(),w.z.unknown()).describe("SNS filter policy applied at subscription level.").optional()}).describe("Optional SNS topic subscription. Creates the subscription and the matching queue policy.").optional()}),S=(0,m.zodToSchema)(v),q=(0,m.zodToSchema)(k),I={};s(I,{createTrigger:()=>ct,env:()=>C,step:()=>A,trigger:()=>ut});var C={};s(C,{push:()=>E});var O=()=>()=>Promise.resolve({ok:!0}),x=()=>{},j={error:x,warn:x,info:x,debug:x,throw:e=>{throw"string"==typeof e?new Error(e):e},json:x,scope:()=>j},E={get push(){return O()},get command(){return O()},get elb(){return O()},logger:j},A={};s(A,{apiGatewayV1Post:()=>T,lambdaGet:()=>P,lambdaPost:()=>D});var D={title:"Lambda POST",description:"An API Gateway v2 HTTP POST with a JSON body is converted into a walker elb event.",trigger:{type:"POST"},in:{version:"2.0",requestContext:{http:{method:"POST",path:"/collect"},requestId:"req-123"},body:JSON.stringify({event:"page view",data:{title:"Home"}}),isBase64Encoded:!1},out:[["elb",{name:"page view",data:{title:"Home"}}]]},T={title:"API Gateway v1 POST",description:"A REST API Gateway v1 POST request with a JSON body is converted into a walker elb event.",trigger:{type:"POST"},in:{httpMethod:"POST",path:"/collect",requestContext:{requestId:"req-789",identity:{sourceIp:"203.0.113.42"}},queryStringParameters:null,body:JSON.stringify({event:"page view",data:{title:"Home"}}),isBase64Encoded:!1},out:[["elb",{name:"page view",data:{title:"Home"}}]]},P={title:"Lambda GET",description:"An API Gateway v2 HTTP GET with query parameters is parsed into an elb event payload.",trigger:{type:"GET"},in:{version:"2.0",requestContext:{http:{method:"GET",path:"/collect"},requestId:"req-456"},rawQueryString:"e=page+view&d=%7B%22title%22%3A%22Home%22%7D",isBase64Encoded:!1},out:[["elb",{e:"page view",d:'{"title":"Home"}'}]]},M=require("@walkeros/core"),z=require("@walkeros/core"),$=require("@walkeros/core"),_=(require("@walkeros/core"),require("@walkeros/core")),H=require("@walkeros/core"),N=require("@walkeros/core"),R=require("@walkeros/core"),G=require("@walkeros/core"),B=require("@walkeros/core"),F=require("@walkeros/core"),U=require("@walkeros/core"),L=require("@walkeros/core"),K=require("@walkeros/core"),Q=require("@walkeros/core"),J={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",Scoped:"_",Session:"session",Shutdown:"shutdown",User:"user",Walker:"walker"};function W(e,t){const n=e.status.startedAt;return{flowId:"default",stepId:t.stepId,stepType:t.stepType,phase:t.phase,eventId:t.eventId,timestamp:new Date(t.now).toISOString(),elapsedMs:t.now-n}}function V(e,t,n,o){if(!Number.isFinite(n.max)||n.max<=0)throw new Error(`pushBounded: max must be > 0 (got ${n.max})`);if("dropNewest"===(n.onOverflow??"dropOldest"))return e.length>=n.max?(o&&o([t]),{appended:!1,dropped:1}):(e.push(t),{appended:!0,dropped:0});const r=[];for(;e.length>=n.max;)r.push(e.shift());return e.push(t),r.length>0&&o&&o(r),{appended:!0,dropped:r.length}}var Y=new WeakMap;function X(e,t,n,o){Y.get(e)||(Y.set(e,!0),t.warn(n,o))}function Z(e){Y.delete(e)}var ee=()=>Date.now();function te(e){if(void 0!==e)return"number"==typeof e?{threshold:e,cooldown:3e4}:{threshold:e.threshold??5,cooldown:e.cooldown??3e4}}function ne(e,t,n,o,r){if("partial"===n)return;const s=((i=e)[a=t]||(i[a]={state:"closed",consecutiveFailures:0}),i[a]);var i,a;return"success"===n?(s.consecutiveFailures=0,s.state="closed",s.probing=!1,void(s.openUntil=void 0)):(s.consecutiveFailures+=1,"half-open"===s.state?(s.state="open",s.probing=!1,void(s.openUntil=ee()+r)):void(s.consecutiveFailures>=o&&(s.state="open",s.probing=!1,s.openUntil=ee()+r)))}function oe(e,t){return e.status.destinations[t]||(e.status.destinations[t]={count:0,failed:0,duration:0,queuePushSize:0,dlqSize:0}),e.status.destinations[t]}function re(e,t,n,o){e.dropped[t]||(e.dropped[t]={});const r=e.dropped[t];return r[n]=(r[n]??0)+o,r[n]}function se(e,t,n,o,r){const s=(0,N.stepId)(t,n);return(t,i)=>{try{if(i)return r?function(e,t,n,o,r,s){const i=t.dlq=t.dlq||[],a={max:t.config.dlqMax??100},c=V(i,[o,r],a);if(c.dropped>0){const t=re(e.status,(0,N.stepId)("destination",n),"dlq",c.dropped);X(i,s,"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:n,cap:a.max,droppedCount:t})}else i.length<a.max&&Z(i);const u=oe(e,n);u.failed++,u.dlqSize=i.length,e.status.failed++;const d=te(t.config.breaker);if(d){const o=t.config.id||n;ne(e.status.breakers,(0,N.stepId)("destination",o),"transport-failure",d.threshold,d.cooldown)}}(e,r,n,i,t,o):e.status.failed++,void o.error("report error",{error:t instanceof Error?t.message:String(t),event:i.name});e.status.connectionErrors[s]=(e.status.connectionErrors[s]??0)+1,o.error("connection error",{error:t instanceof Error?t.message:String(t)})}catch{}}}function ie(e,t){return e.storeId&&t.stores[e.storeId]?t.stores[e.storeId]:t.stores.__cache}function ae(e,t){return e?t.stores[e]:t.stores.__cache}function ce(e){const t={};for(const[n,o]of Object.entries(e)){const e=o.config?.next;"string"==typeof e||Array.isArray(e)&&e.every(e=>"string"==typeof e)?t[n]={next:e}:t[n]={}}return t}function ue(e,t){const n=e.config||{},o=e[t];return void 0!==o?{config:{...n,[t]:o},chainValue:o}:{config:n,chainValue:void 0}}function de(e,t={}){if(!e)return[];if(Array.isArray(e))return e;const n=[],o=new Set;let r=e;for(;r&&t[r]&&!o.has(r);){o.add(r),n.push(r);const e=t[r].next;if(Array.isArray(e)){n.push(...e);break}r=e}return n}async function le(e,t,n){if(t.init&&!t.config.init){const o=t.type||"unknown",r=e.logger.scope(`transformer:${o}`),s={collector:e,logger:r,id:n,ingest:(0,G.createIngest)(n),config:t.config,env:he(t.config.env),reportError:se(e,"transformer",n,r)};r.debug("init");const i=await(0,G.useHooks)(t.init,"TransformerInit",e.hooks,e.logger)(s);if(!1===i)return!1;t.config={...i||t.config,env:i?.env||t.config.env,init:!0},r.debug("init done")}return!0}async function pe(e,t,n,o,r,s){const i=t.type||"unknown",a=e.logger.scope(`transformer:${i}`),c={collector:e,logger:a,id:n,ingest:r,config:t.config,env:{...he(t.config.env),...s?{respond:s}:{}},reportError:se(e,"transformer",n,a)};a.debug("push",{event:o.name});const u="string"==typeof o.id?o.id:"",d=Date.now(),l=W(e,{stepId:(0,G.stepId)("transformer",n),stepType:"transformer",phase:"in",eventId:u,now:d});l.inEvent=o,(0,G.emitStep)(e,l);try{const r=await(0,G.useHooks)(t.push,"TransformerPush",e.hooks,e.logger)(o,c),s=Date.now(),i=W(e,{stepId:(0,G.stepId)("transformer",n),stepType:"transformer",phase:"out",eventId:u,now:s});return i.durationMs=s-d,i.outEvent=r,(0,G.emitStep)(e,i),a.debug("push done"),r}catch(t){const o=Date.now(),r=W(e,{stepId:(0,G.stepId)("transformer",n),stepType:"transformer",phase:"error",eventId:u,now:o});throw r.durationMs=o-d,r.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},(0,G.emitStep)(e,r),t}}function fe(e,t){return e?{...e,_meta:{...e._meta,path:[...e._meta.path]}}:(0,G.createIngest)(t)}async function ge(e,t,n,o,r,s,i){r||(r=(0,G.createIngest)(n[0]??"chain")),i&&r._meta&&(r._meta.chainPath=i);let a=o,c=s;for(const o of n){const s=t[o];if(!s){e.logger.warn(`Transformer not found: ${o}`);continue}if(r&&r._meta&&r._meta.path.length>256)return e.logger.error(`Max path length exceeded at ${o}`),{event:null,respond:c};if(r&&r._meta&&(r._meta.hops++,r._meta.path.push(o)),!await(0,G.tryCatchAsync)(le,t=>{if(t instanceof G.FatalError)throw t;return e.status.failed++,e.logger.scope(`transformer:${s.type||"unknown"}`).error("transformer init failed",{transformer:o,error:t}),!1})(e,s,o))return{event:null,respond:c};if(i&&void 0!==s.config?.chainMocks?.[i]){const t=s.config.chainMocks[i];e.logger.scope(`transformer:${s.type||"unknown"}`).debug("chainMock",{chain:i}),a=t;continue}if(void 0!==s.config?.mock){e.logger.scope(`transformer:${s.type||"unknown"}`).debug("mock"),a=s.config.mock;continue}if(s.config?.disabled)continue;const u=s.config?.cache,d=u?(0,G.compileCache)(u):void 0,l=d?ie(d,e):void 0,p=s.config?.state?(0,G.compileState)(s.config.state):void 0,f=p?.filter(e=>"get"===e.mode),g=p?.filter(e=>"set"===e.mode),h=async t=>g&&0!==g.length?(0,G.applyState)(g,t=>ae(t,e),t,e):t;let m;if(d&&l){const e=(0,G.buildCacheContext)(r,a),t=await(0,G.checkCache)(d,l,e);if("HIT"===t?.status&&t.value){if(a=t.value,d.stop)return{event:a,respond:c,stopped:!0};continue}"MISS"===t?.status&&(m={key:t.key,ttl:t.rule.ttl})}const y=s.config.before;if(y){const n=(0,G.getNextSteps)(y,(0,G.buildCacheContext)(r,a));if(1===n.length){const o=de(n[0],ce(t));if(o.length>0){const n=await ge(e,t,o,a,r,c,i);if(null===n.event)return{event:null,respond:n.respond??c};if(n.stopped)return{event:Array.isArray(n.event)?n.event[0]:n.event,respond:n.respond??c,stopped:!0};n.respond&&(c=n.respond),a=Array.isArray(n.event)?n.event[0]:n.event}}else n.length>1&&await Promise.all(n.map(n=>(0,G.tryCatchAsync)(ge,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,de(n,ce(t)),a,fe(r,n),void 0,i)))}f&&f.length>0&&(a=await(0,G.applyState)(f,t=>ae(t,e),a,e));const v=await(0,G.tryCatchAsync)(pe,t=>(e.logger.scope(`transformer:${s.type||"unknown"}`).error("Push failed",{error:t}),!1))(e,s,o,a,r,c);if(!1===v)return{event:null,respond:c};if(Array.isArray(v)){const s=n.slice(n.indexOf(o)+1),u=await Promise.all(v.map(async n=>{const o=await h(n.event||a),u=fe(r,"unknown");if(n.next){const r=(0,G.getNextSteps)(n.next,(0,G.buildCacheContext)(u,o));if(0===r.length)return{event:o,respond:c};if(1===r.length){const n=de(r[0],ce(t));return n.length>0?ge(e,t,n,o,u,c,i):{event:o,respond:c}}return(await Promise.all(r.map(n=>(0,G.tryCatchAsync)(ge,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,de(n,ce(t)),o,fe(u,n),void 0,i)))).map(e=>({event:e.event,respond:void 0}))}return s.length>0?ge(e,t,s,o,u,c,i):{event:o,respond:c}}));let d=c;const l=[];for(const e of u.flat())if(null!==e)if(e&&"object"==typeof e&&"event"in e){const t=e;if(t.respond&&(d=t.respond),null===t.event)continue;Array.isArray(t.event)?l.push(...t.event):l.push(t.event)}else l.push(e);return 0===l.length?{event:null,respond:d}:1===l.length?{event:l[0],respond:d}:{event:l,respond:d}}if(v&&"object"==typeof v){const{event:n,respond:o,next:s}=v;if(o&&(c=o),void 0!==s){const o=await h(n||a),u=(0,G.getNextSteps)(s,(0,G.buildCacheContext)(r,o));if(0===u.length){a=o;continue}if(1===u.length){const n=de(u[0],ce(t));return n.length>0?ge(e,t,n,o,r,c,i):(e.logger.warn(`Branch target not found: ${JSON.stringify(s)}`),{event:null,respond:c})}return await Promise.all(u.map(n=>(0,G.tryCatchAsync)(ge,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,de(n,ce(t)),o,fe(r,n),void 0,i))),{event:null,respond:void 0}}n&&(a=n)}g&&g.length>0&&(a=await(0,G.applyState)(g,t=>ae(t,e),a,e)),m&&l&&(0,G.storeCache)(l,m.key,a,m.ttl);const w=s.config.next,b="string"==typeof w||Array.isArray(w)&&w.every(e=>"string"==typeof e),k=void 0!==w&&!b;if((!v||"object"==typeof v&&!v.next)&&k){const n=(0,G.getNextSteps)(s.config.next,(0,G.buildCacheContext)(r,a));if(1===n.length){const o=de(n[0],ce(t));return o.length>0?ge(e,t,o,a,r,c,i):{event:a,respond:c}}return n.length>1?(await Promise.all(n.map(n=>(0,G.tryCatchAsync)(ge,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,de(n,ce(t)),a,fe(r,n),void 0,i))),{event:null,respond:void 0}):{event:a,respond:c}}}return{event:a,respond:c}}function he(e){return e&&(0,G.isObject)(e)?e:{}}function me(e){return"string"==typeof e||!(!Array.isArray(e)||!e.every(e=>"string"==typeof e))}async function ye(e,t,n){if(!t.on||!t.queueOn?.length)return;const o=t.queueOn;t.queueOn=[];const r=n||t.config?.id||"unknown";for(const{type:n,data:s}of o)Oe(n)&&!De(e,t,n)||(await(0,R.tryCatchAsync)(t.on,t=>{if(t instanceof R.FatalError)throw t;e.status.failed++,e.logger.scope("source").error("source on flush failed",{sourceId:r,type:n,error:t})})(n,s),Oe(n)&&Ae(e,t,n))}function ve(e){return Boolean(e.config.init)&&!e.config.require?.length}async function we(e,t,n){const{code:o,config:r={},env:s={},primary:i,next:a,before:c,cache:u}=n,d=r.state??n.state,l=d?(0,R.compileState)(d):void 0,p=u,f=p?(0,R.compileCache)({...p,stop:p.stop??!0}):void 0,g=me(a)?de(a,ce(e.transformers)):void 0,h=me(c)?de(c,ce(e.transformers)):void 0,m=s.push,y=m??e.push,v=Boolean(m),w=async(n,o,s)=>{let i;const u=h??(void 0!==c?(()=>{const t=(0,R.getNextSteps)(c,(0,R.buildCacheContext)(s.ingest));return 0===t.length?[]:de(1===t.length?t[0]:t,ce(e.transformers))})():[]);let d=[n];if(u.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const o=await ge(e,e.transformers,u,n,s.ingest,s.respond,`source.${t}.before`);if(null===o.event)return{ok:!0};if(o.stopped)return o.respond&&(s.respond=o.respond),{ok:!0};o.respond&&(s.respond=o.respond),d=Array.isArray(o.event)?o.event:[o.event]}if(f){const t=ie(f,e);if(t){const n=(0,R.buildCacheContext)(s.ingest),o=await(0,R.checkCache)(f,t,n);if(o){if("HIT"===o.status&&void 0!==o.value&&f.stop){let t=o.value;return o.rule.update&&(t=await(0,R.applyUpdate)(t,o.rule.update,{...n,cache:{status:"HIT"}},e)),s.respond?.(t),{ok:!0}}if("MISS"===o.status&&f.stop&&s.respond){const r=s.respond,a=o.rule.update,c={...n,cache:{status:"MISS"}},u=o.key,d=o.rule.ttl,l=n=>{(0,R.storeCache)(t,u,n,d),a?i=(async()=>{const t=await(0,R.applyUpdate)(n,a,c,e);r(t)})():r(n)};s.respond=l}"MISS"!==o.status||f.stop||(0,R.storeCache)(t,o.key,!0,o.rule.ttl)}}}const p=g?{kind:"single",preChain:g}:void 0!==a?(()=>{const t=(0,R.getNextSteps)(a,(0,R.buildCacheContext)(s.ingest));return 0===t.length?{kind:"single",preChain:[]}:1===t.length?{kind:"single",preChain:de(t[0],ce(e.transformers))}:{kind:"many",branches:t.map(t=>de(t,ce(e.transformers)))}})():{kind:"single",preChain:[]};!v&&l&&l.length>0&&(d=await Promise.all(d.map(t=>(0,R.applyState)(l,t=>ae(t,e),t,e))));let m={ok:!0};for(const n of d)"many"===p.kind?(await Promise.all(p.branches.map((i,a)=>(0,R.tryCatchAsync)(async()=>v?y(n):y(n,{...o,id:t,ingest:fe(s.ingest,`${t}.${a}`),respond:void 0,mapping:r,preChain:i}),t=>(e.logger.scope("source:many").error(`many branch ${a} failed`,{error:t}),{ok:!0}))())),m={ok:!0}):m=v?await y(n):await y(n,{...o,id:t,ingest:s.ingest,respond:s.respond,mapping:r,preChain:p.preChain});return i&&await i,m},b=async n=>{const o=(0,R.createIngest)(t);if(!r.ingest||void 0===n)return o;const s=await(0,R.getMappingValue)(n,r.ingest,{collector:e});return{...o,...s,_meta:o._meta}},k=e.logger.scope("source").scope(t),S={command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:k,...s,push:async(e,n={})=>{const o={ingest:(0,R.createIngest)(t),respond:void 0};return w(e,n,o)}},q={collector:e,logger:k,id:t,config:r,env:S,withScope:async(e,t,n)=>{const o={ingest:await b(e),respond:t};return n({...S,push:(e,t={})=>w(e,t,o),ingest:o.ingest,respond:o.respond})},reportError:se(e,"source",t,k)},I=await(0,R.tryCatchAsync)(o,n=>{if(n instanceof R.FatalError)throw n;e.status.failed++,e.logger.scope("source").error("source factory failed",{sourceId:t,error:n})})(q);if(!I)return;const C=I.type||"unknown",O=e.logger.scope(C).scope(t);return S.logger=O,i&&(I.config={...I.config,primary:i}),I}async function be(e){for(const[t,n]of Object.entries(e.sources)){if(ve(n))continue;const o=n.config.require;if(!o?.length)continue;const r=o.filter(t=>!je(e,t));r.length!==o.length&&(n.config.require=r,ve(n)&&await ye(e,n,t))}for(const[t,n]of Object.entries(e.pending.destinations)){if(!e.pending.destinations[t]||e.destinations[t])continue;const o=n.config?.require;if(!o)continue;const r=o.filter(t=>!je(e,t));if(n.config&&(n.config.require=r),r.length>0)continue;delete e.pending.destinations[t];const s=We(n);!1!==s.config.queue&&(s.queuePush=[...e.queue]),e.destinations[t]=s}}function ke(e){if("object"!=typeof e||null===e)return!1;if(!("logger"in e))return!1;const t=e.logger;return"object"==typeof t&&null!==t&&"scope"in t&&"function"==typeof t.scope}var Se=!1;function qe(){Se||(Se=!0,"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn("walkerOS: ignored an on-dispatch call with a non-collector argument"))}function Ie(e,t,n,o){if(n instanceof _.FatalError)throw n;e.logger.scope("on").error("on callback failed",{kind:t,...o,error:n})}var Ce=[J.Consent,J.User,J.Globals,J.Custom];function Oe(e){return Ce.includes(e)}function xe(e,t){switch(t){case J.Consent:return Object.keys(e.consent).length>0;case J.User:return Object.keys(e.user).length>0;case J.Globals:return Object.keys(e.globals).length>0;case J.Custom:return Object.keys(e.custom).length>0;default:return!1}}function je(e,t){switch(t){case J.Consent:case J.User:case J.Globals:case J.Custom:return xe(e,t);case J.Run:case J.Ready:return!0===e.allowed;default:return e.seenEvents.has(String(t))}}function Ee(e,t){return e.cellVersion[String(t)]??0}function Ae(e,t,n){let o=e.delivery.get(t);o||(o={},e.delivery.set(t,o)),o[String(n)]=Ee(e,n)}function De(e,t,n){return e.allowed&&Ee(e,n)>function(e,t,n){const o=e.delivery.get(t),r=o?.[String(n)];return void 0===r?-1:r}(e,t,n)}function Te(e,t,n){const o=e.cascade;if(!o)return!0;let r=o.counts.get(t);r||(r={},o.counts.set(t,r));const s=String(n),i=(r[s]||0)+1;return r[s]=i,i<=8||(9===i&&e.logger.error("state delivery did not converge",{type:s}),!1)}function Pe(e,t){return{collector:e,logger:e.logger.scope("on").scope(String(t))}}function Me(e,t,n,o,r){if(!t.on)return;const s=t.type||"unknown",i=e.logger.scope(s).scope("on").scope(o),a={collector:e,logger:i,id:n,config:t.config,data:r,env:Ve(t.env,t.config.env),reportError:se(e,"destination",n,i,t)};(0,H.tryCatch)(t.on,t=>Ie(e,"destination",t,{destId:n,type:o}))(o,a)}function ze(e,t,n,o){if(!ke(e))return void qe();const r=$e(e,t,o);if(n.length)switch(t){case J.Consent:!function(e,t,n){const o=n||e.consent,r=Pe(e,J.Consent);t.forEach(t=>{De(e,t,J.Consent)&&Te(e,t,J.Consent)&&(Object.keys(o).filter(e=>e in t).forEach(n=>{(0,H.tryCatch)(t[n],t=>Ie(e,"consent",t,{key:n}))(o,r)}),Ae(e,t,J.Consent))})}(e,n,o);break;case J.Ready:!function(e,t){if(!e.allowed)return;const n=Pe(e,J.Ready);t.forEach(t=>{(0,H.tryCatch)(t,t=>Ie(e,"ready",t))(void 0,n)})}(e,n);break;case J.Run:!function(e,t){if(!e.allowed)return;const n=Pe(e,J.Run);t.forEach(t=>{(0,H.tryCatch)(t,t=>Ie(e,"run",t))(void 0,n)})}(e,n);break;case J.Session:!function(e,t){if(!e.session)return;const n=Pe(e,J.Session);t.forEach(t=>{(0,H.tryCatch)(t,t=>Ie(e,"session",t))(e.session,n)})}(e,n);break;default:{const o=Pe(e,t),s=Oe(t);n.forEach(n=>{"function"==typeof n&&(s&&!De(e,n,t)||s&&!Te(e,n,t)||((0,H.tryCatch)(n,n=>Ie(e,"generic",n,{type:t}))(r,o),s&&Ae(e,n,t)))});break}}}function $e(e,t,n){switch(t){case J.Consent:return n||e.consent;case J.Session:return e.session;case J.User:return n||e.user;case J.Custom:return n||e.custom;case J.Globals:return n||e.globals;case J.Config:return n||e.config;default:return}}async function _e(e,t,n,o,r){if(!t.on)return!1;if(Oe(o)&&!De(e,t,o))return!1;if(Oe(o)&&!Te(e,t,o))return!1;const s=await(0,H.tryCatchAsync)(t.on,t=>Ie(e,"source",t,{sourceId:n,type:o}))(o,r);return Oe(o)&&Ae(e,t,o),!1===s}function He(e){return"number"==typeof e&&e>0?e:1e4}var Ne=class extends Error{constructor(e){super(e),this.name="DestinationTimeoutError"}};function Re(e,t,n){let o;const r=new Promise((e,r)=>{o=setTimeout(()=>r(new Ne(n)),t)});return Promise.race([e,r]).finally(()=>{o&&clearTimeout(o)})}var Ge=Object.freeze({batched:!0});function Be(e){return e===Ge}function Fe(e){return void 0===e?{}:"number"==typeof e?{wait:e}:{wait:e.wait,size:e.size,age:e.age}}function Ue(e,t,n){if(!e)return[];if(Array.isArray(e)&&e.every(e=>"string"==typeof e))return de(e,t);if("string"==typeof e)return de(e,t);const o=(0,$.getNextSteps)(e,(0,$.buildCacheContext)(n));return 0===o.length?[]:1===o.length?de(o[0],t):de(o,t)}async function Le(e,t,n={},o){const{allowed:r,consent:s,globals:i,user:a}=e;if(!r)return Je({ok:!1});if(t){const n=e.config.queueMax;if(void 0===n)throw new Error("Collector.Config.queueMax is undefined; defaults must be seeded by collector()");const o=V(e.queue,t,{max:n});if(o.dropped>0){const t=re(e.status,(0,$.stepId)("collector"),"queue",o.dropped);X(e.queue,e.logger,"collector.queue overflow; oldest events dropped",{buffer:"queue",cap:n,droppedCount:t})}else e.queue.length<n&&Z(e.queue);e.status.in++}o||(o=e.destinations);const c=e.transformers?ce(e.transformers):{},u=await Promise.all(Object.entries(o||{}).map(async([o,r])=>{if(r.config.disabled)return{id:o,destination:r,skipped:!0};const u=r.config.id||o,d=(0,$.stepId)("destination",u),l=te(r.config.breaker);if(l&&function(e,t,n){const o=e[t];if(!o||"closed"===o.state)return!1;if("half-open"===o.state)return!0===o.probing;const r=ee();return void 0!==o.openUntil&&r<o.openUntil||(o.state="half-open",o.probing=!0,o.openUntil=r+n,!1)}(e.status.breakers,d,l.cooldown))return{id:o,destination:r,skipped:!0};const p=t=>{l&&ne(e.status.breakers,d,t,l.threshold,l.cooldown)},f=()=>{l&&function(e,t){const n=e[t];n&&"half-open"===n.state&&!0===n.probing&&(n.state="open",n.probing=!1)}(e.status.breakers,d)};let g=(r.queuePush||[]).map(e=>({...e,consent:s}));r.queuePush=[],t&&g.push((0,$.clone)(t));const h=n.ingest?{...n.ingest,_meta:{...n.ingest._meta,path:[...n.ingest._meta.path]}}:(0,$.createIngest)("unknown");if(!g.length&&!r.queueOn?.length)return f(),{id:o,destination:r,skipped:!0};if(!g.length&&r.queueOn?.length){if(!(0,$.getGrantedConsent)(r.config.consent,s))return f(),{id:o,destination:r,skipped:!0};let t=!1;try{t=await Ke(e,r,o,!0)}catch(t){e.status.failed++;const n=r.type||"unknown";e.logger.scope(n).error("destination init failed",{error:t instanceof Error?t.message:String(t)}),p("transport-failure")}return f(),{id:o,destination:r,skipped:!t}}const m=[],y=g.filter(t=>{const n=(0,$.getGrantedConsent)(r.config.consent,s,t.consent);if(n)return t.consent=n,m.push(t),!1;const i=W(e,{stepId:(0,$.stepId)("destination",o),stepType:"destination",phase:"skip",eventId:"string"==typeof t.id?t.id:"",now:Date.now()});return i.skipReason="consent",s&&(i.consent={...s}),r.config.consent&&(i.meta={required:{...r.config.consent}}),(0,$.emitStep)(e,i),!0});if(y.length>0){const t=r.queuePush,n=r.config.id||o,s={max:r.config.queueMax??1e3};let i=0;for(const e of y)i+=V(t,e,s).dropped;if(i>0){oe(e,n);const o=re(e.status,(0,$.stepId)("destination",n),"queue",i);X(t,e.logger.scope(r.type||"unknown"),"destination.queuePush overflow; oldest events dropped",{buffer:"queuePush",destination:n,cap:s.max,droppedCount:o})}else t.length<s.max&&Z(t)}if(!m.length)return f(),{id:o,destination:r,queue:g};let v,w,b=!1;try{b=await Ke(e,r,o,!0)}catch(t){e.status.failed++;const n=r.type||"unknown";e.logger.scope(n).error("destination init failed",{error:t instanceof Error?t.message:String(t)}),p("transport-failure")}if(!b)return f(),{id:o,destination:r,queue:g};r.dlq||(r.dlq=[]);const k=Ue(r.config.before,c,h),S=r.config.next,q=r.config?.cache,I=q?(0,$.compileCache)(q):void 0,C=I?ie(I,e):void 0,O=r.config?.state?(0,$.compileState)(r.config.state):void 0,x=O?.filter(e=>"get"===e.mode),j=O?.filter(e=>"set"===e.mode);let E=0,A=0;return await Promise.all(m.map(async t=>{let s;if(t.globals=(0,$.assign)(i,t.globals),t.user=(0,$.assign)(a,t.user),I?.stop&&C){const e=(0,$.buildCacheContext)(h,t),n=await(0,$.checkCache)(I,C,e);if("HIT"===n?.status)return t;"MISS"===n?.status&&(s={key:n.key,ttl:n.rule.ttl})}let u=t,d=n.respond;if(k.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const r=await ge(e,e.transformers,k,t,h,n.respond,`destination.${o}.before`);if(null===r.event)return t;r.respond&&(d=r.respond),u=Array.isArray(r.event)?r.event[0]:r.event}if(I&&!I.stop&&C){const e=(0,$.buildCacheContext)(h,u),n=await(0,$.checkCache)(I,C,e);if("HIT"===n?.status)return t;"MISS"===n?.status&&(s={key:n.key,ttl:n.rule.ttl})}x&&x.length>0&&u&&(u=await(0,$.applyState)(x,t=>ae(t,e),u,e));const l=Date.now();let p=!1;const f=await(0,$.tryCatchAsync)(Qe,t=>{const n=r.type||"unknown";e.logger.scope(n).error("Push failed",{error:t,event:u.name}),v=t,p=!0;const s=r.dlq,i=r.config.id||o,a={max:r.config.dlqMax??100},c=V(s,[u,t],a);if(c.dropped>0){oe(e,i);const t=re(e.status,(0,$.stepId)("destination",i),"dlq",c.dropped);X(s,e.logger.scope(r.type||"unknown"),"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:i,cap:a.max,droppedCount:t})}else s.length<a.max&&Z(s)})(e,r,o,u,h,d);if(E+=Date.now()-l,s&&C&&void 0===r.config.mock&&(0,$.storeCache)(C,s.key,f??!0,s.ttl),!p&&!Be(f)&&j&&j.length>0&&u&&(u=await(0,$.applyState)(j,t=>ae(t,e),u,e)),void 0===f||Be(f)||(w=f),Be(f)&&A++,!p&&S){void 0!==f&&(h._response=f);const t=Ue(S,c,h);if(t.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const n=await ge(e,e.transformers,t,u,h,d,`destination.${o}.next`);n.respond&&(d=n.respond)}}return t})),{id:o,destination:r,error:v,response:w,totalDuration:E,batchedCount:A,allowedCount:m.length,canonicalId:u,breakerConfig:l}})),d={},l={},p={};for(const t of u){if(t.skipped)continue;const n=t.destination,o={type:n.type||"unknown",data:t.response};oe(e,t.id);const r=e.status.destinations[t.id],s=Date.now();r.queuePushSize=n.queuePush?.length??0,r.dlqSize=n.dlq?.length??0;const i=t.breakerConfig,a=t.canonicalId?(0,$.stepId)("destination",t.canonicalId):void 0,c=t=>{i&&a&&ne(e.status.breakers,a,t,i.threshold,i.cooldown)};if(t.error)o.error=t.error,p[t.id]=o,r.failed++,r.lastAt=s,r.duration+=t.totalDuration||0,e.status.failed++,c("transport-failure");else if(t.queue&&t.queue.length)l[t.id]=o;else{const n=t.batchedCount??0,i=t.allowedCount??0;(Math.max(0,i-n)>0||0===i)&&(d[t.id]=o,r.count++,r.lastAt=s,r.duration+=t.totalDuration||0,e.status.out++,c("success"))}}return Je({event:t,...Object.keys(d).length&&{done:d},...Object.keys(l).length&&{queued:l},...Object.keys(p).length&&{failed:p}})}async function Ke(e,t,n,o=!1){if(t.init&&!t.config.init){if(!o&&function(e){const t=e.config.consent;return!!t&&Object.keys(t).length>0}(t))return e.logger.scope(t.type||"unknown").debug("init blocked: consent gate not cleared"),!1;const r=t.type||"unknown",s=e.logger.scope(r),i={collector:e,logger:s,id:n,config:t.config,env:Ve(t.env,t.config.env),reportError:se(e,"destination",n,s,t)};s.debug("init");const a=Date.now();let c;(0,$.emitStep)(e,W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"init",eventId:"",now:a}));try{c=await(0,$.useHooks)(t.init,"DestinationInit",e.hooks,e.logger)(i)}catch(t){const o=Date.now(),r=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"error",eventId:"",now:o});throw r.durationMs=o-a,r.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},(0,$.emitStep)(e,r),t}if(!1===c)return c;if(t.config={...c||t.config,init:!0},t.queueOn?.length){const o=t.queueOn;t.queueOn=[];for(const{type:r,data:s}of o)Me(e,t,n,r,s)}s.debug("init done")}return!0}async function Qe(e,t,n,o,r,s){const{config:i}=t,a=await(0,$.processEventMapping)(o,i,e);if(a.ignore)return!1;const c=t.type||"unknown",u=e.logger.scope(c),d={collector:e,logger:u,id:n,config:i,data:a.data,rule:a.mapping,ingest:r,env:{...Ve(t.env,i.env),...s?{respond:s}:{}},reportError:se(e,"destination",n,u,t)};if(void 0!==i.mock)return u.debug("mock",{event:a.event.name}),i.mock;const l=a.mapping,p=void 0!==l?.batch,f=p?a.mappingKey||"* *":" batch-all";if((p||void 0!==i.batch)&&t.pushBatch&&void 0===i.mock){if(t.batches=t.batches||{},!t.batches[f]){const o={key:f,entries:[],events:[],data:[]},r=Fe(l?.batch),s=Fe(i.batch),a=r.wait??s.wait??3e4,c=r.size??s.size??1e3,d=r.age??s.age??3e4,g=Ve(t.env,i.env),h=(0,$.debounce)(async()=>{const o=t.batches[f],r=o.batched;if(0===r.entries.length)return;const s={key:r.key,entries:r.entries,events:r.events,data:r.data};r.entries=[],r.events=[],r.data=[];const a=s.entries[0],c={collector:e,logger:u,id:n,config:i,data:void 0,rule:o.isDefault?void 0:a.rule,ingest:a.ingest,env:{...g,...a.respond?{respond:a.respond}:{}},reportError:se(e,"destination",n,u,t)};u.debug("push batch",{events:s.entries.length});const d=t.config.id||n,l=oe(e,d),p=te(t.config.breaker),h=(0,$.stepId)("destination",d),m=t=>{p&&ne(e.status.breakers,h,t,p.threshold,p.cooldown)},y=Date.now(),v=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"flush",eventId:"",now:y});v.batch={size:s.entries.length,index:0},(0,$.emitStep)(e,v);const w=n=>{const o=t.dlq=t.dlq||[],r={max:t.config.dlqMax??100};let s=0;for(const e of n)s+=V(o,e,r).dropped;if(s>0){const t=re(e.status,(0,$.stepId)("destination",d),"dlq",s);X(o,u,"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:d,cap:r.max,droppedCount:t})}else o.length<r.max&&Z(o);l.failed+=n.length,l.dlqSize=o.length,e.status.failed+=n.length};let b=s.entries.length;const k=He(i.timeout),S=await(0,$.tryCatchAsync)((o,r)=>Re(Promise.resolve((0,$.useHooks)(t.pushBatch,"DestinationPushBatch",e.hooks,e.logger)(o,r)),k,`Destination "${n}" batch delivery timed out after ${k}ms`),t=>{b=0;const o=Date.now(),r=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"error",eventId:"",now:o});r.durationMs=o-y,r.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},r.batch={size:s.entries.length,index:0},(0,$.emitStep)(e,r),w(s.entries.map(e=>[e.event,t])),m("transport-failure"),u.error("Push batch failed",{error:t instanceof Error?t.message:String(t),entries:s.entries.length})})(s,c);if((0,$.isObject)(q=S)&&Array.isArray(q.failed)&&S.failed.length>0){const e=[],t=new Set;for(const n of S.failed){const o=s.entries[n.index];o&&!t.has(n.index)&&(t.add(n.index),e.push([o.event,n.error??new Error(`Push batch entry ${n.index} failed (no per-row error provided)`)]))}e.length>0&&(w(e),b=Math.max(0,s.entries.length-e.length),u.error("Push batch partial failure",{failed:e.length,delivered:b,entries:s.entries.length}))}var q;u.debug("push batch done"),l.inFlightBatch=Math.max(0,(l.inFlightBatch??0)-s.entries.length),b>0&&(l.count+=b,l.lastAt=Date.now(),e.status.out+=b,m("success"))},{wait:a,size:c,age:d});t.batches[f]={batched:o,isDefault:!p,batchFn:()=>{h()},flush:async()=>{await h.flush()}}}const o=t.batches[f];o.batched.entries.push({event:a.event,ingest:r,respond:s,rule:l,data:a.data}),o.batched.events.push(a.event),(0,$.isDefined)(a.data)&&o.batched.data.push(a.data);const c=t.config.id||n,d=oe(e,c);return d.inFlightBatch=(d.inFlightBatch??0)+1,o.batchFn(),Ge}{u.debug("push",{event:a.event.name});const o="string"==typeof a.event.id?a.event.id:"",r=Date.now(),s=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"in",eventId:o,now:r});a.mappingKey&&(s.mappingKey=a.mappingKey),a.event.consent&&(s.consent={...a.event.consent}),s.inEvent=a.event,(0,$.emitStep)(e,s);try{const s=He(i.timeout),c=await Re(Promise.resolve((0,$.useHooks)(t.push,"DestinationPush",e.hooks,e.logger)(a.event,d)),s,`Destination "${n}" delivery timed out after ${s}ms`),l=Date.now(),p=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"out",eventId:o,now:l});return p.durationMs=l-r,p.outEvent=a.event,(0,$.isDefined)(c)&&(p.meta={...p.meta,response:c}),a.mappingKey&&(p.mappingKey=a.mappingKey),(0,$.emitStep)(e,p),u.debug("push done"),c}catch(t){const s=Date.now(),i=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"error",eventId:o,now:s});throw i.durationMs=s-r,i.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},a.mappingKey&&(i.mappingKey=a.mappingKey),(0,$.emitStep)(e,i),t}}}function Je(e){return{ok:!e?.failed,...e}}function We(e){const{code:t,config:n={},env:o={},cache:r,state:s}=e,{config:i}=ue(e,"before"),{config:a}=ue({...e,config:i},"next"),c={...t.config,...n,...a};r&&(c.cache=r),void 0!==s&&void 0===c.state&&(c.state=s);const u=Ve(t.env,o);return{...t,config:c,env:u}}function Ve(e,t){return e||t?t?e&&(0,$.isObject)(e)&&(0,$.isObject)(t)?{...e,...t}:t:e:{}}async function Ye(e,t,n){const o=Object.entries(e).map(async([e,o])=>{const r=o.destroy;if(!r)return;const s=o.type||"unknown",i=n.scope(s),a={id:e,config:o.config,env:o.env??{},logger:i};let c;try{await Promise.race([r(a),new Promise((n,o)=>{c=setTimeout(()=>o(new Error(`${t} '${e}' destroy timed out`)),5e3)})])}catch(n){i.error(`${t} '${e}' destroy failed: ${n}`)}finally{c&&clearTimeout(c)}});await Promise.allSettled(o)}function Xe(e,t){e.stateVersion++,e.cellVersion[t]=e.stateVersion}async function Ze(e,t,n){let o,r,s=!1;const i=function(e){return e.cascade?()=>{}:(e.cascade={counts:new WeakMap},()=>{e.cascade=void 0})}(e);try{return await async function(){switch(t){case J.Config:(0,F.isObject)(n)&&((0,B.assign)(e.config,n,{shallow:!1}),r=n,s=!0);break;case J.Consent:if((0,F.isObject)(n)){const{update:t}=function(e,t){const n={};return Object.entries(t).forEach(([e,t])=>{n[e]=!!t}),e.consent=(0,M.assign)(e.consent,n),{update:n}}(e,n);Xe(e,J.Consent),r=t,s=!0}break;case J.Custom:(0,F.isObject)(n)&&(e.custom=(0,B.assign)(e.custom,n),Xe(e,J.Custom),r=n,s=!0);break;case J.Destination:(0,F.isObject)(n)&&"code"in n&&(0,F.isObject)(n.code)&&(o=await async function(e,t){const{code:n,config:o={},env:r={},before:s,next:i,cache:a,state:c}=t;if(!(0,$.isFunction)(n.push))return Je({ok:!1,failed:{invalid:{type:"invalid",error:"Destination code must have a push method"}}});const u=o||{init:!1};let d=s?{...u,before:s}:{...u};i&&(d={...d,next:i}),a&&(d={...d,cache:a}),void 0!==c&&void 0===d.state&&(d={...d,state:c});let l=d.id;if(!l)do{l=(0,$.getId)(5,"abcdefghijklmnopqrstuvwxyz")}while(e.destinations[l]||e.pending.destinations[l]);if(d.require?.length){e.pending.destinations[l]=t,await be(e);const n=e.destinations[l];return n?Le(e,void 0,{},{[l]:n}):Je({ok:!0})}const p={...n,config:d,env:Ve(n.env,r)};return e.destinations[l]=p,!1!==p.config.queue&&(p.queuePush=[...e.queue]),Le(e,void 0,{},{[l]:p})}(e,n));break;case J.Globals:(0,F.isObject)(n)&&(e.globals=(0,B.assign)(e.globals,n),Xe(e,J.Globals),r=n,s=!0);break;case J.Hook:if((0,F.isObject)(n)&&(0,B.isString)(n.name)&&(0,B.isFunction)(n.fn)){const{name:t,fn:o}=n;e.hooks[t]=o,r=n,s=!0}break;case J.On:if((0,F.isObject)(n)&&(0,B.isString)(n.type)){const{type:t,rules:o}=n;await async function(e,t,n){if(!ke(e))return void qe();const o=e.on,r=o[t]||[],s=(0,_.isArray)(n)?n:[n];s.forEach(e=>{r.push(e)}),o[t]=r,ze(e,t,s)}(e,t,o)}break;case J.Ready:s=!0;break;case J.Run:o=await async function(e,t){return e.allowed=!0,e.timing=Date.now(),e.trace=(0,B.getTraceId)(),e.count=0,t&&(t.consent&&(e.consent=(0,B.assign)(e.consent,t.consent),Xe(e,J.Consent)),t.user&&(e.user=(0,B.assign)(e.user,t.user),Xe(e,J.User)),t.globals&&(e.globals=(0,B.assign)(e.config.globalsStatic||{},t.globals),Xe(e,J.Globals)),t.custom&&(e.custom=(0,B.assign)(e.custom,t.custom),Xe(e,J.Custom))),Object.values(e.destinations).forEach(e=>{e.queuePush=[]}),e.queue=[],e.round++,await be(e),await async function(e){if(ke(e))for(const t of Ce){if(!xe(e,t))continue;const n=$e(e,t);ze(e,t,e.on[t]||[]);for(const[o,r]of Object.entries(e.sources))ve(r)&&await _e(e,r,o,t,n)}else qe()}(e),await Le(e)}(e,n),s=!0;break;case J.Session:s=!0;break;case J.Shutdown:e.hasShutdown||(e.hasShutdown=!0,await async function(e){const t=e.logger;await Ye(e.sources,"source",t),await async function(e,t){const n=Object.entries(e).flatMap(([e,n])=>{const o=n.batches;if(!o)return[];const r=t.scope(n.type||"destination");return Object.values(o).map(async t=>{let n;try{await Promise.race([t.flush(),new Promise((t,o)=>{n=setTimeout(()=>o(new Error(`destination '${e}' batch flush timed out`)),5e3)})])}catch(t){r.error(`destination '${e}' batch flush failed: ${t}`)}finally{n&&clearTimeout(n)}})});await Promise.allSettled(n)}(e.destinations,t),await Ye(e.destinations,"destination",t),await Ye(e.transformers,"transformer",t),await Ye(e.stores,"store",t)}(e));break;case J.User:(0,F.isObject)(n)&&((0,B.assign)(e.user,n,{shallow:!1}),Xe(e,J.User),r=n,s=!0)}return s&&(await async function(e,t,n,o){if(!ke(e))return qe(),!0;e.seenEvents.add(String(t));let r=n||[];n||(r=e.on[t]||[]);const s=$e(e,t,o);let i=!1;for(const[n,o]of Object.entries(e.sources)){if(o.config.require?.length){const e=o.config.require.indexOf(t);-1!==e&&o.config.require.splice(e,1)}o.on&&(ve(o)?await _e(e,o,n,t,s)&&(i=!0):(o.queueOn=o.queueOn||[],o.queueOn.push({type:t,data:s})))}Object.entries(e.destinations).forEach(([n,o])=>{if(o.on){if(!o.config.init)return o.queueOn=o.queueOn||[],void o.queueOn.push({type:t,data:s});Me(e,o,n,t,s)}});for(const[t,n]of Object.entries(e.sources))ve(n)&&n.queueOn?.length&&await ye(e,n,t);const a=Object.values(e.sources).some(e=>!ve(e)&&e.config.require?.length);return(Object.keys(e.pending.destinations).length>0||a)&&await be(e),ze(e,t,r,o),!i}(e,t,void 0,r),o=await Le(e)),o||Je({ok:!0})}()}finally{i()}}function et(e,t){return{timing:Math.round((Date.now()-e.timing)/10)/100,source:{type:"collector",schema:"4",version:"4.2.1-next-1781715165983"},...t}}function tt(e,t){if(!t.name)throw new Error("Event name is required");const[n,o]=t.name.split(" ");if(!n||!o)throw new Error("Event name is invalid");const{timestamp:r=Date.now(),name:s=`${n} ${o}`,data:i={},context:a={},globals:c=e.globals,custom:u={},user:d=e.user,nested:l=[],consent:p=e.consent,id:f=(0,B.getSpanId)(),trigger:g="",entity:h=n,action:m=o,timing:y=0,source:v={type:"collector",schema:"4"}}=t,w=v.count??(e.count+=1),b=v.trace??e.trace,k={...v,count:w};return void 0!==b&&(k.trace=b),{name:s,data:i,context:a,globals:c,custom:u,user:d,nested:l,consent:p,id:f,trigger:g,entity:h,action:m,timestamp:r,timing:y,source:k}}function nt(e,t){const n=(0,U.useHooks)(async(n,o={})=>await(0,U.tryCatchAsync)(async()=>{const r=Date.now(),{id:s,ingest:i,respond:a,mapping:c,preChain:u,include:d,exclude:l}=o;let p=a,f=n;const g=d||l?function(e,t,n){let o=e;return t&&(o=Object.fromEntries(Object.entries(o).filter(([e])=>t.includes(e)))),n&&(o=Object.fromEntries(Object.entries(o).filter(([e])=>!n.includes(e)))),o}(e.destinations,d,l):void 0,h=i??(0,U.createIngest)(s||"unknown");if(c){const t=await(0,U.processEventMapping)(f,c,e);if(t.ignore)return Je({ok:!0});if(c.consent&&!(0,U.getGrantedConsent)(c.consent,e.consent,t.event.consent))return Je({ok:!0});f=t.event}if(u?.length&&e.transformers&&Object.keys(e.transformers).length>0){const n=await ge(e,e.transformers,u,f,h,p,s?`source.${s}.next`:void 0);if(null===n.event)return Je({ok:!0});if(n.stopped)return n.respond&&(p=n.respond),Je({ok:!0});if(n.respond&&(p=n.respond),Array.isArray(n.event)){const o=await Promise.all(n.event.map(async n=>{const o=t(n),r=tt(e,o);return Le(e,r,{id:s,ingest:h,respond:p},g)}));if(s){e.status.sources[s]||(e.status.sources[s]={count:0,duration:0});const t=e.status.sources[s];t.count+=n.event.length,t.lastAt=Date.now(),t.duration+=Date.now()-r}return o[0]??Je({ok:!0})}f=n.event}const m=function(e,t){return tt(e,et(e,t))}(e,f),y=await Le(e,m,{id:s,ingest:h,respond:p},g);if(s){e.status.sources[s]||(e.status.sources[s]={count:0,duration:0});const t=e.status.sources[s];t.count++,t.lastAt=Date.now(),t.duration+=Date.now()-r}return y},t=>{if(t instanceof U.FatalError)throw t;return e.status.failed++,e.logger.error("push failed",{event:n,ingest:o.ingest,error:t}),Je({ok:!1})})(),"Push",e.hooks,e.logger);return async(t,o)=>{const r="string"==typeof t.id?t.id:"",s=Date.now(),i=W(e,{stepId:"collector.push",stepType:"collector",phase:"in",eventId:r,now:s});i.inEvent=t,(0,U.emitStep)(e,i);try{const i=await n(t,o),a=Date.now(),c=W(e,{stepId:"collector.push",stepType:"collector",phase:"out",eventId:r,now:a});return c.durationMs=a-s,c.outEvent=i,(0,U.emitStep)(e,c),i}catch(t){const n=Date.now(),o=W(e,{stepId:"collector.push",stepType:"collector",phase:"error",eventId:r,now:n});throw o.durationMs=n-s,o.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},(0,U.emitStep)(e,o),t}}}function ot(e={}){const t=e.maxEntries??1e4,n=e.lowWaterMark??.8,o=e.sweepIntervalMs??6e4,r=Math.floor(t*n),s=new Map,i={hits:0,misses:0,populates:0,writes:0,deletes:0,evictions_entries:0,evictions_ttl:0};let a;return o>0&&(a=setInterval(function(){const e=Date.now();let t=0;for(const[n,o]of s)void 0!==o.expires&&o.expires<=e&&(s.delete(n),t++);i.evictions_ttl+=t},o),a&&"function"==typeof a.unref&&a.unref()),{type:"memory",config:{},get(e){const t=s.get(e);if(t)return void 0!==t.expires&&t.expires<=Date.now()?(s.delete(e),i.evictions_ttl++,void i.misses++):(s.delete(e),s.set(e,t),i.hits++,t.value);i.misses++},set(e,n,o){const a=!s.has(e);a||s.delete(e),s.set(e,{value:n,expires:void 0!==o?Date.now()+o:void 0}),i.writes++,a&&i.populates++,s.size>t&&function(){if(s.size<=t)return;const e=s.size-r;let n=0;for(const t of s.keys()){if(n>=e)break;s.delete(t),n++}i.evictions_entries+=n}()},delete(e){s.delete(e)&&i.deletes++},get counters(){return{...i}},destroy(){void 0!==a&&(clearInterval(a),a=void 0),s.clear()}}}function rt(e,t){const{cacheConfig:n,cacheStore:o,namespace:r,logger:s,storeId:i,collector:a}=t,c=(e,t)=>{if(!a)return;const n=W(a,{stepId:`store.${i}`,stepType:"store",phase:"in",eventId:"",now:Date.now()});n.meta={op:"cache",cached:"hit"===t,status:t,key:e},(0,Q.emitStep)(a,n)},u={hits:0,misses:0,populates:0,writes:0,deletes:0,inflight_dedups:0},d=n.rules.map(e=>({match:e.match?(0,Q.compileMatcher)(e.match):()=>!0,ttl:e.ttl})),l=e=>`${r}:${e}`;function p(e,t){const n=void 0===t?{key:e}:{key:e,value:t};return d.find(e=>e.match(n))}const f=new Map;return{type:e.type,config:e.config,setup:e.setup,get counters(){return{...u}},async get(t){const n=l(t),r=await o.get(n),s=(0,Q.readCacheEnvelope)(r);if(void 0!==s){if(!("expired"in s))return u.hits++,c(t,"hit"),s.value;try{await o.delete(n)}catch(e){g("delete",t,e)}}const i=f.get(n);if(i)return u.inflight_dedups++,c(t,"hit"),i;u.misses++,c(t,"miss");const a=(async()=>{try{const r=await e.get(t);if(void 0===r)return;const s=p(t,r);if(s)try{const e=1e3*s.ttl;await o.set(n,(0,Q.wrapCacheEnvelope)(r,e),e),u.populates++}catch(e){g("set",t,e)}return r}finally{f.delete(n)}})();return f.set(n,a),a},async set(t,n,r){u.writes++,await e.set(t,n,r);const s=p(t,n);if(s)try{const e=1e3*s.ttl;await o.set(l(t),(0,Q.wrapCacheEnvelope)(n,e),e)}catch(e){g("set",t,e)}},async delete(t){u.deletes++,await e.delete(t);try{await o.delete(l(t))}catch(e){g("delete",t,e)}}};function g(e,t,n){const o=`store-cache(${i}): cache ${e} failed for "${t}"; backing succeeded, continuing`;s?s.warn(o,{error:n}):console.warn(o,n)}}function st(e,t,n){const o=`store.${n}`,r=(0,K.useHooks)(t.get,"StoreGet",e.hooks,e.logger),s=(0,K.useHooks)(t.set,"StoreSet",e.hooks,e.logger),i=(0,K.useHooks)(t.delete,"StoreDelete",e.hooks,e.logger);t.get=async t=>{const n=Date.now(),s=W(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:n});s.meta={op:"get",key:t},(0,K.emitStep)(e,s);try{const s=await r(t),i=Date.now(),a=W(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:i});return a.durationMs=i-n,a.meta={op:"get",key:t},(0,K.emitStep)(e,a),s}catch(r){const s=Date.now(),i=W(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:s});throw i.durationMs=s-n,i.meta={op:"get",key:t},i.error=r instanceof Error?{name:r.name,message:r.message}:{message:String(r)},(0,K.emitStep)(e,i),r}},t.set=async(t,n,r)=>{const i=Date.now(),a=W(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:i});a.meta={op:"set",key:t},(0,K.emitStep)(e,a);try{await s(t,n,r);const a=Date.now(),c=W(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:a});c.durationMs=a-i,c.meta={op:"set",key:t},(0,K.emitStep)(e,c)}catch(n){const r=Date.now(),s=W(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:r});throw s.durationMs=r-i,s.meta={op:"set",key:t},s.error=n instanceof Error?{name:n.name,message:n.message}:{message:String(n)},(0,K.emitStep)(e,s),n}},t.delete=async t=>{const n=Date.now(),r=W(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:n});r.meta={op:"delete",key:t},(0,K.emitStep)(e,r);try{await i(t);const r=Date.now(),s=W(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:r});s.durationMs=r-n,s.meta={op:"delete",key:t},(0,K.emitStep)(e,s)}catch(r){const s=Date.now(),i=W(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:s});throw i.durationMs=s-n,i.meta={op:"delete",key:t},i.error=r instanceof Error?{name:r.name,message:r.message}:{message:String(r)},(0,K.emitStep)(e,i),r}}}async function it(e){const t=(0,z.assign)({globalsStatic:{},sessionStatic:{},run:!0,queueMax:1e3},e,{merge:!1,extend:!1}),n={level:e.logger?.level,handler:e.logger?.handler},o=(0,z.createLogger)(n),r={...t.globalsStatic,...e.globals},s={allowed:!1,config:t,consent:e.consent||{},custom:e.custom||{},destinations:{},transformers:{},stores:{},globals:r,hooks:e.hooks||{},observers:new Set,logger:o,on:{},queue:[],round:0,count:0,stateVersion:0,cellVersion:{},delivery:new WeakMap,session:void 0,status:{startedAt:Date.now(),in:0,out:0,failed:0,sources:{},destinations:{},dropped:{},connectionErrors:{},breakers:{}},timing:Date.now(),user:e.user||{},sources:{},pending:{destinations:{}},hasShutdown:!1,seenEvents:new Set,push:void 0,command:void 0};var i,a;s.push=nt(s,e=>et(s,e)),s.command=(i=s,a=Ze,(0,L.useHooks)(async(e,t,n)=>await(0,L.tryCatchAsync)(async()=>await a(i,e,t,n),n=>{if(n instanceof L.FatalError)throw n;return i.status.failed++,i.logger.error("command failed",{command:e,data:t,error:n}),Je({ok:!1})})(),"Command",i.hooks,i.logger));const c=e.stores||{};return s.stores=await async function(e,t={}){const n={};for(const[o,r]of Object.entries(t)){const{code:t,config:s={},env:i={}}=r,a=e.logger.scope("store").scope(o),c={collector:e,logger:a,id:o,config:s,env:i,reportError:se(e,"store",o,a)},u=await t(c);n[o]=u}const o=t,r=function(e){const t={};for(const n of Object.keys(e))t[n]="WHITE";const n=[],o=[];function r(s){const i=t[s];if("BLACK"===i)return;if("GRAY"===i){const e=o.indexOf(s),t=o.slice(-1===e?0:e).concat(s).join(" -> ");throw new Error(`Cycle in cache.store chain: ${t}`)}t[s]="GRAY",o.push(s);const a=e[s].cache?.store;if(void 0!==a){if(!(a in e))throw new Error(`Store "${s}" cache.store references "${a}", which is not declared in flow.stores`);r(a)}o.pop(),t[s]="BLACK",n.push(s)}for(const n of Object.keys(e))"WHITE"===t[n]&&r(n);return n}(o);for(const t of r){const r=o[t].cache;if(!r)continue;let s,i;void 0!==r.store?(s=n[r.store],i=r.store):(n.__cache||(n.__cache=ot()),s=n.__cache,i="__cache");const a=r.namespace??t;e.logger.scope("store-cache").scope(t).info(`store "${t}" caches with namespace "${a}:" via ${i}`),n[t]=rt(n[t],{storeId:t,cacheConfig:r,cacheStore:s,namespace:a,logger:e.logger.scope("store-cache").scope(t),collector:e})}for(const[t,o]of Object.entries(n))"__cache"!==t&&st(e,o,t);return n}(s,c),function(e,t,n){const o=new Map;for(const[n,r]of Object.entries(e))t[n]&&o.set(r,t[n]);if(0!==o.size)for(const e of[n.transformers,n.destinations,n.sources])if(e)for(const t of Object.values(e))r(t.env);function r(e){if(e)for(const[t,n]of Object.entries(e))if("object"==typeof n&&null!==n){const r=o.get(n);r&&(e[t]=r)}}}(c,s.stores,e),s.stores.__cache||(s.stores.__cache=ot()),s.destinations=await async function(e,t={}){const n={};for(const[o,r]of Object.entries(t))r.config?.require?.length?e.pending.destinations[o]=r:n[o]=We(r);return n}(s,e.destinations||{}),s.transformers=await async function(e,t={}){const n={};for(const[o,r]of Object.entries(t)){const{code:t,env:s={}}=r,i=(0,G.validateStepEntry)(r,"Transformer");if(!i.ok){e.logger.warn(`Transformer ${o} invalid (${i.code}): ${i.reason}. Skipping.`);continue}const{config:a}=ue(r,"before"),{config:c}=ue({...r,config:a},"next"),u=Object.keys(s).length>0?{...c,env:s}:c,{cache:d}=r,l=d?{...u,cache:d}:u,p=r.config?.state??r.state,f=void 0!==p&&void 0===l.state?{...l,state:p}:l,g=e.logger.scope("transformer").scope(o),h={collector:e,logger:g,id:o,ingest:(0,G.createIngest)(o),config:f,env:s,reportError:se(e,"transformer",o,g)},m=t??(e=>{const t=r.mapping;if(t){const n=[];if(void 0!==t.data&&n.push("data"),t.mapping)for(const[e,o]of Object.entries(t.mapping))if("object"==typeof o&&null!==o)for(const[t,r]of Object.entries(o)){if("object"!=typeof r||null===r)continue;const o=r;void 0!==o.data&&n.push(`mapping[${e}][${t}].data`),void 0!==o.silent&&n.push(`mapping[${e}][${t}].silent`)}return n.length>0&&e.collector.logger.warn(`Transformer ${o}: \`${n.join(", ")}\` ignored at transformer position (only event-mutating fields apply).`),{type:"pass",config:e.config,push:async n=>{const o=await(0,G.processEventMapping)(n,t,e.collector);return!o.ignore&&{event:o.event}}}}return{type:"pass",config:e.config,push:e=>({event:e})}}),y=await m(h);void 0!==r.before&&void 0===y.config?.before&&(y.config={...y.config??{},before:r.before}),void 0!==r.next&&void 0===y.config?.next&&(y.config={...y.config??{},next:r.next}),void 0!==p&&void 0===y.config?.state&&(y.config={...y.config??{},state:p}),n[o]=y}return n}(s,e.transformers||{}),s}async function at(e){e=e||{};const t=await it(e),n=(o=t,{type:"elb",config:{},push:async(e,t,n,r,s)=>{if("string"==typeof e&&e.startsWith("walker ")){const n=e.replace("walker ","");return o.command(n,t)}let i;if("string"==typeof e)i={name:e},t&&"object"==typeof t&&!Array.isArray(t)&&(i.data=t);else{if(!e||"object"!=typeof e)return Je({ok:!1});i=e,t&&"object"==typeof t&&!Array.isArray(t)&&(i.data={...i.data||{},...t})}return n&&"object"==typeof n&&(i.context=n),r&&Array.isArray(r)&&(i.nested=r),s&&"object"==typeof s&&(i.custom=s),o.push(i)}});var o;t.sources.elb=n,await async function(e,t={}){const n={};for(const[o,r]of Object.entries(t)){const t=await we(e,o,r);if(!t)continue;const s=r.config?.require;t.config={...t.config,init:!1,...s?{require:[...s]}:{}},n[o]=t}Object.assign(e.sources,n);for(const t of Object.keys(n)){const n=e.sources[t];let o=!1;n.init&&await(0,R.tryCatchAsync)(n.init.bind(n),n=>{if(n instanceof R.FatalError)throw n;o=!0,e.status.failed++,e.logger.scope("source").error("source init failed",{sourceId:t,error:n})})(),o||(n.config.init=!0,ve(n)&&await ye(e,n,t))}return await be(e),n}(t,e.sources||{});const{consent:r,user:s,globals:i,custom:a}=e;r&&await t.command("consent",r),s&&await t.command("user",s),i&&await t.command("globals",i),a&&await t.command("custom",a),t.config.run&&await t.command("run");let c=n.push;const u=Object.values(t.sources).filter(e=>"elb"!==e.type),d=u.find(e=>e.config.primary);return d?c=d.push:u.length>0&&(c=u[0].push),{collector:t,elb:c}}var ct=async e=>{let t;return{get flow(){return t},trigger:()=>async n=>{if(!t){const n=await at(e);t={collector:n.collector,elb:n.elb}}const o=function(e){for(const t of Object.values(e.sources||{}))if("lambda"===t.type)return t}(t.collector);if(!o)throw new Error("Lambda source not found in collector");const r={awsRequestId:`test-${Date.now()}`},s=o.push,i=await s(n,r);let a;try{a=JSON.parse(i.body||"{}")}catch{a=i.body}const c={};if(i.headers)for(const[e,t]of Object.entries(i.headers))void 0!==t&&(c[e]=String(t));return{statusCode:i.statusCode,body:a,headers:c}}}};function ut(e){return async t=>{const n={...t};if(n.body&&"string"==typeof n.body){const e=JSON.parse(n.body);e.name&&!e.event&&(n.body=JSON.stringify({...e,event:e.name,name:void 0}))}return e.push(n,{awsRequestId:"test-req"})}}var dt={};s(dt,{createTrigger:()=>qt,env:()=>lt,step:()=>yt});var lt={};s(lt,{push:()=>ht,simulation:()=>mt});var pt=()=>{},ft={error:pt,warn:pt,info:pt,debug:pt,throw:e=>{throw"string"==typeof e?new Error(e):e},json:pt,scope:()=>ft},gt=()=>()=>Promise.resolve({ok:!0}),ht={get push(){return gt()},get command(){return gt()},get elb(){return gt()},logger:ft},mt=["AWS.SQSClient"],yt={};s(yt,{decoderText:()=>bt,malformedJson:()=>kt,orderComplete:()=>wt,pageView:()=>vt});var vt={title:"Page view from SQS",description:"A standard SQS message body containing a walker elb event payload as JSON.",in:{MessageId:"m-1",Body:JSON.stringify({event:"page view",data:{title:"Documentation",url:"https://example.com/docs"}})},out:[["message.ack","m-1"]]},wt={title:"Order complete from SQS",description:"Order complete event flowing through the long-poll loop.",in:{MessageId:"m-2",Body:JSON.stringify({event:"order complete",data:{id:"ORD-500",total:199.99,currency:"EUR"}})},out:[["message.ack","m-2"]]},bt={title:"Text decoder",description:'When decoder is "text", the body string flows under data.payload.',in:{MessageId:"m-3",Body:"raw text payload"},out:[["message.ack","m-3"]]},kt={title:"Malformed JSON nacks",description:"Default decoder is JSON. A malformed body throws DecoderError; the source nacks (skips DeleteMessage) so the message redelivers.",in:{MessageId:"m-4",Body:"{not json"},out:[["message.nack","m-4"]]};function St(e){if("object"!=typeof e||null===e)return!1;const t=e;return"sqs"===t.type&&"function"==typeof t.push}var qt=async e=>{let t;return{get flow(){return t},trigger:()=>async n=>{if(!t){const n=await at(e);t={collector:n.collector,elb:n.elb}}const o=function(e){for(const t of Object.values(e.sources??{}))if(St(t))return t}(t.collector);if(!o)throw new Error("sqs source not registered in collector, ensure it is configured in sources");const r={MessageId:n.MessageId,Body:n.Body,ReceiptHandle:n.ReceiptHandle,Attributes:n.Attributes,MessageAttributes:n.MessageAttributes},s=await o.push(r),i=[];return s&&"object"==typeof s&&(s.acked&&i.push(["message.ack",n.MessageId]),s.nacked&&i.push(["message.nack",n.MessageId])),i}}};//# sourceMappingURL=dev.js.map
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,s=(e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})},i={};s(i,{examples:()=>I,schemas:()=>a,sqsExamples:()=>dt}),module.exports=(e=i,((e,s,i,a)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let c of o(s))r.call(e,c)||c===i||t(e,c,{get:()=>s[c],enumerable:!(a=n(s,c))||a.enumerable});return e})(t({},"__esModule",{value:!0}),e));var a={};s(a,{CorsOptionsSchema:()=>f,CorsOrigin:()=>p,HttpMethod:()=>l,SettingsSchema:()=>g,settings:()=>h,sqsSettings:()=>S,sqsSetup:()=>q});var c=require("@walkeros/core/dev"),u=require("@walkeros/core/dev"),d=require("@walkeros/core/dev"),l=d.z.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),p=d.z.union([d.z.string(),d.z.array(d.z.string()),d.z.literal("*")]),f=d.z.object({origin:p.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:d.z.array(l).describe("Allowed HTTP methods").optional(),headers:d.z.array(d.z.string()).describe("Allowed request headers").optional(),credentials:d.z.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:d.z.number().int().positive().describe("Preflight cache duration in seconds").optional()}),g=u.z.object({cors:u.z.union([u.z.boolean(),f]).describe("CORS configuration: false = disabled, true = allow all origins, object = custom configuration").default(!0),timeout:u.z.number().int().positive().max(9e5).describe("Request timeout in milliseconds (max: 900000 for Lambda)").default(3e4),enablePixelTracking:u.z.boolean().describe("Enable GET requests with 1x1 transparent GIF response for pixel tracking").default(!0),healthPath:u.z.string().describe("Health check endpoint path (e.g., /health)").default("/health")}),h=(0,c.zodToSchema)(g),m=require("@walkeros/core/dev"),y=require("@walkeros/core/dev"),v=y.z.object({queueName:y.z.string().min(1).describe("SQS queue short name (like walkeros-events). Required for both setup and runtime poll."),region:y.z.string().describe("AWS region (like eu-central-1). Default: eu-central-1.").optional(),queueUrl:y.z.string().url().describe("Optional pre-resolved queue URL. When set, init skips the GetQueueUrl lookup.").optional(),client:y.z.any().describe("Pre-configured AWS SQSClient instance. Bypasses construction when supplied.").optional(),config:y.z.any().describe("AWS SDK SQSClientConfig (credentials, endpoint overrides, retries).").optional(),decoder:y.z.enum(["json","text","raw"]).describe("Decoder for the message body. json (default) parses JSON, text forwards UTF-8, raw forwards a Buffer.").optional(),maxMessages:y.z.number().int().min(1).max(10).describe("SQS receive batch size. Cap 10. Default: 10.").optional(),waitTimeSeconds:y.z.number().int().min(0).max(20).describe("Long-poll duration in seconds. Cap 20. Default: 20.").optional(),visibilityTimeout:y.z.number().int().nonnegative().describe("Per-receive visibility timeout override. Default: queue-configured value.").optional(),shutdownTimeoutMs:y.z.number().int().positive().describe("Graceful shutdown timeout in milliseconds. Default: 30000. After this window, destroy() force-closes.").optional(),onPushError:y.z.enum(["nack","ack"]).describe("Behavior when forwarding to the collector throws. nack (default) skips DeleteMessage so the message redelivers; ack drops it.").optional()}),w=require("@walkeros/core/dev"),b=w.z.record(w.z.string(),w.z.string()),k=w.z.object({region:w.z.string().min(1).describe("AWS region.").optional(),fifoQueue:w.z.boolean().describe("FIFO queue with content-based deduplication. Auto-appends .fifo suffix to the queue name.").optional(),visibilityTimeoutSeconds:w.z.number().int().nonnegative().describe("Visibility timeout in seconds. Default: 30.").optional(),messageRetentionSeconds:w.z.number().int().positive().describe("Message retention period in seconds. Default: 345600 (4 days).").optional(),maximumMessageSize:w.z.number().int().min(1024).max(262144).describe("Max message size in bytes. Default: 262144 (256 KB).").optional(),kmsMasterKeyId:w.z.string().describe("KMS key alias or ID for at-rest encryption.").optional(),deadLetterQueue:w.z.object({arn:w.z.string().describe("ARN of an existing DLQ. Mutually exclusive with create: true.").optional(),create:w.z.boolean().describe("Create a sibling DLQ named <queueName>-dlq. Default: false.").optional(),maxReceiveCount:w.z.number().int().min(1).max(1e3).describe("Max receive count before message goes to DLQ. Default: 5.").optional()}).describe("Optional dead-letter queue.").optional(),tags:b.describe("Tags applied to the queue (and inherited by an auto-created DLQ).").optional(),subscribeToSnsTopic:w.z.object({topicArn:w.z.string().min(1).describe("Topic ARN to subscribe to."),rawMessageDelivery:w.z.boolean().describe("Deliver SNS messages without the SNS envelope.").optional(),filterPolicy:w.z.record(w.z.string(),w.z.unknown()).describe("SNS filter policy applied at subscription level.").optional()}).describe("Optional SNS topic subscription. Creates the subscription and the matching queue policy.").optional()}),S=(0,m.zodToSchema)(v),q=(0,m.zodToSchema)(k),I={};s(I,{createTrigger:()=>ct,env:()=>C,step:()=>A,trigger:()=>ut});var C={};s(C,{push:()=>E});var O=()=>()=>Promise.resolve({ok:!0}),x=()=>{},j={error:x,warn:x,info:x,debug:x,throw:e=>{throw"string"==typeof e?new Error(e):e},json:x,scope:()=>j},E={get push(){return O()},get command(){return O()},get elb(){return O()},logger:j},A={};s(A,{apiGatewayV1Post:()=>T,lambdaGet:()=>P,lambdaPost:()=>D});var D={title:"Lambda POST",description:"An API Gateway v2 HTTP POST with a JSON body is converted into a walker elb event.",trigger:{type:"POST"},in:{version:"2.0",requestContext:{http:{method:"POST",path:"/collect"},requestId:"req-123"},body:JSON.stringify({event:"page view",data:{title:"Home"}}),isBase64Encoded:!1},out:[["elb",{name:"page view",data:{title:"Home"}}]]},T={title:"API Gateway v1 POST",description:"A REST API Gateway v1 POST request with a JSON body is converted into a walker elb event.",trigger:{type:"POST"},in:{httpMethod:"POST",path:"/collect",requestContext:{requestId:"req-789",identity:{sourceIp:"203.0.113.42"}},queryStringParameters:null,body:JSON.stringify({event:"page view",data:{title:"Home"}}),isBase64Encoded:!1},out:[["elb",{name:"page view",data:{title:"Home"}}]]},P={title:"Lambda GET",description:"An API Gateway v2 HTTP GET with query parameters is parsed into an elb event payload.",trigger:{type:"GET"},in:{version:"2.0",requestContext:{http:{method:"GET",path:"/collect"},requestId:"req-456"},rawQueryString:"e=page+view&d=%7B%22title%22%3A%22Home%22%7D",isBase64Encoded:!1},out:[["elb",{e:"page view",d:'{"title":"Home"}'}]]},M=require("@walkeros/core"),z=require("@walkeros/core"),$=require("@walkeros/core"),_=(require("@walkeros/core"),require("@walkeros/core")),H=require("@walkeros/core"),N=require("@walkeros/core"),R=require("@walkeros/core"),G=require("@walkeros/core"),B=require("@walkeros/core"),F=require("@walkeros/core"),U=require("@walkeros/core"),L=require("@walkeros/core"),K=require("@walkeros/core"),Q=require("@walkeros/core"),J={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",Scoped:"_",Session:"session",Shutdown:"shutdown",User:"user",Walker:"walker"};function W(e,t){const n=e.status.startedAt;return{flowId:"default",stepId:t.stepId,stepType:t.stepType,phase:t.phase,eventId:t.eventId,timestamp:new Date(t.now).toISOString(),elapsedMs:t.now-n}}function V(e,t,n,o){if(!Number.isFinite(n.max)||n.max<=0)throw new Error(`pushBounded: max must be > 0 (got ${n.max})`);if("dropNewest"===(n.onOverflow??"dropOldest"))return e.length>=n.max?(o&&o([t]),{appended:!1,dropped:1}):(e.push(t),{appended:!0,dropped:0});const r=[];for(;e.length>=n.max;)r.push(e.shift());return e.push(t),r.length>0&&o&&o(r),{appended:!0,dropped:r.length}}var Y=new WeakMap;function X(e,t,n,o){Y.get(e)||(Y.set(e,!0),t.warn(n,o))}function Z(e){Y.delete(e)}var ee=()=>Date.now();function te(e){if(void 0!==e)return"number"==typeof e?{threshold:e,cooldown:3e4}:{threshold:e.threshold??5,cooldown:e.cooldown??3e4}}function ne(e,t,n,o,r){if("partial"===n)return;const s=((i=e)[a=t]||(i[a]={state:"closed",consecutiveFailures:0}),i[a]);var i,a;return"success"===n?(s.consecutiveFailures=0,s.state="closed",s.probing=!1,void(s.openUntil=void 0)):(s.consecutiveFailures+=1,"half-open"===s.state?(s.state="open",s.probing=!1,void(s.openUntil=ee()+r)):void(s.consecutiveFailures>=o&&(s.state="open",s.probing=!1,s.openUntil=ee()+r)))}function oe(e,t){return e.status.destinations[t]||(e.status.destinations[t]={count:0,failed:0,duration:0,queuePushSize:0,dlqSize:0}),e.status.destinations[t]}function re(e,t,n,o){e.dropped[t]||(e.dropped[t]={});const r=e.dropped[t];return r[n]=(r[n]??0)+o,r[n]}function se(e,t,n,o,r){const s=(0,N.stepId)(t,n);return(t,i)=>{try{if(i)return r?function(e,t,n,o,r,s){const i=t.dlq=t.dlq||[],a={max:t.config.dlqMax??100},c=V(i,[o,r],a);if(c.dropped>0){const t=re(e.status,(0,N.stepId)("destination",n),"dlq",c.dropped);X(i,s,"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:n,cap:a.max,droppedCount:t})}else i.length<a.max&&Z(i);const u=oe(e,n);u.failed++,u.dlqSize=i.length,e.status.failed++;const d=te(t.config.breaker);if(d){const o=t.config.id||n;ne(e.status.breakers,(0,N.stepId)("destination",o),"transport-failure",d.threshold,d.cooldown)}}(e,r,n,i,t,o):e.status.failed++,void o.error("report error",{error:t instanceof Error?t.message:String(t),event:i.name});e.status.connectionErrors[s]=(e.status.connectionErrors[s]??0)+1,o.error("connection error",{error:t instanceof Error?t.message:String(t)})}catch{}}}function ie(e,t){return e.storeId&&t.stores[e.storeId]?t.stores[e.storeId]:t.stores.__cache}function ae(e,t){return e?t.stores[e]:t.stores.__cache}function ce(e){const t={};for(const[n,o]of Object.entries(e)){const e=o.config?.next;"string"==typeof e||Array.isArray(e)&&e.every(e=>"string"==typeof e)?t[n]={next:e}:t[n]={}}return t}function ue(e,t){const n=e.config||{},o=e[t];return void 0!==o?{config:{...n,[t]:o},chainValue:o}:{config:n,chainValue:void 0}}function de(e,t={}){if(!e)return[];if(Array.isArray(e))return e;const n=[],o=new Set;let r=e;for(;r&&t[r]&&!o.has(r);){o.add(r),n.push(r);const e=t[r].next;if(Array.isArray(e)){n.push(...e);break}r=e}return n}async function le(e,t,n){if(t.init&&!t.config.init){const o=t.type||"unknown",r=e.logger.scope(`transformer:${o}`),s={collector:e,logger:r,id:n,ingest:(0,G.createIngest)(n),config:t.config,env:he(t.config.env),reportError:se(e,"transformer",n,r)};r.debug("init");const i=await(0,G.useHooks)(t.init,"TransformerInit",e.hooks,e.logger)(s);if(!1===i)return!1;t.config={...i||t.config,env:i?.env||t.config.env,init:!0},r.debug("init done")}return!0}async function pe(e,t,n,o,r,s){const i=t.type||"unknown",a=e.logger.scope(`transformer:${i}`),c={collector:e,logger:a,id:n,ingest:r,config:t.config,env:{...he(t.config.env),...s?{respond:s}:{}},reportError:se(e,"transformer",n,a)};a.debug("push",{event:o.name});const u="string"==typeof o.id?o.id:"",d=Date.now(),l=W(e,{stepId:(0,G.stepId)("transformer",n),stepType:"transformer",phase:"in",eventId:u,now:d});l.inEvent=o,(0,G.emitStep)(e,l);try{const r=await(0,G.useHooks)(t.push,"TransformerPush",e.hooks,e.logger)(o,c),s=Date.now(),i=W(e,{stepId:(0,G.stepId)("transformer",n),stepType:"transformer",phase:"out",eventId:u,now:s});return i.durationMs=s-d,i.outEvent=r,(0,G.emitStep)(e,i),a.debug("push done"),r}catch(t){const o=Date.now(),r=W(e,{stepId:(0,G.stepId)("transformer",n),stepType:"transformer",phase:"error",eventId:u,now:o});throw r.durationMs=o-d,r.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},(0,G.emitStep)(e,r),t}}function fe(e,t){return e?{...e,_meta:{...e._meta,path:[...e._meta.path]}}:(0,G.createIngest)(t)}async function ge(e,t,n,o,r,s,i){r||(r=(0,G.createIngest)(n[0]??"chain")),i&&r._meta&&(r._meta.chainPath=i);let a=o,c=s;for(const o of n){const s=t[o];if(!s){e.logger.warn(`Transformer not found: ${o}`);continue}if(r&&r._meta&&r._meta.path.length>256)return e.logger.error(`Max path length exceeded at ${o}`),{event:null,respond:c};if(r&&r._meta&&(r._meta.hops++,r._meta.path.push(o)),!await(0,G.tryCatchAsync)(le,t=>{if(t instanceof G.FatalError)throw t;return e.status.failed++,e.logger.scope(`transformer:${s.type||"unknown"}`).error("transformer init failed",{transformer:o,error:t}),!1})(e,s,o))return{event:null,respond:c};if(i&&void 0!==s.config?.chainMocks?.[i]){const t=s.config.chainMocks[i];e.logger.scope(`transformer:${s.type||"unknown"}`).debug("chainMock",{chain:i}),a=t;continue}if(void 0!==s.config?.mock){e.logger.scope(`transformer:${s.type||"unknown"}`).debug("mock"),a=s.config.mock;continue}if(s.config?.disabled)continue;const u=s.config?.cache,d=u?(0,G.compileCache)(u):void 0,l=d?ie(d,e):void 0,p=s.config?.state?(0,G.compileState)(s.config.state):void 0,f=p?.filter(e=>"get"===e.mode),g=p?.filter(e=>"set"===e.mode),h=async t=>g&&0!==g.length?(0,G.applyState)(g,t=>ae(t,e),t,e):t;let m;if(d&&l){const e=(0,G.buildCacheContext)(r,a),t=await(0,G.checkCache)(d,l,e);if("HIT"===t?.status&&t.value){if(a=t.value,d.stop)return{event:a,respond:c,stopped:!0};continue}"MISS"===t?.status&&(m={key:t.key,ttl:t.rule.ttl})}const y=s.config.before;if(y){const n=(0,G.getNextSteps)(y,(0,G.buildCacheContext)(r,a));if(1===n.length){const o=de(n[0],ce(t));if(o.length>0){const n=await ge(e,t,o,a,r,c,i);if(null===n.event)return{event:null,respond:n.respond??c};if(n.stopped)return{event:Array.isArray(n.event)?n.event[0]:n.event,respond:n.respond??c,stopped:!0};n.respond&&(c=n.respond),a=Array.isArray(n.event)?n.event[0]:n.event}}else n.length>1&&await Promise.all(n.map(n=>(0,G.tryCatchAsync)(ge,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,de(n,ce(t)),a,fe(r,n),void 0,i)))}f&&f.length>0&&(a=await(0,G.applyState)(f,t=>ae(t,e),a,e));const v=await(0,G.tryCatchAsync)(pe,t=>(e.logger.scope(`transformer:${s.type||"unknown"}`).error("Push failed",{error:t}),!1))(e,s,o,a,r,c);if(!1===v)return{event:null,respond:c};if(Array.isArray(v)){const s=n.slice(n.indexOf(o)+1),u=await Promise.all(v.map(async n=>{const o=await h(n.event||a),u=fe(r,"unknown");if(n.next){const r=(0,G.getNextSteps)(n.next,(0,G.buildCacheContext)(u,o));if(0===r.length)return{event:o,respond:c};if(1===r.length){const n=de(r[0],ce(t));return n.length>0?ge(e,t,n,o,u,c,i):{event:o,respond:c}}return(await Promise.all(r.map(n=>(0,G.tryCatchAsync)(ge,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,de(n,ce(t)),o,fe(u,n),void 0,i)))).map(e=>({event:e.event,respond:void 0}))}return s.length>0?ge(e,t,s,o,u,c,i):{event:o,respond:c}}));let d=c;const l=[];for(const e of u.flat())if(null!==e)if(e&&"object"==typeof e&&"event"in e){const t=e;if(t.respond&&(d=t.respond),null===t.event)continue;Array.isArray(t.event)?l.push(...t.event):l.push(t.event)}else l.push(e);return 0===l.length?{event:null,respond:d}:1===l.length?{event:l[0],respond:d}:{event:l,respond:d}}if(v&&"object"==typeof v){const{event:n,respond:o,next:s}=v;if(o&&(c=o),void 0!==s){const o=await h(n||a),u=(0,G.getNextSteps)(s,(0,G.buildCacheContext)(r,o));if(0===u.length){a=o;continue}if(1===u.length){const n=de(u[0],ce(t));return n.length>0?ge(e,t,n,o,r,c,i):(e.logger.warn(`Branch target not found: ${JSON.stringify(s)}`),{event:null,respond:c})}return await Promise.all(u.map(n=>(0,G.tryCatchAsync)(ge,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,de(n,ce(t)),o,fe(r,n),void 0,i))),{event:null,respond:void 0}}n&&(a=n)}g&&g.length>0&&(a=await(0,G.applyState)(g,t=>ae(t,e),a,e)),m&&l&&(0,G.storeCache)(l,m.key,a,m.ttl);const w=s.config.next,b="string"==typeof w||Array.isArray(w)&&w.every(e=>"string"==typeof e),k=void 0!==w&&!b;if((!v||"object"==typeof v&&!v.next)&&k){const n=(0,G.getNextSteps)(s.config.next,(0,G.buildCacheContext)(r,a));if(1===n.length){const o=de(n[0],ce(t));return o.length>0?ge(e,t,o,a,r,c,i):{event:a,respond:c}}return n.length>1?(await Promise.all(n.map(n=>(0,G.tryCatchAsync)(ge,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,de(n,ce(t)),a,fe(r,n),void 0,i))),{event:null,respond:void 0}):{event:a,respond:c}}}return{event:a,respond:c}}function he(e){return e&&(0,G.isObject)(e)?e:{}}function me(e){return"string"==typeof e||!(!Array.isArray(e)||!e.every(e=>"string"==typeof e))}async function ye(e,t,n){if(!t.on||!t.queueOn?.length)return;const o=t.queueOn;t.queueOn=[];const r=n||t.config?.id||"unknown";for(const{type:n,data:s}of o)Oe(n)&&!De(e,t,n)||(await(0,R.tryCatchAsync)(t.on,t=>{if(t instanceof R.FatalError)throw t;e.status.failed++,e.logger.scope("source").error("source on flush failed",{sourceId:r,type:n,error:t})})(n,s),Oe(n)&&Ae(e,t,n))}function ve(e){return Boolean(e.config.init)&&!e.config.require?.length}async function we(e,t,n){const{code:o,config:r={},env:s={},primary:i,next:a,before:c,cache:u}=n,d=r.state??n.state,l=d?(0,R.compileState)(d):void 0,p=u,f=p?(0,R.compileCache)({...p,stop:p.stop??!0}):void 0,g=me(a)?de(a,ce(e.transformers)):void 0,h=me(c)?de(c,ce(e.transformers)):void 0,m=s.push,y=m??e.push,v=Boolean(m),w=async(n,o,s)=>{let i;const u=h??(void 0!==c?(()=>{const t=(0,R.getNextSteps)(c,(0,R.buildCacheContext)(s.ingest));return 0===t.length?[]:de(1===t.length?t[0]:t,ce(e.transformers))})():[]);let d=[n];if(u.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const o=await ge(e,e.transformers,u,n,s.ingest,s.respond,`source.${t}.before`);if(null===o.event)return{ok:!0};if(o.stopped)return o.respond&&(s.respond=o.respond),{ok:!0};o.respond&&(s.respond=o.respond),d=Array.isArray(o.event)?o.event:[o.event]}if(f){const t=ie(f,e);if(t){const n=(0,R.buildCacheContext)(s.ingest),o=await(0,R.checkCache)(f,t,n);if(o){if("HIT"===o.status&&void 0!==o.value&&f.stop){let t=o.value;return o.rule.update&&(t=await(0,R.applyUpdate)(t,o.rule.update,{...n,cache:{status:"HIT"}},e)),s.respond?.(t),{ok:!0}}if("MISS"===o.status&&f.stop&&s.respond){const r=s.respond,a=o.rule.update,c={...n,cache:{status:"MISS"}},u=o.key,d=o.rule.ttl,l=n=>{(0,R.storeCache)(t,u,n,d),a?i=(async()=>{const t=await(0,R.applyUpdate)(n,a,c,e);r(t)})():r(n)};s.respond=l}"MISS"!==o.status||f.stop||(0,R.storeCache)(t,o.key,!0,o.rule.ttl)}}}const p=g?{kind:"single",preChain:g}:void 0!==a?(()=>{const t=(0,R.getNextSteps)(a,(0,R.buildCacheContext)(s.ingest));return 0===t.length?{kind:"single",preChain:[]}:1===t.length?{kind:"single",preChain:de(t[0],ce(e.transformers))}:{kind:"many",branches:t.map(t=>de(t,ce(e.transformers)))}})():{kind:"single",preChain:[]};!v&&l&&l.length>0&&(d=await Promise.all(d.map(t=>(0,R.applyState)(l,t=>ae(t,e),t,e))));let m={ok:!0};for(const n of d)"many"===p.kind?(await Promise.all(p.branches.map((i,a)=>(0,R.tryCatchAsync)(async()=>v?y(n):y(n,{...o,id:t,ingest:fe(s.ingest,`${t}.${a}`),respond:void 0,mapping:r,preChain:i}),t=>(e.logger.scope("source:many").error(`many branch ${a} failed`,{error:t}),{ok:!0}))())),m={ok:!0}):m=v?await y(n):await y(n,{...o,id:t,ingest:s.ingest,respond:s.respond,mapping:r,preChain:p.preChain});return i&&await i,m},b=async n=>{const o=(0,R.createIngest)(t);if(!r.ingest||void 0===n)return o;const s=await(0,R.getMappingValue)(n,r.ingest,{collector:e});return{...o,...s,_meta:o._meta}},k=e.logger.scope("source").scope(t),S={command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:k,...s,push:async(e,n={})=>{const o={ingest:(0,R.createIngest)(t),respond:void 0};return w(e,n,o)}},q={collector:e,logger:k,id:t,config:r,env:S,withScope:async(e,t,n)=>{const o={ingest:await b(e),respond:t};return n({...S,push:(e,t={})=>w(e,t,o),ingest:o.ingest,respond:o.respond})},reportError:se(e,"source",t,k)},I=await(0,R.tryCatchAsync)(o,n=>{if(n instanceof R.FatalError)throw n;e.status.failed++,e.logger.scope("source").error("source factory failed",{sourceId:t,error:n})})(q);if(!I)return;const C=I.type||"unknown",O=e.logger.scope(C).scope(t);return S.logger=O,i&&(I.config={...I.config,primary:i}),I}async function be(e){for(const[t,n]of Object.entries(e.sources)){if(ve(n))continue;const o=n.config.require;if(!o?.length)continue;const r=o.filter(t=>!je(e,t));r.length!==o.length&&(n.config.require=r,ve(n)&&await ye(e,n,t))}for(const[t,n]of Object.entries(e.pending.destinations)){if(!e.pending.destinations[t]||e.destinations[t])continue;const o=n.config?.require;if(!o)continue;const r=o.filter(t=>!je(e,t));if(n.config&&(n.config.require=r),r.length>0)continue;delete e.pending.destinations[t];const s=We(n);!1!==s.config.queue&&(s.queuePush=[...e.queue]),e.destinations[t]=s}}function ke(e){if("object"!=typeof e||null===e)return!1;if(!("logger"in e))return!1;const t=e.logger;return"object"==typeof t&&null!==t&&"scope"in t&&"function"==typeof t.scope}var Se=!1;function qe(){Se||(Se=!0,"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn("walkerOS: ignored an on-dispatch call with a non-collector argument"))}function Ie(e,t,n,o){if(n instanceof _.FatalError)throw n;e.logger.scope("on").error("on callback failed",{kind:t,...o,error:n})}var Ce=[J.Consent,J.User,J.Globals,J.Custom];function Oe(e){return Ce.includes(e)}function xe(e,t){switch(t){case J.Consent:return Object.keys(e.consent).length>0;case J.User:return Object.keys(e.user).length>0;case J.Globals:return Object.keys(e.globals).length>0;case J.Custom:return Object.keys(e.custom).length>0;default:return!1}}function je(e,t){switch(t){case J.Consent:case J.User:case J.Globals:case J.Custom:return xe(e,t);case J.Run:case J.Ready:return!0===e.allowed;default:return e.seenEvents.has(String(t))}}function Ee(e,t){return e.cellVersion[String(t)]??0}function Ae(e,t,n){let o=e.delivery.get(t);o||(o={},e.delivery.set(t,o)),o[String(n)]=Ee(e,n)}function De(e,t,n){return e.allowed&&Ee(e,n)>function(e,t,n){const o=e.delivery.get(t),r=o?.[String(n)];return void 0===r?-1:r}(e,t,n)}function Te(e,t,n){const o=e.cascade;if(!o)return!0;let r=o.counts.get(t);r||(r={},o.counts.set(t,r));const s=String(n),i=(r[s]||0)+1;return r[s]=i,i<=8||(9===i&&e.logger.error("state delivery did not converge",{type:s}),!1)}function Pe(e,t){return{collector:e,logger:e.logger.scope("on").scope(String(t))}}function Me(e,t,n,o,r){if(!t.on)return;const s=t.type||"unknown",i=e.logger.scope(s).scope("on").scope(o),a={collector:e,logger:i,id:n,config:t.config,data:r,env:Ve(t.env,t.config.env),reportError:se(e,"destination",n,i,t)};(0,H.tryCatch)(t.on,t=>Ie(e,"destination",t,{destId:n,type:o}))(o,a)}function ze(e,t,n,o){if(!ke(e))return void qe();const r=$e(e,t,o);if(n.length)switch(t){case J.Consent:!function(e,t,n){const o=n||e.consent,r=Pe(e,J.Consent);t.forEach(t=>{De(e,t,J.Consent)&&Te(e,t,J.Consent)&&(Object.keys(o).filter(e=>e in t).forEach(n=>{(0,H.tryCatch)(t[n],t=>Ie(e,"consent",t,{key:n}))(o,r)}),Ae(e,t,J.Consent))})}(e,n,o);break;case J.Ready:!function(e,t){if(!e.allowed)return;const n=Pe(e,J.Ready);t.forEach(t=>{(0,H.tryCatch)(t,t=>Ie(e,"ready",t))(void 0,n)})}(e,n);break;case J.Run:!function(e,t){if(!e.allowed)return;const n=Pe(e,J.Run);t.forEach(t=>{(0,H.tryCatch)(t,t=>Ie(e,"run",t))(void 0,n)})}(e,n);break;case J.Session:!function(e,t){if(!e.session)return;const n=Pe(e,J.Session);t.forEach(t=>{(0,H.tryCatch)(t,t=>Ie(e,"session",t))(e.session,n)})}(e,n);break;default:{const o=Pe(e,t),s=Oe(t);n.forEach(n=>{"function"==typeof n&&(s&&!De(e,n,t)||s&&!Te(e,n,t)||((0,H.tryCatch)(n,n=>Ie(e,"generic",n,{type:t}))(r,o),s&&Ae(e,n,t)))});break}}}function $e(e,t,n){switch(t){case J.Consent:return n||e.consent;case J.Session:return e.session;case J.User:return n||e.user;case J.Custom:return n||e.custom;case J.Globals:return n||e.globals;case J.Config:return n||e.config;default:return}}async function _e(e,t,n,o,r){if(!t.on)return!1;if(Oe(o)&&!De(e,t,o))return!1;if(Oe(o)&&!Te(e,t,o))return!1;const s=await(0,H.tryCatchAsync)(t.on,t=>Ie(e,"source",t,{sourceId:n,type:o}))(o,r);return Oe(o)&&Ae(e,t,o),!1===s}function He(e){return"number"==typeof e&&e>0?e:1e4}var Ne=class extends Error{constructor(e){super(e),this.name="DestinationTimeoutError"}};function Re(e,t,n){let o;const r=new Promise((e,r)=>{o=setTimeout(()=>r(new Ne(n)),t)});return Promise.race([e,r]).finally(()=>{o&&clearTimeout(o)})}var Ge=Object.freeze({batched:!0});function Be(e){return e===Ge}function Fe(e){return void 0===e?{}:"number"==typeof e?{wait:e}:{wait:e.wait,size:e.size,age:e.age}}function Ue(e,t,n){if(!e)return[];if(Array.isArray(e)&&e.every(e=>"string"==typeof e))return de(e,t);if("string"==typeof e)return de(e,t);const o=(0,$.getNextSteps)(e,(0,$.buildCacheContext)(n));return 0===o.length?[]:1===o.length?de(o[0],t):de(o,t)}async function Le(e,t,n={},o){const{allowed:r,consent:s,globals:i,user:a}=e;if(!r)return Je({ok:!1});if(t){const n=e.config.queueMax;if(void 0===n)throw new Error("Collector.Config.queueMax is undefined; defaults must be seeded by collector()");const o=V(e.queue,t,{max:n});if(o.dropped>0){const t=re(e.status,(0,$.stepId)("collector"),"queue",o.dropped);X(e.queue,e.logger,"collector.queue overflow; oldest events dropped",{buffer:"queue",cap:n,droppedCount:t})}else e.queue.length<n&&Z(e.queue);e.status.in++}o||(o=e.destinations);const c=e.transformers?ce(e.transformers):{},u=await Promise.all(Object.entries(o||{}).map(async([o,r])=>{if(r.config.disabled)return{id:o,destination:r,skipped:!0};const u=r.config.id||o,d=(0,$.stepId)("destination",u),l=te(r.config.breaker);if(l&&function(e,t,n){const o=e[t];if(!o||"closed"===o.state)return!1;if("half-open"===o.state)return!0===o.probing;const r=ee();return void 0!==o.openUntil&&r<o.openUntil||(o.state="half-open",o.probing=!0,o.openUntil=r+n,!1)}(e.status.breakers,d,l.cooldown))return{id:o,destination:r,skipped:!0};const p=t=>{l&&ne(e.status.breakers,d,t,l.threshold,l.cooldown)},f=()=>{l&&function(e,t){const n=e[t];n&&"half-open"===n.state&&!0===n.probing&&(n.state="open",n.probing=!1)}(e.status.breakers,d)};let g=(r.queuePush||[]).map(e=>({...e,consent:s}));r.queuePush=[],t&&g.push((0,$.clone)(t));const h=n.ingest?{...n.ingest,_meta:{...n.ingest._meta,path:[...n.ingest._meta.path]}}:(0,$.createIngest)("unknown");if(!g.length&&!r.queueOn?.length)return f(),{id:o,destination:r,skipped:!0};if(!g.length&&r.queueOn?.length){if(!(0,$.getGrantedConsent)(r.config.consent,s))return f(),{id:o,destination:r,skipped:!0};let t=!1;try{t=await Ke(e,r,o,!0)}catch(t){e.status.failed++;const n=r.type||"unknown";e.logger.scope(n).error("destination init failed",{error:t instanceof Error?t.message:String(t)}),p("transport-failure")}return f(),{id:o,destination:r,skipped:!t}}const m=[],y=g.filter(t=>{const n=(0,$.getGrantedConsent)(r.config.consent,s,t.consent);if(n)return t.consent=n,m.push(t),!1;const i=W(e,{stepId:(0,$.stepId)("destination",o),stepType:"destination",phase:"skip",eventId:"string"==typeof t.id?t.id:"",now:Date.now()});return i.skipReason="consent",s&&(i.consent={...s}),r.config.consent&&(i.meta={required:{...r.config.consent}}),(0,$.emitStep)(e,i),!0});if(y.length>0){const t=r.queuePush,n=r.config.id||o,s={max:r.config.queueMax??1e3};let i=0;for(const e of y)i+=V(t,e,s).dropped;if(i>0){oe(e,n);const o=re(e.status,(0,$.stepId)("destination",n),"queue",i);X(t,e.logger.scope(r.type||"unknown"),"destination.queuePush overflow; oldest events dropped",{buffer:"queuePush",destination:n,cap:s.max,droppedCount:o})}else t.length<s.max&&Z(t)}if(!m.length)return f(),{id:o,destination:r,queue:g};let v,w,b=!1;try{b=await Ke(e,r,o,!0)}catch(t){e.status.failed++;const n=r.type||"unknown";e.logger.scope(n).error("destination init failed",{error:t instanceof Error?t.message:String(t)}),p("transport-failure")}if(!b)return f(),{id:o,destination:r,queue:g};r.dlq||(r.dlq=[]);const k=Ue(r.config.before,c,h),S=r.config.next,q=r.config?.cache,I=q?(0,$.compileCache)(q):void 0,C=I?ie(I,e):void 0,O=r.config?.state?(0,$.compileState)(r.config.state):void 0,x=O?.filter(e=>"get"===e.mode),j=O?.filter(e=>"set"===e.mode);let E=0,A=0;return await Promise.all(m.map(async t=>{let s;if(t.globals=(0,$.assign)(i,t.globals),t.user=(0,$.assign)(a,t.user),I?.stop&&C){const e=(0,$.buildCacheContext)(h,t),n=await(0,$.checkCache)(I,C,e);if("HIT"===n?.status)return t;"MISS"===n?.status&&(s={key:n.key,ttl:n.rule.ttl})}let u=t,d=n.respond;if(k.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const r=await ge(e,e.transformers,k,t,h,n.respond,`destination.${o}.before`);if(null===r.event)return t;r.respond&&(d=r.respond),u=Array.isArray(r.event)?r.event[0]:r.event}if(I&&!I.stop&&C){const e=(0,$.buildCacheContext)(h,u),n=await(0,$.checkCache)(I,C,e);if("HIT"===n?.status)return t;"MISS"===n?.status&&(s={key:n.key,ttl:n.rule.ttl})}x&&x.length>0&&u&&(u=await(0,$.applyState)(x,t=>ae(t,e),u,e));const l=Date.now();let p=!1;const f=await(0,$.tryCatchAsync)(Qe,t=>{const n=r.type||"unknown";e.logger.scope(n).error("Push failed",{error:t,event:u.name}),v=t,p=!0;const s=r.dlq,i=r.config.id||o,a={max:r.config.dlqMax??100},c=V(s,[u,t],a);if(c.dropped>0){oe(e,i);const t=re(e.status,(0,$.stepId)("destination",i),"dlq",c.dropped);X(s,e.logger.scope(r.type||"unknown"),"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:i,cap:a.max,droppedCount:t})}else s.length<a.max&&Z(s)})(e,r,o,u,h,d);if(E+=Date.now()-l,s&&C&&void 0===r.config.mock&&(0,$.storeCache)(C,s.key,f??!0,s.ttl),!p&&!Be(f)&&j&&j.length>0&&u&&(u=await(0,$.applyState)(j,t=>ae(t,e),u,e)),void 0===f||Be(f)||(w=f),Be(f)&&A++,!p&&S){void 0!==f&&(h._response=f);const t=Ue(S,c,h);if(t.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const n=await ge(e,e.transformers,t,u,h,d,`destination.${o}.next`);n.respond&&(d=n.respond)}}return t})),{id:o,destination:r,error:v,response:w,totalDuration:E,batchedCount:A,allowedCount:m.length,canonicalId:u,breakerConfig:l}})),d={},l={},p={};for(const t of u){if(t.skipped)continue;const n=t.destination,o={type:n.type||"unknown",data:t.response};oe(e,t.id);const r=e.status.destinations[t.id],s=Date.now();r.queuePushSize=n.queuePush?.length??0,r.dlqSize=n.dlq?.length??0;const i=t.breakerConfig,a=t.canonicalId?(0,$.stepId)("destination",t.canonicalId):void 0,c=t=>{i&&a&&ne(e.status.breakers,a,t,i.threshold,i.cooldown)};if(t.error)o.error=t.error,p[t.id]=o,r.failed++,r.lastAt=s,r.duration+=t.totalDuration||0,e.status.failed++,c("transport-failure");else if(t.queue&&t.queue.length)l[t.id]=o;else{const n=t.batchedCount??0,i=t.allowedCount??0;(Math.max(0,i-n)>0||0===i)&&(d[t.id]=o,r.count++,r.lastAt=s,r.duration+=t.totalDuration||0,e.status.out++,c("success"))}}return Je({event:t,...Object.keys(d).length&&{done:d},...Object.keys(l).length&&{queued:l},...Object.keys(p).length&&{failed:p}})}async function Ke(e,t,n,o=!1){if(t.init&&!t.config.init){if(!o&&function(e){const t=e.config.consent;return!!t&&Object.keys(t).length>0}(t))return e.logger.scope(t.type||"unknown").debug("init blocked: consent gate not cleared"),!1;const r=t.type||"unknown",s=e.logger.scope(r),i={collector:e,logger:s,id:n,config:t.config,env:Ve(t.env,t.config.env),reportError:se(e,"destination",n,s,t)};s.debug("init");const a=Date.now();let c;(0,$.emitStep)(e,W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"init",eventId:"",now:a}));try{c=await(0,$.useHooks)(t.init,"DestinationInit",e.hooks,e.logger)(i)}catch(t){const o=Date.now(),r=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"error",eventId:"",now:o});throw r.durationMs=o-a,r.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},(0,$.emitStep)(e,r),t}if(!1===c)return c;if(t.config={...c||t.config,init:!0},t.queueOn?.length){const o=t.queueOn;t.queueOn=[];for(const{type:r,data:s}of o)Me(e,t,n,r,s)}s.debug("init done")}return!0}async function Qe(e,t,n,o,r,s){const{config:i}=t,a=await(0,$.processEventMapping)(o,i,e);if(a.ignore)return!1;const c=t.type||"unknown",u=e.logger.scope(c),d={collector:e,logger:u,id:n,config:i,data:a.data,rule:a.mapping,ingest:r,env:{...Ve(t.env,i.env),...s?{respond:s}:{}},reportError:se(e,"destination",n,u,t)};if(void 0!==i.mock)return u.debug("mock",{event:a.event.name}),i.mock;const l=a.mapping,p=void 0!==l?.batch,f=p?a.mappingKey||"* *":" batch-all";if((p||void 0!==i.batch)&&t.pushBatch&&void 0===i.mock){if(t.batches=t.batches||{},!t.batches[f]){const o={key:f,entries:[],events:[],data:[]},r=Fe(l?.batch),s=Fe(i.batch),a=r.wait??s.wait??3e4,c=r.size??s.size??1e3,d=r.age??s.age??3e4,g=Ve(t.env,i.env),h=(0,$.debounce)(async()=>{const o=t.batches[f],r=o.batched;if(0===r.entries.length)return;const s={key:r.key,entries:r.entries,events:r.events,data:r.data};r.entries=[],r.events=[],r.data=[];const a=s.entries[0],c={collector:e,logger:u,id:n,config:i,data:void 0,rule:o.isDefault?void 0:a.rule,ingest:a.ingest,env:{...g,...a.respond?{respond:a.respond}:{}},reportError:se(e,"destination",n,u,t)};u.debug("push batch",{events:s.entries.length});const d=t.config.id||n,l=oe(e,d),p=te(t.config.breaker),h=(0,$.stepId)("destination",d),m=t=>{p&&ne(e.status.breakers,h,t,p.threshold,p.cooldown)},y=Date.now(),v=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"flush",eventId:"",now:y});v.batch={size:s.entries.length,index:0},(0,$.emitStep)(e,v);const w=n=>{const o=t.dlq=t.dlq||[],r={max:t.config.dlqMax??100};let s=0;for(const e of n)s+=V(o,e,r).dropped;if(s>0){const t=re(e.status,(0,$.stepId)("destination",d),"dlq",s);X(o,u,"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:d,cap:r.max,droppedCount:t})}else o.length<r.max&&Z(o);l.failed+=n.length,l.dlqSize=o.length,e.status.failed+=n.length};let b=s.entries.length;const k=He(i.timeout),S=await(0,$.tryCatchAsync)((o,r)=>Re(Promise.resolve((0,$.useHooks)(t.pushBatch,"DestinationPushBatch",e.hooks,e.logger)(o,r)),k,`Destination "${n}" batch delivery timed out after ${k}ms`),t=>{b=0;const o=Date.now(),r=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"error",eventId:"",now:o});r.durationMs=o-y,r.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},r.batch={size:s.entries.length,index:0},(0,$.emitStep)(e,r),w(s.entries.map(e=>[e.event,t])),m("transport-failure"),u.error("Push batch failed",{error:t instanceof Error?t.message:String(t),entries:s.entries.length})})(s,c);if((0,$.isObject)(q=S)&&Array.isArray(q.failed)&&S.failed.length>0){const e=[],t=new Set;for(const n of S.failed){const o=s.entries[n.index];o&&!t.has(n.index)&&(t.add(n.index),e.push([o.event,n.error??new Error(`Push batch entry ${n.index} failed (no per-row error provided)`)]))}e.length>0&&(w(e),b=Math.max(0,s.entries.length-e.length),u.error("Push batch partial failure",{failed:e.length,delivered:b,entries:s.entries.length}))}var q;u.debug("push batch done"),l.inFlightBatch=Math.max(0,(l.inFlightBatch??0)-s.entries.length),b>0&&(l.count+=b,l.lastAt=Date.now(),e.status.out+=b,m("success"))},{wait:a,size:c,age:d});t.batches[f]={batched:o,isDefault:!p,batchFn:()=>{h()},flush:async()=>{await h.flush()}}}const o=t.batches[f];o.batched.entries.push({event:a.event,ingest:r,respond:s,rule:l,data:a.data}),o.batched.events.push(a.event),(0,$.isDefined)(a.data)&&o.batched.data.push(a.data);const c=t.config.id||n,d=oe(e,c);return d.inFlightBatch=(d.inFlightBatch??0)+1,o.batchFn(),Ge}{u.debug("push",{event:a.event.name});const o="string"==typeof a.event.id?a.event.id:"",r=Date.now(),s=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"in",eventId:o,now:r});a.mappingKey&&(s.mappingKey=a.mappingKey),a.event.consent&&(s.consent={...a.event.consent}),s.inEvent=a.event,(0,$.emitStep)(e,s);try{const s=He(i.timeout),c=await Re(Promise.resolve((0,$.useHooks)(t.push,"DestinationPush",e.hooks,e.logger)(a.event,d)),s,`Destination "${n}" delivery timed out after ${s}ms`),l=Date.now(),p=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"out",eventId:o,now:l});return p.durationMs=l-r,p.outEvent=a.event,(0,$.isDefined)(c)&&(p.meta={...p.meta,response:c}),a.mappingKey&&(p.mappingKey=a.mappingKey),(0,$.emitStep)(e,p),u.debug("push done"),c}catch(t){const s=Date.now(),i=W(e,{stepId:(0,$.stepId)("destination",n),stepType:"destination",phase:"error",eventId:o,now:s});throw i.durationMs=s-r,i.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},a.mappingKey&&(i.mappingKey=a.mappingKey),(0,$.emitStep)(e,i),t}}}function Je(e){return{ok:!e?.failed,...e}}function We(e){const{code:t,config:n={},env:o={},cache:r,state:s}=e,{config:i}=ue(e,"before"),{config:a}=ue({...e,config:i},"next"),c={...t.config,...n,...a};r&&(c.cache=r),void 0!==s&&void 0===c.state&&(c.state=s);const u=Ve(t.env,o);return{...t,config:c,env:u}}function Ve(e,t){return e||t?t?e&&(0,$.isObject)(e)&&(0,$.isObject)(t)?{...e,...t}:t:e:{}}async function Ye(e,t,n){const o=Object.entries(e).map(async([e,o])=>{const r=o.destroy;if(!r)return;const s=o.type||"unknown",i=n.scope(s),a={id:e,config:o.config,env:o.env??{},logger:i};let c;try{await Promise.race([r(a),new Promise((n,o)=>{c=setTimeout(()=>o(new Error(`${t} '${e}' destroy timed out`)),5e3)})])}catch(n){i.error(`${t} '${e}' destroy failed: ${n}`)}finally{c&&clearTimeout(c)}});await Promise.allSettled(o)}function Xe(e,t){e.stateVersion++,e.cellVersion[t]=e.stateVersion}async function Ze(e,t,n){let o,r,s=!1;const i=function(e){return e.cascade?()=>{}:(e.cascade={counts:new WeakMap},()=>{e.cascade=void 0})}(e);try{return await async function(){switch(t){case J.Config:(0,F.isObject)(n)&&((0,B.assign)(e.config,n,{shallow:!1}),r=n,s=!0);break;case J.Consent:if((0,F.isObject)(n)){const{update:t}=function(e,t){const n={};return Object.entries(t).forEach(([e,t])=>{n[e]=!!t}),e.consent=(0,M.assign)(e.consent,n),{update:n}}(e,n);Xe(e,J.Consent),r=t,s=!0}break;case J.Custom:(0,F.isObject)(n)&&(e.custom=(0,B.assign)(e.custom,n),Xe(e,J.Custom),r=n,s=!0);break;case J.Destination:(0,F.isObject)(n)&&"code"in n&&(0,F.isObject)(n.code)&&(o=await async function(e,t){const{code:n,config:o={},env:r={},before:s,next:i,cache:a,state:c}=t;if(!(0,$.isFunction)(n.push))return Je({ok:!1,failed:{invalid:{type:"invalid",error:"Destination code must have a push method"}}});const u=o||{init:!1};let d=s?{...u,before:s}:{...u};i&&(d={...d,next:i}),a&&(d={...d,cache:a}),void 0!==c&&void 0===d.state&&(d={...d,state:c});let l=d.id;if(!l)do{l=(0,$.getId)(5,"abcdefghijklmnopqrstuvwxyz")}while(e.destinations[l]||e.pending.destinations[l]);if(d.require?.length){e.pending.destinations[l]=t,await be(e);const n=e.destinations[l];return n?Le(e,void 0,{},{[l]:n}):Je({ok:!0})}const p={...n,config:d,env:Ve(n.env,r)};return e.destinations[l]=p,!1!==p.config.queue&&(p.queuePush=[...e.queue]),Le(e,void 0,{},{[l]:p})}(e,n));break;case J.Globals:(0,F.isObject)(n)&&(e.globals=(0,B.assign)(e.globals,n),Xe(e,J.Globals),r=n,s=!0);break;case J.Hook:if((0,F.isObject)(n)&&(0,B.isString)(n.name)&&(0,B.isFunction)(n.fn)){const{name:t,fn:o}=n;e.hooks[t]=o,r=n,s=!0}break;case J.On:if((0,F.isObject)(n)&&(0,B.isString)(n.type)){const{type:t,rules:o}=n;await async function(e,t,n){if(!ke(e))return void qe();const o=e.on,r=o[t]||[],s=(0,_.isArray)(n)?n:[n];s.forEach(e=>{r.push(e)}),o[t]=r,ze(e,t,s)}(e,t,o)}break;case J.Ready:s=!0;break;case J.Run:o=await async function(e,t){return e.allowed=!0,e.timing=Date.now(),e.trace=(0,B.getTraceId)(),e.count=0,t&&(t.consent&&(e.consent=(0,B.assign)(e.consent,t.consent),Xe(e,J.Consent)),t.user&&(e.user=(0,B.assign)(e.user,t.user),Xe(e,J.User)),t.globals&&(e.globals=(0,B.assign)(e.config.globalsStatic||{},t.globals),Xe(e,J.Globals)),t.custom&&(e.custom=(0,B.assign)(e.custom,t.custom),Xe(e,J.Custom))),Object.values(e.destinations).forEach(e=>{e.queuePush=[]}),e.queue=[],e.round++,await be(e),await async function(e){if(ke(e))for(const t of Ce){if(!xe(e,t))continue;const n=$e(e,t);ze(e,t,e.on[t]||[]);for(const[o,r]of Object.entries(e.sources))ve(r)&&await _e(e,r,o,t,n)}else qe()}(e),await Le(e)}(e,n),s=!0;break;case J.Session:s=!0;break;case J.Shutdown:e.hasShutdown||(e.hasShutdown=!0,await async function(e){const t=e.logger;await Ye(e.sources,"source",t),await async function(e,t){const n=Object.entries(e).flatMap(([e,n])=>{const o=n.batches;if(!o)return[];const r=t.scope(n.type||"destination");return Object.values(o).map(async t=>{let n;try{await Promise.race([t.flush(),new Promise((t,o)=>{n=setTimeout(()=>o(new Error(`destination '${e}' batch flush timed out`)),5e3)})])}catch(t){r.error(`destination '${e}' batch flush failed: ${t}`)}finally{n&&clearTimeout(n)}})});await Promise.allSettled(n)}(e.destinations,t),await Ye(e.destinations,"destination",t),await Ye(e.transformers,"transformer",t),await Ye(e.stores,"store",t)}(e));break;case J.User:(0,F.isObject)(n)&&((0,B.assign)(e.user,n,{shallow:!1}),Xe(e,J.User),r=n,s=!0)}return s&&(await async function(e,t,n,o){if(!ke(e))return qe(),!0;e.seenEvents.add(String(t));let r=n||[];n||(r=e.on[t]||[]);const s=$e(e,t,o);let i=!1;for(const[n,o]of Object.entries(e.sources)){if(o.config.require?.length){const e=o.config.require.indexOf(t);-1!==e&&o.config.require.splice(e,1)}o.on&&(ve(o)?await _e(e,o,n,t,s)&&(i=!0):(o.queueOn=o.queueOn||[],o.queueOn.push({type:t,data:s})))}Object.entries(e.destinations).forEach(([n,o])=>{if(o.on){if(!o.config.init)return o.queueOn=o.queueOn||[],void o.queueOn.push({type:t,data:s});Me(e,o,n,t,s)}});for(const[t,n]of Object.entries(e.sources))ve(n)&&n.queueOn?.length&&await ye(e,n,t);const a=Object.values(e.sources).some(e=>!ve(e)&&e.config.require?.length);return(Object.keys(e.pending.destinations).length>0||a)&&await be(e),ze(e,t,r,o),!i}(e,t,void 0,r),o=await Le(e)),o||Je({ok:!0})}()}finally{i()}}function et(e,t){return{timing:Math.round((Date.now()-e.timing)/10)/100,source:{type:"collector",schema:"4",version:"4.2.1"},...t}}function tt(e,t){if(!t.name)throw new Error("Event name is required");const[n,o]=t.name.split(" ");if(!n||!o)throw new Error("Event name is invalid");const{timestamp:r=Date.now(),name:s=`${n} ${o}`,data:i={},context:a={},globals:c=e.globals,custom:u={},user:d=e.user,nested:l=[],consent:p=e.consent,id:f=(0,B.getSpanId)(),trigger:g="",entity:h=n,action:m=o,timing:y=0,source:v={type:"collector",schema:"4"}}=t,w=v.count??(e.count+=1),b=v.trace??e.trace,k={...v,count:w};return void 0!==b&&(k.trace=b),{name:s,data:i,context:a,globals:c,custom:u,user:d,nested:l,consent:p,id:f,trigger:g,entity:h,action:m,timestamp:r,timing:y,source:k}}function nt(e,t){const n=(0,U.useHooks)(async(n,o={})=>await(0,U.tryCatchAsync)(async()=>{const r=Date.now(),{id:s,ingest:i,respond:a,mapping:c,preChain:u,include:d,exclude:l}=o;let p=a,f=n;const g=d||l?function(e,t,n){let o=e;return t&&(o=Object.fromEntries(Object.entries(o).filter(([e])=>t.includes(e)))),n&&(o=Object.fromEntries(Object.entries(o).filter(([e])=>!n.includes(e)))),o}(e.destinations,d,l):void 0,h=i??(0,U.createIngest)(s||"unknown");if(c){const t=await(0,U.processEventMapping)(f,c,e);if(t.ignore)return Je({ok:!0});if(c.consent&&!(0,U.getGrantedConsent)(c.consent,e.consent,t.event.consent))return Je({ok:!0});f=t.event}if(u?.length&&e.transformers&&Object.keys(e.transformers).length>0){const n=await ge(e,e.transformers,u,f,h,p,s?`source.${s}.next`:void 0);if(null===n.event)return Je({ok:!0});if(n.stopped)return n.respond&&(p=n.respond),Je({ok:!0});if(n.respond&&(p=n.respond),Array.isArray(n.event)){const o=await Promise.all(n.event.map(async n=>{const o=t(n),r=tt(e,o);return Le(e,r,{id:s,ingest:h,respond:p},g)}));if(s){e.status.sources[s]||(e.status.sources[s]={count:0,duration:0});const t=e.status.sources[s];t.count+=n.event.length,t.lastAt=Date.now(),t.duration+=Date.now()-r}return o[0]??Je({ok:!0})}f=n.event}const m=function(e,t){return tt(e,et(e,t))}(e,f),y=await Le(e,m,{id:s,ingest:h,respond:p},g);if(s){e.status.sources[s]||(e.status.sources[s]={count:0,duration:0});const t=e.status.sources[s];t.count++,t.lastAt=Date.now(),t.duration+=Date.now()-r}return y},t=>{if(t instanceof U.FatalError)throw t;return e.status.failed++,e.logger.error("push failed",{event:n,ingest:o.ingest,error:t}),Je({ok:!1})})(),"Push",e.hooks,e.logger);return async(t,o)=>{const r="string"==typeof t.id?t.id:"",s=Date.now(),i=W(e,{stepId:"collector.push",stepType:"collector",phase:"in",eventId:r,now:s});i.inEvent=t,(0,U.emitStep)(e,i);try{const i=await n(t,o),a=Date.now(),c=W(e,{stepId:"collector.push",stepType:"collector",phase:"out",eventId:r,now:a});return c.durationMs=a-s,c.outEvent=i,(0,U.emitStep)(e,c),i}catch(t){const n=Date.now(),o=W(e,{stepId:"collector.push",stepType:"collector",phase:"error",eventId:r,now:n});throw o.durationMs=n-s,o.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},(0,U.emitStep)(e,o),t}}}function ot(e={}){const t=e.maxEntries??1e4,n=e.lowWaterMark??.8,o=e.sweepIntervalMs??6e4,r=Math.floor(t*n),s=new Map,i={hits:0,misses:0,populates:0,writes:0,deletes:0,evictions_entries:0,evictions_ttl:0};let a;return o>0&&(a=setInterval(function(){const e=Date.now();let t=0;for(const[n,o]of s)void 0!==o.expires&&o.expires<=e&&(s.delete(n),t++);i.evictions_ttl+=t},o),a&&"function"==typeof a.unref&&a.unref()),{type:"memory",config:{},get(e){const t=s.get(e);if(t)return void 0!==t.expires&&t.expires<=Date.now()?(s.delete(e),i.evictions_ttl++,void i.misses++):(s.delete(e),s.set(e,t),i.hits++,t.value);i.misses++},set(e,n,o){const a=!s.has(e);a||s.delete(e),s.set(e,{value:n,expires:void 0!==o?Date.now()+o:void 0}),i.writes++,a&&i.populates++,s.size>t&&function(){if(s.size<=t)return;const e=s.size-r;let n=0;for(const t of s.keys()){if(n>=e)break;s.delete(t),n++}i.evictions_entries+=n}()},delete(e){s.delete(e)&&i.deletes++},get counters(){return{...i}},destroy(){void 0!==a&&(clearInterval(a),a=void 0),s.clear()}}}function rt(e,t){const{cacheConfig:n,cacheStore:o,namespace:r,logger:s,storeId:i,collector:a}=t,c=(e,t)=>{if(!a)return;const n=W(a,{stepId:`store.${i}`,stepType:"store",phase:"in",eventId:"",now:Date.now()});n.meta={op:"cache",cached:"hit"===t,status:t,key:e},(0,Q.emitStep)(a,n)},u={hits:0,misses:0,populates:0,writes:0,deletes:0,inflight_dedups:0},d=n.rules.map(e=>({match:e.match?(0,Q.compileMatcher)(e.match):()=>!0,ttl:e.ttl})),l=e=>`${r}:${e}`;function p(e,t){const n=void 0===t?{key:e}:{key:e,value:t};return d.find(e=>e.match(n))}const f=new Map;return{type:e.type,config:e.config,setup:e.setup,get counters(){return{...u}},async get(t){const n=l(t),r=await o.get(n),s=(0,Q.readCacheEnvelope)(r);if(void 0!==s){if(!("expired"in s))return u.hits++,c(t,"hit"),s.value;try{await o.delete(n)}catch(e){g("delete",t,e)}}const i=f.get(n);if(i)return u.inflight_dedups++,c(t,"hit"),i;u.misses++,c(t,"miss");const a=(async()=>{try{const r=await e.get(t);if(void 0===r)return;const s=p(t,r);if(s)try{const e=1e3*s.ttl;await o.set(n,(0,Q.wrapCacheEnvelope)(r,e),e),u.populates++}catch(e){g("set",t,e)}return r}finally{f.delete(n)}})();return f.set(n,a),a},async set(t,n,r){u.writes++,await e.set(t,n,r);const s=p(t,n);if(s)try{const e=1e3*s.ttl;await o.set(l(t),(0,Q.wrapCacheEnvelope)(n,e),e)}catch(e){g("set",t,e)}},async delete(t){u.deletes++,await e.delete(t);try{await o.delete(l(t))}catch(e){g("delete",t,e)}}};function g(e,t,n){const o=`store-cache(${i}): cache ${e} failed for "${t}"; backing succeeded, continuing`;s?s.warn(o,{error:n}):console.warn(o,n)}}function st(e,t,n){const o=`store.${n}`,r=(0,K.useHooks)(t.get,"StoreGet",e.hooks,e.logger),s=(0,K.useHooks)(t.set,"StoreSet",e.hooks,e.logger),i=(0,K.useHooks)(t.delete,"StoreDelete",e.hooks,e.logger);t.get=async t=>{const n=Date.now(),s=W(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:n});s.meta={op:"get",key:t},(0,K.emitStep)(e,s);try{const s=await r(t),i=Date.now(),a=W(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:i});return a.durationMs=i-n,a.meta={op:"get",key:t},(0,K.emitStep)(e,a),s}catch(r){const s=Date.now(),i=W(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:s});throw i.durationMs=s-n,i.meta={op:"get",key:t},i.error=r instanceof Error?{name:r.name,message:r.message}:{message:String(r)},(0,K.emitStep)(e,i),r}},t.set=async(t,n,r)=>{const i=Date.now(),a=W(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:i});a.meta={op:"set",key:t},(0,K.emitStep)(e,a);try{await s(t,n,r);const a=Date.now(),c=W(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:a});c.durationMs=a-i,c.meta={op:"set",key:t},(0,K.emitStep)(e,c)}catch(n){const r=Date.now(),s=W(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:r});throw s.durationMs=r-i,s.meta={op:"set",key:t},s.error=n instanceof Error?{name:n.name,message:n.message}:{message:String(n)},(0,K.emitStep)(e,s),n}},t.delete=async t=>{const n=Date.now(),r=W(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:n});r.meta={op:"delete",key:t},(0,K.emitStep)(e,r);try{await i(t);const r=Date.now(),s=W(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:r});s.durationMs=r-n,s.meta={op:"delete",key:t},(0,K.emitStep)(e,s)}catch(r){const s=Date.now(),i=W(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:s});throw i.durationMs=s-n,i.meta={op:"delete",key:t},i.error=r instanceof Error?{name:r.name,message:r.message}:{message:String(r)},(0,K.emitStep)(e,i),r}}}async function it(e){const t=(0,z.assign)({globalsStatic:{},sessionStatic:{},run:!0,queueMax:1e3},e,{merge:!1,extend:!1}),n={level:e.logger?.level,handler:e.logger?.handler},o=(0,z.createLogger)(n),r={...t.globalsStatic,...e.globals},s={allowed:!1,config:t,consent:e.consent||{},custom:e.custom||{},destinations:{},transformers:{},stores:{},globals:r,hooks:e.hooks||{},observers:new Set,logger:o,on:{},queue:[],round:0,count:0,stateVersion:0,cellVersion:{},delivery:new WeakMap,session:void 0,status:{startedAt:Date.now(),in:0,out:0,failed:0,sources:{},destinations:{},dropped:{},connectionErrors:{},breakers:{}},timing:Date.now(),user:e.user||{},sources:{},pending:{destinations:{}},hasShutdown:!1,seenEvents:new Set,push:void 0,command:void 0};var i,a;s.push=nt(s,e=>et(s,e)),s.command=(i=s,a=Ze,(0,L.useHooks)(async(e,t,n)=>await(0,L.tryCatchAsync)(async()=>await a(i,e,t,n),n=>{if(n instanceof L.FatalError)throw n;return i.status.failed++,i.logger.error("command failed",{command:e,data:t,error:n}),Je({ok:!1})})(),"Command",i.hooks,i.logger));const c=e.stores||{};return s.stores=await async function(e,t={}){const n={};for(const[o,r]of Object.entries(t)){const{code:t,config:s={},env:i={}}=r,a=e.logger.scope("store").scope(o),c={collector:e,logger:a,id:o,config:s,env:i,reportError:se(e,"store",o,a)},u=await t(c);n[o]=u}const o=t,r=function(e){const t={};for(const n of Object.keys(e))t[n]="WHITE";const n=[],o=[];function r(s){const i=t[s];if("BLACK"===i)return;if("GRAY"===i){const e=o.indexOf(s),t=o.slice(-1===e?0:e).concat(s).join(" -> ");throw new Error(`Cycle in cache.store chain: ${t}`)}t[s]="GRAY",o.push(s);const a=e[s].cache?.store;if(void 0!==a){if(!(a in e))throw new Error(`Store "${s}" cache.store references "${a}", which is not declared in flow.stores`);r(a)}o.pop(),t[s]="BLACK",n.push(s)}for(const n of Object.keys(e))"WHITE"===t[n]&&r(n);return n}(o);for(const t of r){const r=o[t].cache;if(!r)continue;let s,i;void 0!==r.store?(s=n[r.store],i=r.store):(n.__cache||(n.__cache=ot()),s=n.__cache,i="__cache");const a=r.namespace??t;e.logger.scope("store-cache").scope(t).info(`store "${t}" caches with namespace "${a}:" via ${i}`),n[t]=rt(n[t],{storeId:t,cacheConfig:r,cacheStore:s,namespace:a,logger:e.logger.scope("store-cache").scope(t),collector:e})}for(const[t,o]of Object.entries(n))"__cache"!==t&&st(e,o,t);return n}(s,c),function(e,t,n){const o=new Map;for(const[n,r]of Object.entries(e))t[n]&&o.set(r,t[n]);if(0!==o.size)for(const e of[n.transformers,n.destinations,n.sources])if(e)for(const t of Object.values(e))r(t.env);function r(e){if(e)for(const[t,n]of Object.entries(e))if("object"==typeof n&&null!==n){const r=o.get(n);r&&(e[t]=r)}}}(c,s.stores,e),s.stores.__cache||(s.stores.__cache=ot()),s.destinations=await async function(e,t={}){const n={};for(const[o,r]of Object.entries(t))r.config?.require?.length?e.pending.destinations[o]=r:n[o]=We(r);return n}(s,e.destinations||{}),s.transformers=await async function(e,t={}){const n={};for(const[o,r]of Object.entries(t)){const{code:t,env:s={}}=r,i=(0,G.validateStepEntry)(r,"Transformer");if(!i.ok){e.logger.warn(`Transformer ${o} invalid (${i.code}): ${i.reason}. Skipping.`);continue}const{config:a}=ue(r,"before"),{config:c}=ue({...r,config:a},"next"),u=Object.keys(s).length>0?{...c,env:s}:c,{cache:d}=r,l=d?{...u,cache:d}:u,p=r.config?.state??r.state,f=void 0!==p&&void 0===l.state?{...l,state:p}:l,g=e.logger.scope("transformer").scope(o),h={collector:e,logger:g,id:o,ingest:(0,G.createIngest)(o),config:f,env:s,reportError:se(e,"transformer",o,g)},m=t??(e=>{const t=r.mapping;if(t){const n=[];if(void 0!==t.data&&n.push("data"),t.mapping)for(const[e,o]of Object.entries(t.mapping))if("object"==typeof o&&null!==o)for(const[t,r]of Object.entries(o)){if("object"!=typeof r||null===r)continue;const o=r;void 0!==o.data&&n.push(`mapping[${e}][${t}].data`),void 0!==o.silent&&n.push(`mapping[${e}][${t}].silent`)}return n.length>0&&e.collector.logger.warn(`Transformer ${o}: \`${n.join(", ")}\` ignored at transformer position (only event-mutating fields apply).`),{type:"pass",config:e.config,push:async n=>{const o=await(0,G.processEventMapping)(n,t,e.collector);return!o.ignore&&{event:o.event}}}}return{type:"pass",config:e.config,push:e=>({event:e})}}),y=await m(h);void 0!==r.before&&void 0===y.config?.before&&(y.config={...y.config??{},before:r.before}),void 0!==r.next&&void 0===y.config?.next&&(y.config={...y.config??{},next:r.next}),void 0!==p&&void 0===y.config?.state&&(y.config={...y.config??{},state:p}),n[o]=y}return n}(s,e.transformers||{}),s}async function at(e){e=e||{};const t=await it(e),n=(o=t,{type:"elb",config:{},push:async(e,t,n,r,s)=>{if("string"==typeof e&&e.startsWith("walker ")){const n=e.replace("walker ","");return o.command(n,t)}let i;if("string"==typeof e)i={name:e},t&&"object"==typeof t&&!Array.isArray(t)&&(i.data=t);else{if(!e||"object"!=typeof e)return Je({ok:!1});i=e,t&&"object"==typeof t&&!Array.isArray(t)&&(i.data={...i.data||{},...t})}return n&&"object"==typeof n&&(i.context=n),r&&Array.isArray(r)&&(i.nested=r),s&&"object"==typeof s&&(i.custom=s),o.push(i)}});var o;t.sources.elb=n,await async function(e,t={}){const n={};for(const[o,r]of Object.entries(t)){const t=await we(e,o,r);if(!t)continue;const s=r.config?.require;t.config={...t.config,init:!1,...s?{require:[...s]}:{}},n[o]=t}Object.assign(e.sources,n);for(const t of Object.keys(n)){const n=e.sources[t];let o=!1;n.init&&await(0,R.tryCatchAsync)(n.init.bind(n),n=>{if(n instanceof R.FatalError)throw n;o=!0,e.status.failed++,e.logger.scope("source").error("source init failed",{sourceId:t,error:n})})(),o||(n.config.init=!0,ve(n)&&await ye(e,n,t))}return await be(e),n}(t,e.sources||{});const{consent:r,user:s,globals:i,custom:a}=e;r&&await t.command("consent",r),s&&await t.command("user",s),i&&await t.command("globals",i),a&&await t.command("custom",a),t.config.run&&await t.command("run");let c=n.push;const u=Object.values(t.sources).filter(e=>"elb"!==e.type),d=u.find(e=>e.config.primary);return d?c=d.push:u.length>0&&(c=u[0].push),{collector:t,elb:c}}var ct=async e=>{let t;return{get flow(){return t},trigger:()=>async n=>{if(!t){const n=await at(e);t={collector:n.collector,elb:n.elb}}const o=function(e){for(const t of Object.values(e.sources||{}))if("lambda"===t.type)return t}(t.collector);if(!o)throw new Error("Lambda source not found in collector");const r={awsRequestId:`test-${Date.now()}`},s=o.push,i=await s(n,r);let a;try{a=JSON.parse(i.body||"{}")}catch{a=i.body}const c={};if(i.headers)for(const[e,t]of Object.entries(i.headers))void 0!==t&&(c[e]=String(t));return{statusCode:i.statusCode,body:a,headers:c}}}};function ut(e){return async t=>{const n={...t};if(n.body&&"string"==typeof n.body){const e=JSON.parse(n.body);e.name&&!e.event&&(n.body=JSON.stringify({...e,event:e.name,name:void 0}))}return e.push(n,{awsRequestId:"test-req"})}}var dt={};s(dt,{createTrigger:()=>qt,env:()=>lt,step:()=>yt});var lt={};s(lt,{push:()=>ht,simulation:()=>mt});var pt=()=>{},ft={error:pt,warn:pt,info:pt,debug:pt,throw:e=>{throw"string"==typeof e?new Error(e):e},json:pt,scope:()=>ft},gt=()=>()=>Promise.resolve({ok:!0}),ht={get push(){return gt()},get command(){return gt()},get elb(){return gt()},logger:ft},mt=["AWS.SQSClient"],yt={};s(yt,{decoderText:()=>bt,malformedJson:()=>kt,orderComplete:()=>wt,pageView:()=>vt});var vt={title:"Page view from SQS",description:"A standard SQS message body containing a walker elb event payload as JSON.",in:{MessageId:"m-1",Body:JSON.stringify({event:"page view",data:{title:"Documentation",url:"https://example.com/docs"}})},out:[["message.ack","m-1"]]},wt={title:"Order complete from SQS",description:"Order complete event flowing through the long-poll loop.",in:{MessageId:"m-2",Body:JSON.stringify({event:"order complete",data:{id:"ORD-500",total:199.99,currency:"EUR"}})},out:[["message.ack","m-2"]]},bt={title:"Text decoder",description:'When decoder is "text", the body string flows under data.payload.',in:{MessageId:"m-3",Body:"raw text payload"},out:[["message.ack","m-3"]]},kt={title:"Malformed JSON nacks",description:"Default decoder is JSON. A malformed body throws DecoderError; the source nacks (skips DeleteMessage) so the message redelivers.",in:{MessageId:"m-4",Body:"{not json"},out:[["message.nack","m-4"]]};function St(e){if("object"!=typeof e||null===e)return!1;const t=e;return"sqs"===t.type&&"function"==typeof t.push}var qt=async e=>{let t;return{get flow(){return t},trigger:()=>async n=>{if(!t){const n=await at(e);t={collector:n.collector,elb:n.elb}}const o=function(e){for(const t of Object.values(e.sources??{}))if(St(t))return t}(t.collector);if(!o)throw new Error("sqs source not registered in collector, ensure it is configured in sources");const r={MessageId:n.MessageId,Body:n.Body,ReceiptHandle:n.ReceiptHandle,Attributes:n.Attributes,MessageAttributes:n.MessageAttributes},s=await o.push(r),i=[];return s&&"object"==typeof s&&(s.acked&&i.push(["message.ack",n.MessageId]),s.nacked&&i.push(["message.nack",n.MessageId])),i}}};//# sourceMappingURL=dev.js.map
|
package/dist/dev.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.defineProperty,t=(t,n)=>{for(var o in n)e(t,o,{get:n[o],enumerable:!0})},n={};t(n,{CorsOptionsSchema:()=>c,CorsOrigin:()=>a,HttpMethod:()=>i,SettingsSchema:()=>u,settings:()=>l,sqsSettings:()=>y,sqsSetup:()=>v});import{zodToSchema as o}from"@walkeros/core/dev";import{z as s}from"@walkeros/core/dev";import{z as r}from"@walkeros/core/dev";var i=r.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),a=r.union([r.string(),r.array(r.string()),r.literal("*")]),c=r.object({origin:a.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:r.array(i).describe("Allowed HTTP methods").optional(),headers:r.array(r.string()).describe("Allowed request headers").optional(),credentials:r.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:r.number().int().positive().describe("Preflight cache duration in seconds").optional()}),u=s.object({cors:s.union([s.boolean(),c]).describe("CORS configuration: false = disabled, true = allow all origins, object = custom configuration").default(!0),timeout:s.number().int().positive().max(9e5).describe("Request timeout in milliseconds (max: 900000 for Lambda)").default(3e4),enablePixelTracking:s.boolean().describe("Enable GET requests with 1x1 transparent GIF response for pixel tracking").default(!0),healthPath:s.string().describe("Health check endpoint path (e.g., /health)").default("/health")}),l=o(u);import{zodToSchema as d}from"@walkeros/core/dev";import{z as f}from"@walkeros/core/dev";var p=f.object({queueName:f.string().min(1).describe("SQS queue short name (like walkeros-events). Required for both setup and runtime poll."),region:f.string().describe("AWS region (like eu-central-1). Default: eu-central-1.").optional(),queueUrl:f.string().url().describe("Optional pre-resolved queue URL. When set, init skips the GetQueueUrl lookup.").optional(),client:f.any().describe("Pre-configured AWS SQSClient instance. Bypasses construction when supplied.").optional(),config:f.any().describe("AWS SDK SQSClientConfig (credentials, endpoint overrides, retries).").optional(),decoder:f.enum(["json","text","raw"]).describe("Decoder for the message body. json (default) parses JSON, text forwards UTF-8, raw forwards a Buffer.").optional(),maxMessages:f.number().int().min(1).max(10).describe("SQS receive batch size. Cap 10. Default: 10.").optional(),waitTimeSeconds:f.number().int().min(0).max(20).describe("Long-poll duration in seconds. Cap 20. Default: 20.").optional(),visibilityTimeout:f.number().int().nonnegative().describe("Per-receive visibility timeout override. Default: queue-configured value.").optional(),shutdownTimeoutMs:f.number().int().positive().describe("Graceful shutdown timeout in milliseconds. Default: 30000. After this window, destroy() force-closes.").optional(),onPushError:f.enum(["nack","ack"]).describe("Behavior when forwarding to the collector throws. nack (default) skips DeleteMessage so the message redelivers; ack drops it.").optional()});import{z as g}from"@walkeros/core/dev";var h=g.record(g.string(),g.string()),m=g.object({region:g.string().min(1).describe("AWS region.").optional(),fifoQueue:g.boolean().describe("FIFO queue with content-based deduplication. Auto-appends .fifo suffix to the queue name.").optional(),visibilityTimeoutSeconds:g.number().int().nonnegative().describe("Visibility timeout in seconds. Default: 30.").optional(),messageRetentionSeconds:g.number().int().positive().describe("Message retention period in seconds. Default: 345600 (4 days).").optional(),maximumMessageSize:g.number().int().min(1024).max(262144).describe("Max message size in bytes. Default: 262144 (256 KB).").optional(),kmsMasterKeyId:g.string().describe("KMS key alias or ID for at-rest encryption.").optional(),deadLetterQueue:g.object({arn:g.string().describe("ARN of an existing DLQ. Mutually exclusive with create: true.").optional(),create:g.boolean().describe("Create a sibling DLQ named <queueName>-dlq. Default: false.").optional(),maxReceiveCount:g.number().int().min(1).max(1e3).describe("Max receive count before message goes to DLQ. Default: 5.").optional()}).describe("Optional dead-letter queue.").optional(),tags:h.describe("Tags applied to the queue (and inherited by an auto-created DLQ).").optional(),subscribeToSnsTopic:g.object({topicArn:g.string().min(1).describe("Topic ARN to subscribe to."),rawMessageDelivery:g.boolean().describe("Deliver SNS messages without the SNS envelope.").optional(),filterPolicy:g.record(g.string(),g.unknown()).describe("SNS filter policy applied at subscription level.").optional()}).describe("Optional SNS topic subscription. Creates the subscription and the matching queue policy.").optional()}),y=d(p),v=d(m),w={};t(w,{createTrigger:()=>mn,env:()=>b,step:()=>x,trigger:()=>yn});var b={};t(b,{push:()=>I});var k=()=>()=>Promise.resolve({ok:!0}),S=()=>{},q={error:S,warn:S,info:S,debug:S,throw:e=>{throw"string"==typeof e?new Error(e):e},json:S,scope:()=>q},I={get push(){return k()},get command(){return k()},get elb(){return k()},logger:q},x={};t(x,{apiGatewayV1Post:()=>C,lambdaGet:()=>E,lambdaPost:()=>O});var O={title:"Lambda POST",description:"An API Gateway v2 HTTP POST with a JSON body is converted into a walker elb event.",trigger:{type:"POST"},in:{version:"2.0",requestContext:{http:{method:"POST",path:"/collect"},requestId:"req-123"},body:JSON.stringify({event:"page view",data:{title:"Home"}}),isBase64Encoded:!1},out:[["elb",{name:"page view",data:{title:"Home"}}]]},C={title:"API Gateway v1 POST",description:"A REST API Gateway v1 POST request with a JSON body is converted into a walker elb event.",trigger:{type:"POST"},in:{httpMethod:"POST",path:"/collect",requestContext:{requestId:"req-789",identity:{sourceIp:"203.0.113.42"}},queryStringParameters:null,body:JSON.stringify({event:"page view",data:{title:"Home"}}),isBase64Encoded:!1},out:[["elb",{name:"page view",data:{title:"Home"}}]]},E={title:"Lambda GET",description:"An API Gateway v2 HTTP GET with query parameters is parsed into an elb event payload.",trigger:{type:"GET"},in:{version:"2.0",requestContext:{http:{method:"GET",path:"/collect"},requestId:"req-456"},rawQueryString:"e=page+view&d=%7B%22title%22%3A%22Home%22%7D",isBase64Encoded:!1},out:[["elb",{e:"page view",d:'{"title":"Home"}'}]]};import{assign as D}from"@walkeros/core";import{assign as T,createLogger as j}from"@walkeros/core";import{assign as A,buildCacheContext as M,clone as P,compileCache as $,checkCache as _,storeCache as R,createIngest as H,debounce as G,emitStep as N,getId as z,getGrantedConsent as B,getNextSteps as U,isDefined as F,isFunction as L,isObject as K,processEventMapping as Q,stepId as J,tryCatchAsync as W,useHooks as V,compileState as Y,applyState as X}from"@walkeros/core";import{emitStep as Z}from"@walkeros/core";import{isArray as ee,FatalError as te}from"@walkeros/core";import{tryCatch as ne,tryCatchAsync as oe}from"@walkeros/core";import{stepId as se}from"@walkeros/core";import{createIngest as re,FatalError as ie,getMappingValue as ae,tryCatchAsync as ce,getNextSteps as ue,compileCache as le,checkCache as de,storeCache as fe,applyUpdate as pe,buildCacheContext as ge,compileState as he,applyState as me}from"@walkeros/core";import{createIngest as ye,emitStep as ve,FatalError as we,isObject as be,stepId as ke,tryCatchAsync as Se,useHooks as qe,getNextSteps as Ie,compileCache as xe,checkCache as Oe,storeCache as Ce,buildCacheContext as Ee,validateStepEntry as De,processEventMapping as Te,compileState as je,applyState as Ae}from"@walkeros/core";import{assign as Me,getSpanId as Pe,getTraceId as $e,isFunction as _e,isString as Re}from"@walkeros/core";import{isObject as He}from"@walkeros/core";import{createIngest as Ge,emitStep as Ne,FatalError as ze,getGrantedConsent as Be,processEventMapping as Ue,tryCatchAsync as Fe,useHooks as Le}from"@walkeros/core";import{FatalError as Ke,useHooks as Qe,tryCatchAsync as Je}from"@walkeros/core";import{emitStep as We,useHooks as Ve}from"@walkeros/core";import{compileMatcher as Ye,emitStep as Xe,readCacheEnvelope as Ze,wrapCacheEnvelope as et}from"@walkeros/core";var tt={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",Scoped:"_",Session:"session",Shutdown:"shutdown",User:"user",Walker:"walker"};function nt(e,t){const n=e.status.startedAt;return{flowId:"default",stepId:t.stepId,stepType:t.stepType,phase:t.phase,eventId:t.eventId,timestamp:new Date(t.now).toISOString(),elapsedMs:t.now-n}}function ot(e,t,n,o){if(!Number.isFinite(n.max)||n.max<=0)throw new Error(`pushBounded: max must be > 0 (got ${n.max})`);if("dropNewest"===(n.onOverflow??"dropOldest"))return e.length>=n.max?(o&&o([t]),{appended:!1,dropped:1}):(e.push(t),{appended:!0,dropped:0});const s=[];for(;e.length>=n.max;)s.push(e.shift());return e.push(t),s.length>0&&o&&o(s),{appended:!0,dropped:s.length}}var st=new WeakMap;function rt(e,t,n,o){st.get(e)||(st.set(e,!0),t.warn(n,o))}function it(e){st.delete(e)}var at=()=>Date.now();function ct(e){if(void 0!==e)return"number"==typeof e?{threshold:e,cooldown:3e4}:{threshold:e.threshold??5,cooldown:e.cooldown??3e4}}function ut(e,t,n,o,s){if("partial"===n)return;const r=((i=e)[a=t]||(i[a]={state:"closed",consecutiveFailures:0}),i[a]);var i,a;return"success"===n?(r.consecutiveFailures=0,r.state="closed",r.probing=!1,void(r.openUntil=void 0)):(r.consecutiveFailures+=1,"half-open"===r.state?(r.state="open",r.probing=!1,void(r.openUntil=at()+s)):void(r.consecutiveFailures>=o&&(r.state="open",r.probing=!1,r.openUntil=at()+s)))}function lt(e,t){return e.status.destinations[t]||(e.status.destinations[t]={count:0,failed:0,duration:0,queuePushSize:0,dlqSize:0}),e.status.destinations[t]}function dt(e,t,n,o){e.dropped[t]||(e.dropped[t]={});const s=e.dropped[t];return s[n]=(s[n]??0)+o,s[n]}function ft(e,t,n,o,s){const r=se(t,n);return(t,i)=>{try{if(i)return s?function(e,t,n,o,s,r){const i=t.dlq=t.dlq||[],a={max:t.config.dlqMax??100},c=ot(i,[o,s],a);if(c.dropped>0){const t=dt(e.status,se("destination",n),"dlq",c.dropped);rt(i,r,"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:n,cap:a.max,droppedCount:t})}else i.length<a.max&&it(i);const u=lt(e,n);u.failed++,u.dlqSize=i.length,e.status.failed++;const l=ct(t.config.breaker);if(l){const o=t.config.id||n;ut(e.status.breakers,se("destination",o),"transport-failure",l.threshold,l.cooldown)}}(e,s,n,i,t,o):e.status.failed++,void o.error("report error",{error:t instanceof Error?t.message:String(t),event:i.name});e.status.connectionErrors[r]=(e.status.connectionErrors[r]??0)+1,o.error("connection error",{error:t instanceof Error?t.message:String(t)})}catch{}}}function pt(e,t){return e.storeId&&t.stores[e.storeId]?t.stores[e.storeId]:t.stores.__cache}function gt(e,t){return e?t.stores[e]:t.stores.__cache}function ht(e){const t={};for(const[n,o]of Object.entries(e)){const e=o.config?.next;"string"==typeof e||Array.isArray(e)&&e.every(e=>"string"==typeof e)?t[n]={next:e}:t[n]={}}return t}function mt(e,t){const n=e.config||{},o=e[t];return void 0!==o?{config:{...n,[t]:o},chainValue:o}:{config:n,chainValue:void 0}}function yt(e,t={}){if(!e)return[];if(Array.isArray(e))return e;const n=[],o=new Set;let s=e;for(;s&&t[s]&&!o.has(s);){o.add(s),n.push(s);const e=t[s].next;if(Array.isArray(e)){n.push(...e);break}s=e}return n}async function vt(e,t,n){if(t.init&&!t.config.init){const o=t.type||"unknown",s=e.logger.scope(`transformer:${o}`),r={collector:e,logger:s,id:n,ingest:ye(n),config:t.config,env:St(t.config.env),reportError:ft(e,"transformer",n,s)};s.debug("init");const i=await qe(t.init,"TransformerInit",e.hooks,e.logger)(r);if(!1===i)return!1;t.config={...i||t.config,env:i?.env||t.config.env,init:!0},s.debug("init done")}return!0}async function wt(e,t,n,o,s,r){const i=t.type||"unknown",a=e.logger.scope(`transformer:${i}`),c={collector:e,logger:a,id:n,ingest:s,config:t.config,env:{...St(t.config.env),...r?{respond:r}:{}},reportError:ft(e,"transformer",n,a)};a.debug("push",{event:o.name});const u="string"==typeof o.id?o.id:"",l=Date.now(),d=nt(e,{stepId:ke("transformer",n),stepType:"transformer",phase:"in",eventId:u,now:l});d.inEvent=o,ve(e,d);try{const s=await qe(t.push,"TransformerPush",e.hooks,e.logger)(o,c),r=Date.now(),i=nt(e,{stepId:ke("transformer",n),stepType:"transformer",phase:"out",eventId:u,now:r});return i.durationMs=r-l,i.outEvent=s,ve(e,i),a.debug("push done"),s}catch(t){const o=Date.now(),s=nt(e,{stepId:ke("transformer",n),stepType:"transformer",phase:"error",eventId:u,now:o});throw s.durationMs=o-l,s.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},ve(e,s),t}}function bt(e,t){return e?{...e,_meta:{...e._meta,path:[...e._meta.path]}}:ye(t)}async function kt(e,t,n,o,s,r,i){s||(s=ye(n[0]??"chain")),i&&s._meta&&(s._meta.chainPath=i);let a=o,c=r;for(const o of n){const r=t[o];if(!r){e.logger.warn(`Transformer not found: ${o}`);continue}if(s&&s._meta&&s._meta.path.length>256)return e.logger.error(`Max path length exceeded at ${o}`),{event:null,respond:c};if(s&&s._meta&&(s._meta.hops++,s._meta.path.push(o)),!await Se(vt,t=>{if(t instanceof we)throw t;return e.status.failed++,e.logger.scope(`transformer:${r.type||"unknown"}`).error("transformer init failed",{transformer:o,error:t}),!1})(e,r,o))return{event:null,respond:c};if(i&&void 0!==r.config?.chainMocks?.[i]){const t=r.config.chainMocks[i];e.logger.scope(`transformer:${r.type||"unknown"}`).debug("chainMock",{chain:i}),a=t;continue}if(void 0!==r.config?.mock){e.logger.scope(`transformer:${r.type||"unknown"}`).debug("mock"),a=r.config.mock;continue}if(r.config?.disabled)continue;const u=r.config?.cache,l=u?xe(u):void 0,d=l?pt(l,e):void 0,f=r.config?.state?je(r.config.state):void 0,p=f?.filter(e=>"get"===e.mode),g=f?.filter(e=>"set"===e.mode),h=async t=>g&&0!==g.length?Ae(g,t=>gt(t,e),t,e):t;let m;if(l&&d){const e=Ee(s,a),t=await Oe(l,d,e);if("HIT"===t?.status&&t.value){if(a=t.value,l.stop)return{event:a,respond:c,stopped:!0};continue}"MISS"===t?.status&&(m={key:t.key,ttl:t.rule.ttl})}const y=r.config.before;if(y){const n=Ie(y,Ee(s,a));if(1===n.length){const o=yt(n[0],ht(t));if(o.length>0){const n=await kt(e,t,o,a,s,c,i);if(null===n.event)return{event:null,respond:n.respond??c};if(n.stopped)return{event:Array.isArray(n.event)?n.event[0]:n.event,respond:n.respond??c,stopped:!0};n.respond&&(c=n.respond),a=Array.isArray(n.event)?n.event[0]:n.event}}else n.length>1&&await Promise.all(n.map(n=>Se(kt,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,yt(n,ht(t)),a,bt(s,n),void 0,i)))}p&&p.length>0&&(a=await Ae(p,t=>gt(t,e),a,e));const v=await Se(wt,t=>(e.logger.scope(`transformer:${r.type||"unknown"}`).error("Push failed",{error:t}),!1))(e,r,o,a,s,c);if(!1===v)return{event:null,respond:c};if(Array.isArray(v)){const r=n.slice(n.indexOf(o)+1),u=await Promise.all(v.map(async n=>{const o=await h(n.event||a),u=bt(s,"unknown");if(n.next){const s=Ie(n.next,Ee(u,o));if(0===s.length)return{event:o,respond:c};if(1===s.length){const n=yt(s[0],ht(t));return n.length>0?kt(e,t,n,o,u,c,i):{event:o,respond:c}}return(await Promise.all(s.map(n=>Se(kt,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,yt(n,ht(t)),o,bt(u,n),void 0,i)))).map(e=>({event:e.event,respond:void 0}))}return r.length>0?kt(e,t,r,o,u,c,i):{event:o,respond:c}}));let l=c;const d=[];for(const e of u.flat())if(null!==e)if(e&&"object"==typeof e&&"event"in e){const t=e;if(t.respond&&(l=t.respond),null===t.event)continue;Array.isArray(t.event)?d.push(...t.event):d.push(t.event)}else d.push(e);return 0===d.length?{event:null,respond:l}:1===d.length?{event:d[0],respond:l}:{event:d,respond:l}}if(v&&"object"==typeof v){const{event:n,respond:o,next:r}=v;if(o&&(c=o),void 0!==r){const o=await h(n||a),u=Ie(r,Ee(s,o));if(0===u.length){a=o;continue}if(1===u.length){const n=yt(u[0],ht(t));return n.length>0?kt(e,t,n,o,s,c,i):(e.logger.warn(`Branch target not found: ${JSON.stringify(r)}`),{event:null,respond:c})}return await Promise.all(u.map(n=>Se(kt,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,yt(n,ht(t)),o,bt(s,n),void 0,i))),{event:null,respond:void 0}}n&&(a=n)}g&&g.length>0&&(a=await Ae(g,t=>gt(t,e),a,e)),m&&d&&Ce(d,m.key,a,m.ttl);const w=r.config.next,b="string"==typeof w||Array.isArray(w)&&w.every(e=>"string"==typeof e),k=void 0!==w&&!b;if((!v||"object"==typeof v&&!v.next)&&k){const n=Ie(r.config.next,Ee(s,a));if(1===n.length){const o=yt(n[0],ht(t));return o.length>0?kt(e,t,o,a,s,c,i):{event:a,respond:c}}return n.length>1?(await Promise.all(n.map(n=>Se(kt,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,yt(n,ht(t)),a,bt(s,n),void 0,i))),{event:null,respond:void 0}):{event:a,respond:c}}}return{event:a,respond:c}}function St(e){return e&&be(e)?e:{}}function qt(e){return"string"==typeof e||!(!Array.isArray(e)||!e.every(e=>"string"==typeof e))}async function It(e,t,n){if(!t.on||!t.queueOn?.length)return;const o=t.queueOn;t.queueOn=[];const s=n||t.config?.id||"unknown";for(const{type:n,data:r}of o)Mt(n)&&!Ht(e,t,n)||(await ce(t.on,t=>{if(t instanceof ie)throw t;e.status.failed++,e.logger.scope("source").error("source on flush failed",{sourceId:s,type:n,error:t})})(n,r),Mt(n)&&Rt(e,t,n))}function xt(e){return Boolean(e.config.init)&&!e.config.require?.length}async function Ot(e,t,n){const{code:o,config:s={},env:r={},primary:i,next:a,before:c,cache:u}=n,l=s.state??n.state,d=l?he(l):void 0,f=u,p=f?le({...f,stop:f.stop??!0}):void 0,g=qt(a)?yt(a,ht(e.transformers)):void 0,h=qt(c)?yt(c,ht(e.transformers)):void 0,m=r.push,y=m??e.push,v=Boolean(m),w=async(n,o,r)=>{let i;const u=h??(void 0!==c?(()=>{const t=ue(c,ge(r.ingest));return 0===t.length?[]:yt(1===t.length?t[0]:t,ht(e.transformers))})():[]);let l=[n];if(u.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const o=await kt(e,e.transformers,u,n,r.ingest,r.respond,`source.${t}.before`);if(null===o.event)return{ok:!0};if(o.stopped)return o.respond&&(r.respond=o.respond),{ok:!0};o.respond&&(r.respond=o.respond),l=Array.isArray(o.event)?o.event:[o.event]}if(p){const t=pt(p,e);if(t){const n=ge(r.ingest),o=await de(p,t,n);if(o){if("HIT"===o.status&&void 0!==o.value&&p.stop){let t=o.value;return o.rule.update&&(t=await pe(t,o.rule.update,{...n,cache:{status:"HIT"}},e)),r.respond?.(t),{ok:!0}}if("MISS"===o.status&&p.stop&&r.respond){const s=r.respond,a=o.rule.update,c={...n,cache:{status:"MISS"}},u=o.key,l=o.rule.ttl,d=n=>{fe(t,u,n,l),a?i=(async()=>{const t=await pe(n,a,c,e);s(t)})():s(n)};r.respond=d}"MISS"!==o.status||p.stop||fe(t,o.key,!0,o.rule.ttl)}}}const f=g?{kind:"single",preChain:g}:void 0!==a?(()=>{const t=ue(a,ge(r.ingest));return 0===t.length?{kind:"single",preChain:[]}:1===t.length?{kind:"single",preChain:yt(t[0],ht(e.transformers))}:{kind:"many",branches:t.map(t=>yt(t,ht(e.transformers)))}})():{kind:"single",preChain:[]};!v&&d&&d.length>0&&(l=await Promise.all(l.map(t=>me(d,t=>gt(t,e),t,e))));let m={ok:!0};for(const n of l)"many"===f.kind?(await Promise.all(f.branches.map((i,a)=>ce(async()=>v?y(n):y(n,{...o,id:t,ingest:bt(r.ingest,`${t}.${a}`),respond:void 0,mapping:s,preChain:i}),t=>(e.logger.scope("source:many").error(`many branch ${a} failed`,{error:t}),{ok:!0}))())),m={ok:!0}):m=v?await y(n):await y(n,{...o,id:t,ingest:r.ingest,respond:r.respond,mapping:s,preChain:f.preChain});return i&&await i,m},b=async n=>{const o=re(t);if(!s.ingest||void 0===n)return o;const r=await ae(n,s.ingest,{collector:e});return{...o,...r,_meta:o._meta}},k=e.logger.scope("source").scope(t),S={command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:k,...r,push:async(e,n={})=>{const o={ingest:re(t),respond:void 0};return w(e,n,o)}},q={collector:e,logger:k,id:t,config:s,env:S,withScope:async(e,t,n)=>{const o={ingest:await b(e),respond:t};return n({...S,push:(e,t={})=>w(e,t,o),ingest:o.ingest,respond:o.respond})},reportError:ft(e,"source",t,k)},I=await ce(o,n=>{if(n instanceof ie)throw n;e.status.failed++,e.logger.scope("source").error("source factory failed",{sourceId:t,error:n})})(q);if(!I)return;const x=I.type||"unknown",O=e.logger.scope(x).scope(t);return S.logger=O,i&&(I.config={...I.config,primary:i}),I}async function Ct(e){for(const[t,n]of Object.entries(e.sources)){if(xt(n))continue;const o=n.config.require;if(!o?.length)continue;const s=o.filter(t=>!$t(e,t));s.length!==o.length&&(n.config.require=s,xt(n)&&await It(e,n,t))}for(const[t,n]of Object.entries(e.pending.destinations)){if(!e.pending.destinations[t]||e.destinations[t])continue;const o=n.config?.require;if(!o)continue;const s=o.filter(t=>!$t(e,t));if(n.config&&(n.config.require=s),s.length>0)continue;delete e.pending.destinations[t];const r=nn(n);!1!==r.config.queue&&(r.queuePush=[...e.queue]),e.destinations[t]=r}}function Et(e){if("object"!=typeof e||null===e)return!1;if(!("logger"in e))return!1;const t=e.logger;return"object"==typeof t&&null!==t&&"scope"in t&&"function"==typeof t.scope}var Dt=!1;function Tt(){Dt||(Dt=!0,"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn("walkerOS: ignored an on-dispatch call with a non-collector argument"))}function jt(e,t,n,o){if(n instanceof te)throw n;e.logger.scope("on").error("on callback failed",{kind:t,...o,error:n})}var At=[tt.Consent,tt.User,tt.Globals,tt.Custom];function Mt(e){return At.includes(e)}function Pt(e,t){switch(t){case tt.Consent:return Object.keys(e.consent).length>0;case tt.User:return Object.keys(e.user).length>0;case tt.Globals:return Object.keys(e.globals).length>0;case tt.Custom:return Object.keys(e.custom).length>0;default:return!1}}function $t(e,t){switch(t){case tt.Consent:case tt.User:case tt.Globals:case tt.Custom:return Pt(e,t);case tt.Run:case tt.Ready:return!0===e.allowed;default:return e.seenEvents.has(String(t))}}function _t(e,t){return e.cellVersion[String(t)]??0}function Rt(e,t,n){let o=e.delivery.get(t);o||(o={},e.delivery.set(t,o)),o[String(n)]=_t(e,n)}function Ht(e,t,n){return e.allowed&&_t(e,n)>function(e,t,n){const o=e.delivery.get(t),s=o?.[String(n)];return void 0===s?-1:s}(e,t,n)}function Gt(e,t,n){const o=e.cascade;if(!o)return!0;let s=o.counts.get(t);s||(s={},o.counts.set(t,s));const r=String(n),i=(s[r]||0)+1;return s[r]=i,i<=8||(9===i&&e.logger.error("state delivery did not converge",{type:r}),!1)}function Nt(e,t){return{collector:e,logger:e.logger.scope("on").scope(String(t))}}function zt(e,t,n,o,s){if(!t.on)return;const r=t.type||"unknown",i=e.logger.scope(r).scope("on").scope(o),a={collector:e,logger:i,id:n,config:t.config,data:s,env:on(t.env,t.config.env),reportError:ft(e,"destination",n,i,t)};ne(t.on,t=>jt(e,"destination",t,{destId:n,type:o}))(o,a)}function Bt(e,t,n,o){if(!Et(e))return void Tt();const s=Ut(e,t,o);if(n.length)switch(t){case tt.Consent:!function(e,t,n){const o=n||e.consent,s=Nt(e,tt.Consent);t.forEach(t=>{Ht(e,t,tt.Consent)&&Gt(e,t,tt.Consent)&&(Object.keys(o).filter(e=>e in t).forEach(n=>{ne(t[n],t=>jt(e,"consent",t,{key:n}))(o,s)}),Rt(e,t,tt.Consent))})}(e,n,o);break;case tt.Ready:!function(e,t){if(!e.allowed)return;const n=Nt(e,tt.Ready);t.forEach(t=>{ne(t,t=>jt(e,"ready",t))(void 0,n)})}(e,n);break;case tt.Run:!function(e,t){if(!e.allowed)return;const n=Nt(e,tt.Run);t.forEach(t=>{ne(t,t=>jt(e,"run",t))(void 0,n)})}(e,n);break;case tt.Session:!function(e,t){if(!e.session)return;const n=Nt(e,tt.Session);t.forEach(t=>{ne(t,t=>jt(e,"session",t))(e.session,n)})}(e,n);break;default:{const o=Nt(e,t),r=Mt(t);n.forEach(n=>{"function"==typeof n&&(r&&!Ht(e,n,t)||r&&!Gt(e,n,t)||(ne(n,n=>jt(e,"generic",n,{type:t}))(s,o),r&&Rt(e,n,t)))});break}}}function Ut(e,t,n){switch(t){case tt.Consent:return n||e.consent;case tt.Session:return e.session;case tt.User:return n||e.user;case tt.Custom:return n||e.custom;case tt.Globals:return n||e.globals;case tt.Config:return n||e.config;default:return}}async function Ft(e,t,n,o,s){if(!t.on)return!1;if(Mt(o)&&!Ht(e,t,o))return!1;if(Mt(o)&&!Gt(e,t,o))return!1;const r=await oe(t.on,t=>jt(e,"source",t,{sourceId:n,type:o}))(o,s);return Mt(o)&&Rt(e,t,o),!1===r}function Lt(e){return"number"==typeof e&&e>0?e:1e4}var Kt=class extends Error{constructor(e){super(e),this.name="DestinationTimeoutError"}};function Qt(e,t,n){let o;const s=new Promise((e,s)=>{o=setTimeout(()=>s(new Kt(n)),t)});return Promise.race([e,s]).finally(()=>{o&&clearTimeout(o)})}var Jt=Object.freeze({batched:!0});function Wt(e){return e===Jt}function Vt(e){return void 0===e?{}:"number"==typeof e?{wait:e}:{wait:e.wait,size:e.size,age:e.age}}function Yt(e,t,n){if(!e)return[];if(Array.isArray(e)&&e.every(e=>"string"==typeof e))return yt(e,t);if("string"==typeof e)return yt(e,t);const o=U(e,M(n));return 0===o.length?[]:1===o.length?yt(o[0],t):yt(o,t)}async function Xt(e,t,n={},o){const{allowed:s,consent:r,globals:i,user:a}=e;if(!s)return tn({ok:!1});if(t){const n=e.config.queueMax;if(void 0===n)throw new Error("Collector.Config.queueMax is undefined; defaults must be seeded by collector()");const o=ot(e.queue,t,{max:n});if(o.dropped>0){const t=dt(e.status,J("collector"),"queue",o.dropped);rt(e.queue,e.logger,"collector.queue overflow; oldest events dropped",{buffer:"queue",cap:n,droppedCount:t})}else e.queue.length<n&&it(e.queue);e.status.in++}o||(o=e.destinations);const c=e.transformers?ht(e.transformers):{},u=await Promise.all(Object.entries(o||{}).map(async([o,s])=>{if(s.config.disabled)return{id:o,destination:s,skipped:!0};const u=s.config.id||o,l=J("destination",u),d=ct(s.config.breaker);if(d&&function(e,t,n){const o=e[t];if(!o||"closed"===o.state)return!1;if("half-open"===o.state)return!0===o.probing;const s=at();return void 0!==o.openUntil&&s<o.openUntil||(o.state="half-open",o.probing=!0,o.openUntil=s+n,!1)}(e.status.breakers,l,d.cooldown))return{id:o,destination:s,skipped:!0};const f=t=>{d&&ut(e.status.breakers,l,t,d.threshold,d.cooldown)},p=()=>{d&&function(e,t){const n=e[t];n&&"half-open"===n.state&&!0===n.probing&&(n.state="open",n.probing=!1)}(e.status.breakers,l)};let g=(s.queuePush||[]).map(e=>({...e,consent:r}));s.queuePush=[],t&&g.push(P(t));const h=n.ingest?{...n.ingest,_meta:{...n.ingest._meta,path:[...n.ingest._meta.path]}}:H("unknown");if(!g.length&&!s.queueOn?.length)return p(),{id:o,destination:s,skipped:!0};if(!g.length&&s.queueOn?.length){if(!B(s.config.consent,r))return p(),{id:o,destination:s,skipped:!0};let t=!1;try{t=await Zt(e,s,o,!0)}catch(t){e.status.failed++;const n=s.type||"unknown";e.logger.scope(n).error("destination init failed",{error:t instanceof Error?t.message:String(t)}),f("transport-failure")}return p(),{id:o,destination:s,skipped:!t}}const m=[],y=g.filter(t=>{const n=B(s.config.consent,r,t.consent);if(n)return t.consent=n,m.push(t),!1;const i=nt(e,{stepId:J("destination",o),stepType:"destination",phase:"skip",eventId:"string"==typeof t.id?t.id:"",now:Date.now()});return i.skipReason="consent",r&&(i.consent={...r}),s.config.consent&&(i.meta={required:{...s.config.consent}}),N(e,i),!0});if(y.length>0){const t=s.queuePush,n=s.config.id||o,r={max:s.config.queueMax??1e3};let i=0;for(const e of y)i+=ot(t,e,r).dropped;if(i>0){lt(e,n);const o=dt(e.status,J("destination",n),"queue",i);rt(t,e.logger.scope(s.type||"unknown"),"destination.queuePush overflow; oldest events dropped",{buffer:"queuePush",destination:n,cap:r.max,droppedCount:o})}else t.length<r.max&&it(t)}if(!m.length)return p(),{id:o,destination:s,queue:g};let v,w,b=!1;try{b=await Zt(e,s,o,!0)}catch(t){e.status.failed++;const n=s.type||"unknown";e.logger.scope(n).error("destination init failed",{error:t instanceof Error?t.message:String(t)}),f("transport-failure")}if(!b)return p(),{id:o,destination:s,queue:g};s.dlq||(s.dlq=[]);const k=Yt(s.config.before,c,h),S=s.config.next,q=s.config?.cache,I=q?$(q):void 0,x=I?pt(I,e):void 0,O=s.config?.state?Y(s.config.state):void 0,C=O?.filter(e=>"get"===e.mode),E=O?.filter(e=>"set"===e.mode);let D=0,T=0;return await Promise.all(m.map(async t=>{let r;if(t.globals=A(i,t.globals),t.user=A(a,t.user),I?.stop&&x){const e=M(h,t),n=await _(I,x,e);if("HIT"===n?.status)return t;"MISS"===n?.status&&(r={key:n.key,ttl:n.rule.ttl})}let u=t,l=n.respond;if(k.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const s=await kt(e,e.transformers,k,t,h,n.respond,`destination.${o}.before`);if(null===s.event)return t;s.respond&&(l=s.respond),u=Array.isArray(s.event)?s.event[0]:s.event}if(I&&!I.stop&&x){const e=M(h,u),n=await _(I,x,e);if("HIT"===n?.status)return t;"MISS"===n?.status&&(r={key:n.key,ttl:n.rule.ttl})}C&&C.length>0&&u&&(u=await X(C,t=>gt(t,e),u,e));const d=Date.now();let f=!1;const p=await W(en,t=>{const n=s.type||"unknown";e.logger.scope(n).error("Push failed",{error:t,event:u.name}),v=t,f=!0;const r=s.dlq,i=s.config.id||o,a={max:s.config.dlqMax??100},c=ot(r,[u,t],a);if(c.dropped>0){lt(e,i);const t=dt(e.status,J("destination",i),"dlq",c.dropped);rt(r,e.logger.scope(s.type||"unknown"),"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:i,cap:a.max,droppedCount:t})}else r.length<a.max&&it(r)})(e,s,o,u,h,l);if(D+=Date.now()-d,r&&x&&void 0===s.config.mock&&R(x,r.key,p??!0,r.ttl),!f&&!Wt(p)&&E&&E.length>0&&u&&(u=await X(E,t=>gt(t,e),u,e)),void 0===p||Wt(p)||(w=p),Wt(p)&&T++,!f&&S){void 0!==p&&(h._response=p);const t=Yt(S,c,h);if(t.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const n=await kt(e,e.transformers,t,u,h,l,`destination.${o}.next`);n.respond&&(l=n.respond)}}return t})),{id:o,destination:s,error:v,response:w,totalDuration:D,batchedCount:T,allowedCount:m.length,canonicalId:u,breakerConfig:d}})),l={},d={},f={};for(const t of u){if(t.skipped)continue;const n=t.destination,o={type:n.type||"unknown",data:t.response};lt(e,t.id);const s=e.status.destinations[t.id],r=Date.now();s.queuePushSize=n.queuePush?.length??0,s.dlqSize=n.dlq?.length??0;const i=t.breakerConfig,a=t.canonicalId?J("destination",t.canonicalId):void 0,c=t=>{i&&a&&ut(e.status.breakers,a,t,i.threshold,i.cooldown)};if(t.error)o.error=t.error,f[t.id]=o,s.failed++,s.lastAt=r,s.duration+=t.totalDuration||0,e.status.failed++,c("transport-failure");else if(t.queue&&t.queue.length)d[t.id]=o;else{const n=t.batchedCount??0,i=t.allowedCount??0;(Math.max(0,i-n)>0||0===i)&&(l[t.id]=o,s.count++,s.lastAt=r,s.duration+=t.totalDuration||0,e.status.out++,c("success"))}}return tn({event:t,...Object.keys(l).length&&{done:l},...Object.keys(d).length&&{queued:d},...Object.keys(f).length&&{failed:f}})}async function Zt(e,t,n,o=!1){if(t.init&&!t.config.init){if(!o&&function(e){const t=e.config.consent;return!!t&&Object.keys(t).length>0}(t))return e.logger.scope(t.type||"unknown").debug("init blocked: consent gate not cleared"),!1;const s=t.type||"unknown",r=e.logger.scope(s),i={collector:e,logger:r,id:n,config:t.config,env:on(t.env,t.config.env),reportError:ft(e,"destination",n,r,t)};r.debug("init");const a=Date.now();let c;N(e,nt(e,{stepId:J("destination",n),stepType:"destination",phase:"init",eventId:"",now:a}));try{c=await V(t.init,"DestinationInit",e.hooks,e.logger)(i)}catch(t){const o=Date.now(),s=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"error",eventId:"",now:o});throw s.durationMs=o-a,s.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},N(e,s),t}if(!1===c)return c;if(t.config={...c||t.config,init:!0},t.queueOn?.length){const o=t.queueOn;t.queueOn=[];for(const{type:s,data:r}of o)zt(e,t,n,s,r)}r.debug("init done")}return!0}async function en(e,t,n,o,s,r){const{config:i}=t,a=await Q(o,i,e);if(a.ignore)return!1;const c=t.type||"unknown",u=e.logger.scope(c),l={collector:e,logger:u,id:n,config:i,data:a.data,rule:a.mapping,ingest:s,env:{...on(t.env,i.env),...r?{respond:r}:{}},reportError:ft(e,"destination",n,u,t)};if(void 0!==i.mock)return u.debug("mock",{event:a.event.name}),i.mock;const d=a.mapping,f=void 0!==d?.batch,p=f?a.mappingKey||"* *":" batch-all";if((f||void 0!==i.batch)&&t.pushBatch&&void 0===i.mock){if(t.batches=t.batches||{},!t.batches[p]){const o={key:p,entries:[],events:[],data:[]},s=Vt(d?.batch),r=Vt(i.batch),a=s.wait??r.wait??3e4,c=s.size??r.size??1e3,l=s.age??r.age??3e4,g=on(t.env,i.env),h=G(async()=>{const o=t.batches[p],s=o.batched;if(0===s.entries.length)return;const r={key:s.key,entries:s.entries,events:s.events,data:s.data};s.entries=[],s.events=[],s.data=[];const a=r.entries[0],c={collector:e,logger:u,id:n,config:i,data:void 0,rule:o.isDefault?void 0:a.rule,ingest:a.ingest,env:{...g,...a.respond?{respond:a.respond}:{}},reportError:ft(e,"destination",n,u,t)};u.debug("push batch",{events:r.entries.length});const l=t.config.id||n,d=lt(e,l),f=ct(t.config.breaker),h=J("destination",l),m=t=>{f&&ut(e.status.breakers,h,t,f.threshold,f.cooldown)},y=Date.now(),v=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"flush",eventId:"",now:y});v.batch={size:r.entries.length,index:0},N(e,v);const w=n=>{const o=t.dlq=t.dlq||[],s={max:t.config.dlqMax??100};let r=0;for(const e of n)r+=ot(o,e,s).dropped;if(r>0){const t=dt(e.status,J("destination",l),"dlq",r);rt(o,u,"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:l,cap:s.max,droppedCount:t})}else o.length<s.max&&it(o);d.failed+=n.length,d.dlqSize=o.length,e.status.failed+=n.length};let b=r.entries.length;const k=Lt(i.timeout),S=await W((o,s)=>Qt(Promise.resolve(V(t.pushBatch,"DestinationPushBatch",e.hooks,e.logger)(o,s)),k,`Destination "${n}" batch delivery timed out after ${k}ms`),t=>{b=0;const o=Date.now(),s=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"error",eventId:"",now:o});s.durationMs=o-y,s.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},s.batch={size:r.entries.length,index:0},N(e,s),w(r.entries.map(e=>[e.event,t])),m("transport-failure"),u.error("Push batch failed",{error:t instanceof Error?t.message:String(t),entries:r.entries.length})})(r,c);if(K(q=S)&&Array.isArray(q.failed)&&S.failed.length>0){const e=[],t=new Set;for(const n of S.failed){const o=r.entries[n.index];o&&!t.has(n.index)&&(t.add(n.index),e.push([o.event,n.error??new Error(`Push batch entry ${n.index} failed (no per-row error provided)`)]))}e.length>0&&(w(e),b=Math.max(0,r.entries.length-e.length),u.error("Push batch partial failure",{failed:e.length,delivered:b,entries:r.entries.length}))}var q;u.debug("push batch done"),d.inFlightBatch=Math.max(0,(d.inFlightBatch??0)-r.entries.length),b>0&&(d.count+=b,d.lastAt=Date.now(),e.status.out+=b,m("success"))},{wait:a,size:c,age:l});t.batches[p]={batched:o,isDefault:!f,batchFn:()=>{h()},flush:async()=>{await h.flush()}}}const o=t.batches[p];o.batched.entries.push({event:a.event,ingest:s,respond:r,rule:d,data:a.data}),o.batched.events.push(a.event),F(a.data)&&o.batched.data.push(a.data);const c=t.config.id||n,l=lt(e,c);return l.inFlightBatch=(l.inFlightBatch??0)+1,o.batchFn(),Jt}{u.debug("push",{event:a.event.name});const o="string"==typeof a.event.id?a.event.id:"",s=Date.now(),r=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"in",eventId:o,now:s});a.mappingKey&&(r.mappingKey=a.mappingKey),a.event.consent&&(r.consent={...a.event.consent}),r.inEvent=a.event,N(e,r);try{const r=Lt(i.timeout),c=await Qt(Promise.resolve(V(t.push,"DestinationPush",e.hooks,e.logger)(a.event,l)),r,`Destination "${n}" delivery timed out after ${r}ms`),d=Date.now(),f=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"out",eventId:o,now:d});return f.durationMs=d-s,f.outEvent=a.event,F(c)&&(f.meta={...f.meta,response:c}),a.mappingKey&&(f.mappingKey=a.mappingKey),N(e,f),u.debug("push done"),c}catch(t){const r=Date.now(),i=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"error",eventId:o,now:r});throw i.durationMs=r-s,i.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},a.mappingKey&&(i.mappingKey=a.mappingKey),N(e,i),t}}}function tn(e){return{ok:!e?.failed,...e}}function nn(e){const{code:t,config:n={},env:o={},cache:s,state:r}=e,{config:i}=mt(e,"before"),{config:a}=mt({...e,config:i},"next"),c={...t.config,...n,...a};s&&(c.cache=s),void 0!==r&&void 0===c.state&&(c.state=r);const u=on(t.env,o);return{...t,config:c,env:u}}function on(e,t){return e||t?t?e&&K(e)&&K(t)?{...e,...t}:t:e:{}}async function sn(e,t,n){const o=Object.entries(e).map(async([e,o])=>{const s=o.destroy;if(!s)return;const r=o.type||"unknown",i=n.scope(r),a={id:e,config:o.config,env:o.env??{},logger:i};let c;try{await Promise.race([s(a),new Promise((n,o)=>{c=setTimeout(()=>o(new Error(`${t} '${e}' destroy timed out`)),5e3)})])}catch(n){i.error(`${t} '${e}' destroy failed: ${n}`)}finally{c&&clearTimeout(c)}});await Promise.allSettled(o)}function rn(e,t){e.stateVersion++,e.cellVersion[t]=e.stateVersion}async function an(e,t,n){let o,s,r=!1;const i=function(e){return e.cascade?()=>{}:(e.cascade={counts:new WeakMap},()=>{e.cascade=void 0})}(e);try{return await async function(){switch(t){case tt.Config:He(n)&&(Me(e.config,n,{shallow:!1}),s=n,r=!0);break;case tt.Consent:if(He(n)){const{update:t}=function(e,t){const n={};return Object.entries(t).forEach(([e,t])=>{n[e]=!!t}),e.consent=D(e.consent,n),{update:n}}(e,n);rn(e,tt.Consent),s=t,r=!0}break;case tt.Custom:He(n)&&(e.custom=Me(e.custom,n),rn(e,tt.Custom),s=n,r=!0);break;case tt.Destination:He(n)&&"code"in n&&He(n.code)&&(o=await async function(e,t){const{code:n,config:o={},env:s={},before:r,next:i,cache:a,state:c}=t;if(!L(n.push))return tn({ok:!1,failed:{invalid:{type:"invalid",error:"Destination code must have a push method"}}});const u=o||{init:!1};let l=r?{...u,before:r}:{...u};i&&(l={...l,next:i}),a&&(l={...l,cache:a}),void 0!==c&&void 0===l.state&&(l={...l,state:c});let d=l.id;if(!d)do{d=z(5,"abcdefghijklmnopqrstuvwxyz")}while(e.destinations[d]||e.pending.destinations[d]);if(l.require?.length){e.pending.destinations[d]=t,await Ct(e);const n=e.destinations[d];return n?Xt(e,void 0,{},{[d]:n}):tn({ok:!0})}const f={...n,config:l,env:on(n.env,s)};return e.destinations[d]=f,!1!==f.config.queue&&(f.queuePush=[...e.queue]),Xt(e,void 0,{},{[d]:f})}(e,n));break;case tt.Globals:He(n)&&(e.globals=Me(e.globals,n),rn(e,tt.Globals),s=n,r=!0);break;case tt.Hook:if(He(n)&&Re(n.name)&&_e(n.fn)){const{name:t,fn:o}=n;e.hooks[t]=o,s=n,r=!0}break;case tt.On:if(He(n)&&Re(n.type)){const{type:t,rules:o}=n;await async function(e,t,n){if(!Et(e))return void Tt();const o=e.on,s=o[t]||[],r=ee(n)?n:[n];r.forEach(e=>{s.push(e)}),o[t]=s,Bt(e,t,r)}(e,t,o)}break;case tt.Ready:r=!0;break;case tt.Run:o=await async function(e,t){return e.allowed=!0,e.timing=Date.now(),e.trace=$e(),e.count=0,t&&(t.consent&&(e.consent=Me(e.consent,t.consent),rn(e,tt.Consent)),t.user&&(e.user=Me(e.user,t.user),rn(e,tt.User)),t.globals&&(e.globals=Me(e.config.globalsStatic||{},t.globals),rn(e,tt.Globals)),t.custom&&(e.custom=Me(e.custom,t.custom),rn(e,tt.Custom))),Object.values(e.destinations).forEach(e=>{e.queuePush=[]}),e.queue=[],e.round++,await Ct(e),await async function(e){if(Et(e))for(const t of At){if(!Pt(e,t))continue;const n=Ut(e,t);Bt(e,t,e.on[t]||[]);for(const[o,s]of Object.entries(e.sources))xt(s)&&await Ft(e,s,o,t,n)}else Tt()}(e),await Xt(e)}(e,n),r=!0;break;case tt.Session:r=!0;break;case tt.Shutdown:e.hasShutdown||(e.hasShutdown=!0,await async function(e){const t=e.logger;await sn(e.sources,"source",t),await async function(e,t){const n=Object.entries(e).flatMap(([e,n])=>{const o=n.batches;if(!o)return[];const s=t.scope(n.type||"destination");return Object.values(o).map(async t=>{let n;try{await Promise.race([t.flush(),new Promise((t,o)=>{n=setTimeout(()=>o(new Error(`destination '${e}' batch flush timed out`)),5e3)})])}catch(t){s.error(`destination '${e}' batch flush failed: ${t}`)}finally{n&&clearTimeout(n)}})});await Promise.allSettled(n)}(e.destinations,t),await sn(e.destinations,"destination",t),await sn(e.transformers,"transformer",t),await sn(e.stores,"store",t)}(e));break;case tt.User:He(n)&&(Me(e.user,n,{shallow:!1}),rn(e,tt.User),s=n,r=!0)}return r&&(await async function(e,t,n,o){if(!Et(e))return Tt(),!0;e.seenEvents.add(String(t));let s=n||[];n||(s=e.on[t]||[]);const r=Ut(e,t,o);let i=!1;for(const[n,o]of Object.entries(e.sources)){if(o.config.require?.length){const e=o.config.require.indexOf(t);-1!==e&&o.config.require.splice(e,1)}o.on&&(xt(o)?await Ft(e,o,n,t,r)&&(i=!0):(o.queueOn=o.queueOn||[],o.queueOn.push({type:t,data:r})))}Object.entries(e.destinations).forEach(([n,o])=>{if(o.on){if(!o.config.init)return o.queueOn=o.queueOn||[],void o.queueOn.push({type:t,data:r});zt(e,o,n,t,r)}});for(const[t,n]of Object.entries(e.sources))xt(n)&&n.queueOn?.length&&await It(e,n,t);const a=Object.values(e.sources).some(e=>!xt(e)&&e.config.require?.length);return(Object.keys(e.pending.destinations).length>0||a)&&await Ct(e),Bt(e,t,s,o),!i}(e,t,void 0,s),o=await Xt(e)),o||tn({ok:!0})}()}finally{i()}}function cn(e,t){return{timing:Math.round((Date.now()-e.timing)/10)/100,source:{type:"collector",schema:"4",version:"4.2.1-next-1781715165983"},...t}}function un(e,t){if(!t.name)throw new Error("Event name is required");const[n,o]=t.name.split(" ");if(!n||!o)throw new Error("Event name is invalid");const{timestamp:s=Date.now(),name:r=`${n} ${o}`,data:i={},context:a={},globals:c=e.globals,custom:u={},user:l=e.user,nested:d=[],consent:f=e.consent,id:p=Pe(),trigger:g="",entity:h=n,action:m=o,timing:y=0,source:v={type:"collector",schema:"4"}}=t,w=v.count??(e.count+=1),b=v.trace??e.trace,k={...v,count:w};return void 0!==b&&(k.trace=b),{name:r,data:i,context:a,globals:c,custom:u,user:l,nested:d,consent:f,id:p,trigger:g,entity:h,action:m,timestamp:s,timing:y,source:k}}function ln(e,t){const n=Le(async(n,o={})=>await Fe(async()=>{const s=Date.now(),{id:r,ingest:i,respond:a,mapping:c,preChain:u,include:l,exclude:d}=o;let f=a,p=n;const g=l||d?function(e,t,n){let o=e;return t&&(o=Object.fromEntries(Object.entries(o).filter(([e])=>t.includes(e)))),n&&(o=Object.fromEntries(Object.entries(o).filter(([e])=>!n.includes(e)))),o}(e.destinations,l,d):void 0,h=i??Ge(r||"unknown");if(c){const t=await Ue(p,c,e);if(t.ignore)return tn({ok:!0});if(c.consent&&!Be(c.consent,e.consent,t.event.consent))return tn({ok:!0});p=t.event}if(u?.length&&e.transformers&&Object.keys(e.transformers).length>0){const n=await kt(e,e.transformers,u,p,h,f,r?`source.${r}.next`:void 0);if(null===n.event)return tn({ok:!0});if(n.stopped)return n.respond&&(f=n.respond),tn({ok:!0});if(n.respond&&(f=n.respond),Array.isArray(n.event)){const o=await Promise.all(n.event.map(async n=>{const o=t(n),s=un(e,o);return Xt(e,s,{id:r,ingest:h,respond:f},g)}));if(r){e.status.sources[r]||(e.status.sources[r]={count:0,duration:0});const t=e.status.sources[r];t.count+=n.event.length,t.lastAt=Date.now(),t.duration+=Date.now()-s}return o[0]??tn({ok:!0})}p=n.event}const m=function(e,t){return un(e,cn(e,t))}(e,p),y=await Xt(e,m,{id:r,ingest:h,respond:f},g);if(r){e.status.sources[r]||(e.status.sources[r]={count:0,duration:0});const t=e.status.sources[r];t.count++,t.lastAt=Date.now(),t.duration+=Date.now()-s}return y},t=>{if(t instanceof ze)throw t;return e.status.failed++,e.logger.error("push failed",{event:n,ingest:o.ingest,error:t}),tn({ok:!1})})(),"Push",e.hooks,e.logger);return async(t,o)=>{const s="string"==typeof t.id?t.id:"",r=Date.now(),i=nt(e,{stepId:"collector.push",stepType:"collector",phase:"in",eventId:s,now:r});i.inEvent=t,Ne(e,i);try{const i=await n(t,o),a=Date.now(),c=nt(e,{stepId:"collector.push",stepType:"collector",phase:"out",eventId:s,now:a});return c.durationMs=a-r,c.outEvent=i,Ne(e,c),i}catch(t){const n=Date.now(),o=nt(e,{stepId:"collector.push",stepType:"collector",phase:"error",eventId:s,now:n});throw o.durationMs=n-r,o.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},Ne(e,o),t}}}function dn(e={}){const t=e.maxEntries??1e4,n=e.lowWaterMark??.8,o=e.sweepIntervalMs??6e4,s=Math.floor(t*n),r=new Map,i={hits:0,misses:0,populates:0,writes:0,deletes:0,evictions_entries:0,evictions_ttl:0};let a;return o>0&&(a=setInterval(function(){const e=Date.now();let t=0;for(const[n,o]of r)void 0!==o.expires&&o.expires<=e&&(r.delete(n),t++);i.evictions_ttl+=t},o),a&&"function"==typeof a.unref&&a.unref()),{type:"memory",config:{},get(e){const t=r.get(e);if(t)return void 0!==t.expires&&t.expires<=Date.now()?(r.delete(e),i.evictions_ttl++,void i.misses++):(r.delete(e),r.set(e,t),i.hits++,t.value);i.misses++},set(e,n,o){const a=!r.has(e);a||r.delete(e),r.set(e,{value:n,expires:void 0!==o?Date.now()+o:void 0}),i.writes++,a&&i.populates++,r.size>t&&function(){if(r.size<=t)return;const e=r.size-s;let n=0;for(const t of r.keys()){if(n>=e)break;r.delete(t),n++}i.evictions_entries+=n}()},delete(e){r.delete(e)&&i.deletes++},get counters(){return{...i}},destroy(){void 0!==a&&(clearInterval(a),a=void 0),r.clear()}}}function fn(e,t){const{cacheConfig:n,cacheStore:o,namespace:s,logger:r,storeId:i,collector:a}=t,c=(e,t)=>{if(!a)return;const n=nt(a,{stepId:`store.${i}`,stepType:"store",phase:"in",eventId:"",now:Date.now()});n.meta={op:"cache",cached:"hit"===t,status:t,key:e},Xe(a,n)},u={hits:0,misses:0,populates:0,writes:0,deletes:0,inflight_dedups:0},l=n.rules.map(e=>({match:e.match?Ye(e.match):()=>!0,ttl:e.ttl})),d=e=>`${s}:${e}`;function f(e,t){const n=void 0===t?{key:e}:{key:e,value:t};return l.find(e=>e.match(n))}const p=new Map;return{type:e.type,config:e.config,setup:e.setup,get counters(){return{...u}},async get(t){const n=d(t),s=await o.get(n),r=Ze(s);if(void 0!==r){if(!("expired"in r))return u.hits++,c(t,"hit"),r.value;try{await o.delete(n)}catch(e){g("delete",t,e)}}const i=p.get(n);if(i)return u.inflight_dedups++,c(t,"hit"),i;u.misses++,c(t,"miss");const a=(async()=>{try{const s=await e.get(t);if(void 0===s)return;const r=f(t,s);if(r)try{const e=1e3*r.ttl;await o.set(n,et(s,e),e),u.populates++}catch(e){g("set",t,e)}return s}finally{p.delete(n)}})();return p.set(n,a),a},async set(t,n,s){u.writes++,await e.set(t,n,s);const r=f(t,n);if(r)try{const e=1e3*r.ttl;await o.set(d(t),et(n,e),e)}catch(e){g("set",t,e)}},async delete(t){u.deletes++,await e.delete(t);try{await o.delete(d(t))}catch(e){g("delete",t,e)}}};function g(e,t,n){const o=`store-cache(${i}): cache ${e} failed for "${t}"; backing succeeded, continuing`;r?r.warn(o,{error:n}):console.warn(o,n)}}function pn(e,t,n){const o=`store.${n}`,s=Ve(t.get,"StoreGet",e.hooks,e.logger),r=Ve(t.set,"StoreSet",e.hooks,e.logger),i=Ve(t.delete,"StoreDelete",e.hooks,e.logger);t.get=async t=>{const n=Date.now(),r=nt(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:n});r.meta={op:"get",key:t},We(e,r);try{const r=await s(t),i=Date.now(),a=nt(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:i});return a.durationMs=i-n,a.meta={op:"get",key:t},We(e,a),r}catch(s){const r=Date.now(),i=nt(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:r});throw i.durationMs=r-n,i.meta={op:"get",key:t},i.error=s instanceof Error?{name:s.name,message:s.message}:{message:String(s)},We(e,i),s}},t.set=async(t,n,s)=>{const i=Date.now(),a=nt(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:i});a.meta={op:"set",key:t},We(e,a);try{await r(t,n,s);const a=Date.now(),c=nt(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:a});c.durationMs=a-i,c.meta={op:"set",key:t},We(e,c)}catch(n){const s=Date.now(),r=nt(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:s});throw r.durationMs=s-i,r.meta={op:"set",key:t},r.error=n instanceof Error?{name:n.name,message:n.message}:{message:String(n)},We(e,r),n}},t.delete=async t=>{const n=Date.now(),s=nt(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:n});s.meta={op:"delete",key:t},We(e,s);try{await i(t);const s=Date.now(),r=nt(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:s});r.durationMs=s-n,r.meta={op:"delete",key:t},We(e,r)}catch(s){const r=Date.now(),i=nt(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:r});throw i.durationMs=r-n,i.meta={op:"delete",key:t},i.error=s instanceof Error?{name:s.name,message:s.message}:{message:String(s)},We(e,i),s}}}async function gn(e){const t=T({globalsStatic:{},sessionStatic:{},run:!0,queueMax:1e3},e,{merge:!1,extend:!1}),n={level:e.logger?.level,handler:e.logger?.handler},o=j(n),s={...t.globalsStatic,...e.globals},r={allowed:!1,config:t,consent:e.consent||{},custom:e.custom||{},destinations:{},transformers:{},stores:{},globals:s,hooks:e.hooks||{},observers:new Set,logger:o,on:{},queue:[],round:0,count:0,stateVersion:0,cellVersion:{},delivery:new WeakMap,session:void 0,status:{startedAt:Date.now(),in:0,out:0,failed:0,sources:{},destinations:{},dropped:{},connectionErrors:{},breakers:{}},timing:Date.now(),user:e.user||{},sources:{},pending:{destinations:{}},hasShutdown:!1,seenEvents:new Set,push:void 0,command:void 0};var i,a;r.push=ln(r,e=>cn(r,e)),r.command=(a=an,Qe(async(e,t,n)=>await Je(async()=>await a(i,e,t,n),n=>{if(n instanceof Ke)throw n;return i.status.failed++,i.logger.error("command failed",{command:e,data:t,error:n}),tn({ok:!1})})(),"Command",(i=r).hooks,i.logger));const c=e.stores||{};return r.stores=await async function(e,t={}){const n={};for(const[o,s]of Object.entries(t)){const{code:t,config:r={},env:i={}}=s,a=e.logger.scope("store").scope(o),c={collector:e,logger:a,id:o,config:r,env:i,reportError:ft(e,"store",o,a)},u=await t(c);n[o]=u}const o=t,s=function(e){const t={};for(const n of Object.keys(e))t[n]="WHITE";const n=[],o=[];function s(r){const i=t[r];if("BLACK"===i)return;if("GRAY"===i){const e=o.indexOf(r),t=o.slice(-1===e?0:e).concat(r).join(" -> ");throw new Error(`Cycle in cache.store chain: ${t}`)}t[r]="GRAY",o.push(r);const a=e[r].cache?.store;if(void 0!==a){if(!(a in e))throw new Error(`Store "${r}" cache.store references "${a}", which is not declared in flow.stores`);s(a)}o.pop(),t[r]="BLACK",n.push(r)}for(const n of Object.keys(e))"WHITE"===t[n]&&s(n);return n}(o);for(const t of s){const s=o[t].cache;if(!s)continue;let r,i;void 0!==s.store?(r=n[s.store],i=s.store):(n.__cache||(n.__cache=dn()),r=n.__cache,i="__cache");const a=s.namespace??t;e.logger.scope("store-cache").scope(t).info(`store "${t}" caches with namespace "${a}:" via ${i}`),n[t]=fn(n[t],{storeId:t,cacheConfig:s,cacheStore:r,namespace:a,logger:e.logger.scope("store-cache").scope(t),collector:e})}for(const[t,o]of Object.entries(n))"__cache"!==t&&pn(e,o,t);return n}(r,c),function(e,t,n){const o=new Map;for(const[n,s]of Object.entries(e))t[n]&&o.set(s,t[n]);if(0!==o.size)for(const e of[n.transformers,n.destinations,n.sources])if(e)for(const t of Object.values(e))s(t.env);function s(e){if(e)for(const[t,n]of Object.entries(e))if("object"==typeof n&&null!==n){const s=o.get(n);s&&(e[t]=s)}}}(c,r.stores,e),r.stores.__cache||(r.stores.__cache=dn()),r.destinations=await async function(e,t={}){const n={};for(const[o,s]of Object.entries(t))s.config?.require?.length?e.pending.destinations[o]=s:n[o]=nn(s);return n}(r,e.destinations||{}),r.transformers=await async function(e,t={}){const n={};for(const[o,s]of Object.entries(t)){const{code:t,env:r={}}=s,i=De(s,"Transformer");if(!i.ok){e.logger.warn(`Transformer ${o} invalid (${i.code}): ${i.reason}. Skipping.`);continue}const{config:a}=mt(s,"before"),{config:c}=mt({...s,config:a},"next"),u=Object.keys(r).length>0?{...c,env:r}:c,{cache:l}=s,d=l?{...u,cache:l}:u,f=s.config?.state??s.state,p=void 0!==f&&void 0===d.state?{...d,state:f}:d,g=e.logger.scope("transformer").scope(o),h={collector:e,logger:g,id:o,ingest:ye(o),config:p,env:r,reportError:ft(e,"transformer",o,g)},m=t??(e=>{const t=s.mapping;if(t){const n=[];if(void 0!==t.data&&n.push("data"),t.mapping)for(const[e,o]of Object.entries(t.mapping))if("object"==typeof o&&null!==o)for(const[t,s]of Object.entries(o)){if("object"!=typeof s||null===s)continue;const o=s;void 0!==o.data&&n.push(`mapping[${e}][${t}].data`),void 0!==o.silent&&n.push(`mapping[${e}][${t}].silent`)}return n.length>0&&e.collector.logger.warn(`Transformer ${o}: \`${n.join(", ")}\` ignored at transformer position (only event-mutating fields apply).`),{type:"pass",config:e.config,push:async n=>{const o=await Te(n,t,e.collector);return!o.ignore&&{event:o.event}}}}return{type:"pass",config:e.config,push:e=>({event:e})}}),y=await m(h);void 0!==s.before&&void 0===y.config?.before&&(y.config={...y.config??{},before:s.before}),void 0!==s.next&&void 0===y.config?.next&&(y.config={...y.config??{},next:s.next}),void 0!==f&&void 0===y.config?.state&&(y.config={...y.config??{},state:f}),n[o]=y}return n}(r,e.transformers||{}),r}async function hn(e){e=e||{};const t=await gn(e),n=(o=t,{type:"elb",config:{},push:async(e,t,n,s,r)=>{if("string"==typeof e&&e.startsWith("walker ")){const n=e.replace("walker ","");return o.command(n,t)}let i;if("string"==typeof e)i={name:e},t&&"object"==typeof t&&!Array.isArray(t)&&(i.data=t);else{if(!e||"object"!=typeof e)return tn({ok:!1});i=e,t&&"object"==typeof t&&!Array.isArray(t)&&(i.data={...i.data||{},...t})}return n&&"object"==typeof n&&(i.context=n),s&&Array.isArray(s)&&(i.nested=s),r&&"object"==typeof r&&(i.custom=r),o.push(i)}});var o;t.sources.elb=n,await async function(e,t={}){const n={};for(const[o,s]of Object.entries(t)){const t=await Ot(e,o,s);if(!t)continue;const r=s.config?.require;t.config={...t.config,init:!1,...r?{require:[...r]}:{}},n[o]=t}Object.assign(e.sources,n);for(const t of Object.keys(n)){const n=e.sources[t];let o=!1;n.init&&await ce(n.init.bind(n),n=>{if(n instanceof ie)throw n;o=!0,e.status.failed++,e.logger.scope("source").error("source init failed",{sourceId:t,error:n})})(),o||(n.config.init=!0,xt(n)&&await It(e,n,t))}return await Ct(e),n}(t,e.sources||{});const{consent:s,user:r,globals:i,custom:a}=e;s&&await t.command("consent",s),r&&await t.command("user",r),i&&await t.command("globals",i),a&&await t.command("custom",a),t.config.run&&await t.command("run");let c=n.push;const u=Object.values(t.sources).filter(e=>"elb"!==e.type),l=u.find(e=>e.config.primary);return l?c=l.push:u.length>0&&(c=u[0].push),{collector:t,elb:c}}var mn=async e=>{let t;return{get flow(){return t},trigger:()=>async n=>{if(!t){const n=await hn(e);t={collector:n.collector,elb:n.elb}}const o=function(e){for(const t of Object.values(e.sources||{}))if("lambda"===t.type)return t}(t.collector);if(!o)throw new Error("Lambda source not found in collector");const s={awsRequestId:`test-${Date.now()}`},r=o.push,i=await r(n,s);let a;try{a=JSON.parse(i.body||"{}")}catch{a=i.body}const c={};if(i.headers)for(const[e,t]of Object.entries(i.headers))void 0!==t&&(c[e]=String(t));return{statusCode:i.statusCode,body:a,headers:c}}}};function yn(e){return async t=>{const n={...t};if(n.body&&"string"==typeof n.body){const e=JSON.parse(n.body);e.name&&!e.event&&(n.body=JSON.stringify({...e,event:e.name,name:void 0}))}return e.push(n,{awsRequestId:"test-req"})}}var vn={};t(vn,{createTrigger:()=>jn,env:()=>wn,step:()=>xn});var wn={};t(wn,{push:()=>qn,simulation:()=>In});var bn=()=>{},kn={error:bn,warn:bn,info:bn,debug:bn,throw:e=>{throw"string"==typeof e?new Error(e):e},json:bn,scope:()=>kn},Sn=()=>()=>Promise.resolve({ok:!0}),qn={get push(){return Sn()},get command(){return Sn()},get elb(){return Sn()},logger:kn},In=["AWS.SQSClient"],xn={};t(xn,{decoderText:()=>En,malformedJson:()=>Dn,orderComplete:()=>Cn,pageView:()=>On});var On={title:"Page view from SQS",description:"A standard SQS message body containing a walker elb event payload as JSON.",in:{MessageId:"m-1",Body:JSON.stringify({event:"page view",data:{title:"Documentation",url:"https://example.com/docs"}})},out:[["message.ack","m-1"]]},Cn={title:"Order complete from SQS",description:"Order complete event flowing through the long-poll loop.",in:{MessageId:"m-2",Body:JSON.stringify({event:"order complete",data:{id:"ORD-500",total:199.99,currency:"EUR"}})},out:[["message.ack","m-2"]]},En={title:"Text decoder",description:'When decoder is "text", the body string flows under data.payload.',in:{MessageId:"m-3",Body:"raw text payload"},out:[["message.ack","m-3"]]},Dn={title:"Malformed JSON nacks",description:"Default decoder is JSON. A malformed body throws DecoderError; the source nacks (skips DeleteMessage) so the message redelivers.",in:{MessageId:"m-4",Body:"{not json"},out:[["message.nack","m-4"]]};function Tn(e){if("object"!=typeof e||null===e)return!1;const t=e;return"sqs"===t.type&&"function"==typeof t.push}var jn=async e=>{let t;return{get flow(){return t},trigger:()=>async n=>{if(!t){const n=await hn(e);t={collector:n.collector,elb:n.elb}}const o=function(e){for(const t of Object.values(e.sources??{}))if(Tn(t))return t}(t.collector);if(!o)throw new Error("sqs source not registered in collector, ensure it is configured in sources");const s={MessageId:n.MessageId,Body:n.Body,ReceiptHandle:n.ReceiptHandle,Attributes:n.Attributes,MessageAttributes:n.MessageAttributes},r=await o.push(s),i=[];return r&&"object"==typeof r&&(r.acked&&i.push(["message.ack",n.MessageId]),r.nacked&&i.push(["message.nack",n.MessageId])),i}}};export{w as examples,n as schemas,vn as sqsExamples};//# sourceMappingURL=dev.mjs.map
|
|
1
|
+
var e=Object.defineProperty,t=(t,n)=>{for(var o in n)e(t,o,{get:n[o],enumerable:!0})},n={};t(n,{CorsOptionsSchema:()=>c,CorsOrigin:()=>a,HttpMethod:()=>i,SettingsSchema:()=>u,settings:()=>l,sqsSettings:()=>y,sqsSetup:()=>v});import{zodToSchema as o}from"@walkeros/core/dev";import{z as s}from"@walkeros/core/dev";import{z as r}from"@walkeros/core/dev";var i=r.enum(["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"]),a=r.union([r.string(),r.array(r.string()),r.literal("*")]),c=r.object({origin:a.describe("Allowed origins (* for all, URL string, or array of URLs)").optional(),methods:r.array(i).describe("Allowed HTTP methods").optional(),headers:r.array(r.string()).describe("Allowed request headers").optional(),credentials:r.boolean().describe("Allow credentials (cookies, authorization headers)").optional(),maxAge:r.number().int().positive().describe("Preflight cache duration in seconds").optional()}),u=s.object({cors:s.union([s.boolean(),c]).describe("CORS configuration: false = disabled, true = allow all origins, object = custom configuration").default(!0),timeout:s.number().int().positive().max(9e5).describe("Request timeout in milliseconds (max: 900000 for Lambda)").default(3e4),enablePixelTracking:s.boolean().describe("Enable GET requests with 1x1 transparent GIF response for pixel tracking").default(!0),healthPath:s.string().describe("Health check endpoint path (e.g., /health)").default("/health")}),l=o(u);import{zodToSchema as d}from"@walkeros/core/dev";import{z as f}from"@walkeros/core/dev";var p=f.object({queueName:f.string().min(1).describe("SQS queue short name (like walkeros-events). Required for both setup and runtime poll."),region:f.string().describe("AWS region (like eu-central-1). Default: eu-central-1.").optional(),queueUrl:f.string().url().describe("Optional pre-resolved queue URL. When set, init skips the GetQueueUrl lookup.").optional(),client:f.any().describe("Pre-configured AWS SQSClient instance. Bypasses construction when supplied.").optional(),config:f.any().describe("AWS SDK SQSClientConfig (credentials, endpoint overrides, retries).").optional(),decoder:f.enum(["json","text","raw"]).describe("Decoder for the message body. json (default) parses JSON, text forwards UTF-8, raw forwards a Buffer.").optional(),maxMessages:f.number().int().min(1).max(10).describe("SQS receive batch size. Cap 10. Default: 10.").optional(),waitTimeSeconds:f.number().int().min(0).max(20).describe("Long-poll duration in seconds. Cap 20. Default: 20.").optional(),visibilityTimeout:f.number().int().nonnegative().describe("Per-receive visibility timeout override. Default: queue-configured value.").optional(),shutdownTimeoutMs:f.number().int().positive().describe("Graceful shutdown timeout in milliseconds. Default: 30000. After this window, destroy() force-closes.").optional(),onPushError:f.enum(["nack","ack"]).describe("Behavior when forwarding to the collector throws. nack (default) skips DeleteMessage so the message redelivers; ack drops it.").optional()});import{z as g}from"@walkeros/core/dev";var h=g.record(g.string(),g.string()),m=g.object({region:g.string().min(1).describe("AWS region.").optional(),fifoQueue:g.boolean().describe("FIFO queue with content-based deduplication. Auto-appends .fifo suffix to the queue name.").optional(),visibilityTimeoutSeconds:g.number().int().nonnegative().describe("Visibility timeout in seconds. Default: 30.").optional(),messageRetentionSeconds:g.number().int().positive().describe("Message retention period in seconds. Default: 345600 (4 days).").optional(),maximumMessageSize:g.number().int().min(1024).max(262144).describe("Max message size in bytes. Default: 262144 (256 KB).").optional(),kmsMasterKeyId:g.string().describe("KMS key alias or ID for at-rest encryption.").optional(),deadLetterQueue:g.object({arn:g.string().describe("ARN of an existing DLQ. Mutually exclusive with create: true.").optional(),create:g.boolean().describe("Create a sibling DLQ named <queueName>-dlq. Default: false.").optional(),maxReceiveCount:g.number().int().min(1).max(1e3).describe("Max receive count before message goes to DLQ. Default: 5.").optional()}).describe("Optional dead-letter queue.").optional(),tags:h.describe("Tags applied to the queue (and inherited by an auto-created DLQ).").optional(),subscribeToSnsTopic:g.object({topicArn:g.string().min(1).describe("Topic ARN to subscribe to."),rawMessageDelivery:g.boolean().describe("Deliver SNS messages without the SNS envelope.").optional(),filterPolicy:g.record(g.string(),g.unknown()).describe("SNS filter policy applied at subscription level.").optional()}).describe("Optional SNS topic subscription. Creates the subscription and the matching queue policy.").optional()}),y=d(p),v=d(m),w={};t(w,{createTrigger:()=>mn,env:()=>b,step:()=>x,trigger:()=>yn});var b={};t(b,{push:()=>I});var k=()=>()=>Promise.resolve({ok:!0}),S=()=>{},q={error:S,warn:S,info:S,debug:S,throw:e=>{throw"string"==typeof e?new Error(e):e},json:S,scope:()=>q},I={get push(){return k()},get command(){return k()},get elb(){return k()},logger:q},x={};t(x,{apiGatewayV1Post:()=>C,lambdaGet:()=>E,lambdaPost:()=>O});var O={title:"Lambda POST",description:"An API Gateway v2 HTTP POST with a JSON body is converted into a walker elb event.",trigger:{type:"POST"},in:{version:"2.0",requestContext:{http:{method:"POST",path:"/collect"},requestId:"req-123"},body:JSON.stringify({event:"page view",data:{title:"Home"}}),isBase64Encoded:!1},out:[["elb",{name:"page view",data:{title:"Home"}}]]},C={title:"API Gateway v1 POST",description:"A REST API Gateway v1 POST request with a JSON body is converted into a walker elb event.",trigger:{type:"POST"},in:{httpMethod:"POST",path:"/collect",requestContext:{requestId:"req-789",identity:{sourceIp:"203.0.113.42"}},queryStringParameters:null,body:JSON.stringify({event:"page view",data:{title:"Home"}}),isBase64Encoded:!1},out:[["elb",{name:"page view",data:{title:"Home"}}]]},E={title:"Lambda GET",description:"An API Gateway v2 HTTP GET with query parameters is parsed into an elb event payload.",trigger:{type:"GET"},in:{version:"2.0",requestContext:{http:{method:"GET",path:"/collect"},requestId:"req-456"},rawQueryString:"e=page+view&d=%7B%22title%22%3A%22Home%22%7D",isBase64Encoded:!1},out:[["elb",{e:"page view",d:'{"title":"Home"}'}]]};import{assign as D}from"@walkeros/core";import{assign as T,createLogger as j}from"@walkeros/core";import{assign as A,buildCacheContext as M,clone as P,compileCache as $,checkCache as _,storeCache as R,createIngest as H,debounce as G,emitStep as N,getId as z,getGrantedConsent as B,getNextSteps as U,isDefined as F,isFunction as L,isObject as K,processEventMapping as Q,stepId as J,tryCatchAsync as W,useHooks as V,compileState as Y,applyState as X}from"@walkeros/core";import{emitStep as Z}from"@walkeros/core";import{isArray as ee,FatalError as te}from"@walkeros/core";import{tryCatch as ne,tryCatchAsync as oe}from"@walkeros/core";import{stepId as se}from"@walkeros/core";import{createIngest as re,FatalError as ie,getMappingValue as ae,tryCatchAsync as ce,getNextSteps as ue,compileCache as le,checkCache as de,storeCache as fe,applyUpdate as pe,buildCacheContext as ge,compileState as he,applyState as me}from"@walkeros/core";import{createIngest as ye,emitStep as ve,FatalError as we,isObject as be,stepId as ke,tryCatchAsync as Se,useHooks as qe,getNextSteps as Ie,compileCache as xe,checkCache as Oe,storeCache as Ce,buildCacheContext as Ee,validateStepEntry as De,processEventMapping as Te,compileState as je,applyState as Ae}from"@walkeros/core";import{assign as Me,getSpanId as Pe,getTraceId as $e,isFunction as _e,isString as Re}from"@walkeros/core";import{isObject as He}from"@walkeros/core";import{createIngest as Ge,emitStep as Ne,FatalError as ze,getGrantedConsent as Be,processEventMapping as Ue,tryCatchAsync as Fe,useHooks as Le}from"@walkeros/core";import{FatalError as Ke,useHooks as Qe,tryCatchAsync as Je}from"@walkeros/core";import{emitStep as We,useHooks as Ve}from"@walkeros/core";import{compileMatcher as Ye,emitStep as Xe,readCacheEnvelope as Ze,wrapCacheEnvelope as et}from"@walkeros/core";var tt={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",Scoped:"_",Session:"session",Shutdown:"shutdown",User:"user",Walker:"walker"};function nt(e,t){const n=e.status.startedAt;return{flowId:"default",stepId:t.stepId,stepType:t.stepType,phase:t.phase,eventId:t.eventId,timestamp:new Date(t.now).toISOString(),elapsedMs:t.now-n}}function ot(e,t,n,o){if(!Number.isFinite(n.max)||n.max<=0)throw new Error(`pushBounded: max must be > 0 (got ${n.max})`);if("dropNewest"===(n.onOverflow??"dropOldest"))return e.length>=n.max?(o&&o([t]),{appended:!1,dropped:1}):(e.push(t),{appended:!0,dropped:0});const s=[];for(;e.length>=n.max;)s.push(e.shift());return e.push(t),s.length>0&&o&&o(s),{appended:!0,dropped:s.length}}var st=new WeakMap;function rt(e,t,n,o){st.get(e)||(st.set(e,!0),t.warn(n,o))}function it(e){st.delete(e)}var at=()=>Date.now();function ct(e){if(void 0!==e)return"number"==typeof e?{threshold:e,cooldown:3e4}:{threshold:e.threshold??5,cooldown:e.cooldown??3e4}}function ut(e,t,n,o,s){if("partial"===n)return;const r=((i=e)[a=t]||(i[a]={state:"closed",consecutiveFailures:0}),i[a]);var i,a;return"success"===n?(r.consecutiveFailures=0,r.state="closed",r.probing=!1,void(r.openUntil=void 0)):(r.consecutiveFailures+=1,"half-open"===r.state?(r.state="open",r.probing=!1,void(r.openUntil=at()+s)):void(r.consecutiveFailures>=o&&(r.state="open",r.probing=!1,r.openUntil=at()+s)))}function lt(e,t){return e.status.destinations[t]||(e.status.destinations[t]={count:0,failed:0,duration:0,queuePushSize:0,dlqSize:0}),e.status.destinations[t]}function dt(e,t,n,o){e.dropped[t]||(e.dropped[t]={});const s=e.dropped[t];return s[n]=(s[n]??0)+o,s[n]}function ft(e,t,n,o,s){const r=se(t,n);return(t,i)=>{try{if(i)return s?function(e,t,n,o,s,r){const i=t.dlq=t.dlq||[],a={max:t.config.dlqMax??100},c=ot(i,[o,s],a);if(c.dropped>0){const t=dt(e.status,se("destination",n),"dlq",c.dropped);rt(i,r,"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:n,cap:a.max,droppedCount:t})}else i.length<a.max&&it(i);const u=lt(e,n);u.failed++,u.dlqSize=i.length,e.status.failed++;const l=ct(t.config.breaker);if(l){const o=t.config.id||n;ut(e.status.breakers,se("destination",o),"transport-failure",l.threshold,l.cooldown)}}(e,s,n,i,t,o):e.status.failed++,void o.error("report error",{error:t instanceof Error?t.message:String(t),event:i.name});e.status.connectionErrors[r]=(e.status.connectionErrors[r]??0)+1,o.error("connection error",{error:t instanceof Error?t.message:String(t)})}catch{}}}function pt(e,t){return e.storeId&&t.stores[e.storeId]?t.stores[e.storeId]:t.stores.__cache}function gt(e,t){return e?t.stores[e]:t.stores.__cache}function ht(e){const t={};for(const[n,o]of Object.entries(e)){const e=o.config?.next;"string"==typeof e||Array.isArray(e)&&e.every(e=>"string"==typeof e)?t[n]={next:e}:t[n]={}}return t}function mt(e,t){const n=e.config||{},o=e[t];return void 0!==o?{config:{...n,[t]:o},chainValue:o}:{config:n,chainValue:void 0}}function yt(e,t={}){if(!e)return[];if(Array.isArray(e))return e;const n=[],o=new Set;let s=e;for(;s&&t[s]&&!o.has(s);){o.add(s),n.push(s);const e=t[s].next;if(Array.isArray(e)){n.push(...e);break}s=e}return n}async function vt(e,t,n){if(t.init&&!t.config.init){const o=t.type||"unknown",s=e.logger.scope(`transformer:${o}`),r={collector:e,logger:s,id:n,ingest:ye(n),config:t.config,env:St(t.config.env),reportError:ft(e,"transformer",n,s)};s.debug("init");const i=await qe(t.init,"TransformerInit",e.hooks,e.logger)(r);if(!1===i)return!1;t.config={...i||t.config,env:i?.env||t.config.env,init:!0},s.debug("init done")}return!0}async function wt(e,t,n,o,s,r){const i=t.type||"unknown",a=e.logger.scope(`transformer:${i}`),c={collector:e,logger:a,id:n,ingest:s,config:t.config,env:{...St(t.config.env),...r?{respond:r}:{}},reportError:ft(e,"transformer",n,a)};a.debug("push",{event:o.name});const u="string"==typeof o.id?o.id:"",l=Date.now(),d=nt(e,{stepId:ke("transformer",n),stepType:"transformer",phase:"in",eventId:u,now:l});d.inEvent=o,ve(e,d);try{const s=await qe(t.push,"TransformerPush",e.hooks,e.logger)(o,c),r=Date.now(),i=nt(e,{stepId:ke("transformer",n),stepType:"transformer",phase:"out",eventId:u,now:r});return i.durationMs=r-l,i.outEvent=s,ve(e,i),a.debug("push done"),s}catch(t){const o=Date.now(),s=nt(e,{stepId:ke("transformer",n),stepType:"transformer",phase:"error",eventId:u,now:o});throw s.durationMs=o-l,s.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},ve(e,s),t}}function bt(e,t){return e?{...e,_meta:{...e._meta,path:[...e._meta.path]}}:ye(t)}async function kt(e,t,n,o,s,r,i){s||(s=ye(n[0]??"chain")),i&&s._meta&&(s._meta.chainPath=i);let a=o,c=r;for(const o of n){const r=t[o];if(!r){e.logger.warn(`Transformer not found: ${o}`);continue}if(s&&s._meta&&s._meta.path.length>256)return e.logger.error(`Max path length exceeded at ${o}`),{event:null,respond:c};if(s&&s._meta&&(s._meta.hops++,s._meta.path.push(o)),!await Se(vt,t=>{if(t instanceof we)throw t;return e.status.failed++,e.logger.scope(`transformer:${r.type||"unknown"}`).error("transformer init failed",{transformer:o,error:t}),!1})(e,r,o))return{event:null,respond:c};if(i&&void 0!==r.config?.chainMocks?.[i]){const t=r.config.chainMocks[i];e.logger.scope(`transformer:${r.type||"unknown"}`).debug("chainMock",{chain:i}),a=t;continue}if(void 0!==r.config?.mock){e.logger.scope(`transformer:${r.type||"unknown"}`).debug("mock"),a=r.config.mock;continue}if(r.config?.disabled)continue;const u=r.config?.cache,l=u?xe(u):void 0,d=l?pt(l,e):void 0,f=r.config?.state?je(r.config.state):void 0,p=f?.filter(e=>"get"===e.mode),g=f?.filter(e=>"set"===e.mode),h=async t=>g&&0!==g.length?Ae(g,t=>gt(t,e),t,e):t;let m;if(l&&d){const e=Ee(s,a),t=await Oe(l,d,e);if("HIT"===t?.status&&t.value){if(a=t.value,l.stop)return{event:a,respond:c,stopped:!0};continue}"MISS"===t?.status&&(m={key:t.key,ttl:t.rule.ttl})}const y=r.config.before;if(y){const n=Ie(y,Ee(s,a));if(1===n.length){const o=yt(n[0],ht(t));if(o.length>0){const n=await kt(e,t,o,a,s,c,i);if(null===n.event)return{event:null,respond:n.respond??c};if(n.stopped)return{event:Array.isArray(n.event)?n.event[0]:n.event,respond:n.respond??c,stopped:!0};n.respond&&(c=n.respond),a=Array.isArray(n.event)?n.event[0]:n.event}}else n.length>1&&await Promise.all(n.map(n=>Se(kt,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,yt(n,ht(t)),a,bt(s,n),void 0,i)))}p&&p.length>0&&(a=await Ae(p,t=>gt(t,e),a,e));const v=await Se(wt,t=>(e.logger.scope(`transformer:${r.type||"unknown"}`).error("Push failed",{error:t}),!1))(e,r,o,a,s,c);if(!1===v)return{event:null,respond:c};if(Array.isArray(v)){const r=n.slice(n.indexOf(o)+1),u=await Promise.all(v.map(async n=>{const o=await h(n.event||a),u=bt(s,"unknown");if(n.next){const s=Ie(n.next,Ee(u,o));if(0===s.length)return{event:o,respond:c};if(1===s.length){const n=yt(s[0],ht(t));return n.length>0?kt(e,t,n,o,u,c,i):{event:o,respond:c}}return(await Promise.all(s.map(n=>Se(kt,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,yt(n,ht(t)),o,bt(u,n),void 0,i)))).map(e=>({event:e.event,respond:void 0}))}return r.length>0?kt(e,t,r,o,u,c,i):{event:o,respond:c}}));let l=c;const d=[];for(const e of u.flat())if(null!==e)if(e&&"object"==typeof e&&"event"in e){const t=e;if(t.respond&&(l=t.respond),null===t.event)continue;Array.isArray(t.event)?d.push(...t.event):d.push(t.event)}else d.push(e);return 0===d.length?{event:null,respond:l}:1===d.length?{event:d[0],respond:l}:{event:d,respond:l}}if(v&&"object"==typeof v){const{event:n,respond:o,next:r}=v;if(o&&(c=o),void 0!==r){const o=await h(n||a),u=Ie(r,Ee(s,o));if(0===u.length){a=o;continue}if(1===u.length){const n=yt(u[0],ht(t));return n.length>0?kt(e,t,n,o,s,c,i):(e.logger.warn(`Branch target not found: ${JSON.stringify(r)}`),{event:null,respond:c})}return await Promise.all(u.map(n=>Se(kt,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,yt(n,ht(t)),o,bt(s,n),void 0,i))),{event:null,respond:void 0}}n&&(a=n)}g&&g.length>0&&(a=await Ae(g,t=>gt(t,e),a,e)),m&&d&&Ce(d,m.key,a,m.ttl);const w=r.config.next,b="string"==typeof w||Array.isArray(w)&&w.every(e=>"string"==typeof e),k=void 0!==w&&!b;if((!v||"object"==typeof v&&!v.next)&&k){const n=Ie(r.config.next,Ee(s,a));if(1===n.length){const o=yt(n[0],ht(t));return o.length>0?kt(e,t,o,a,s,c,i):{event:a,respond:c}}return n.length>1?(await Promise.all(n.map(n=>Se(kt,t=>(e.logger.scope("transformer:many").error(`many branch ${n} failed`,{error:t}),{event:null,respond:void 0}))(e,t,yt(n,ht(t)),a,bt(s,n),void 0,i))),{event:null,respond:void 0}):{event:a,respond:c}}}return{event:a,respond:c}}function St(e){return e&&be(e)?e:{}}function qt(e){return"string"==typeof e||!(!Array.isArray(e)||!e.every(e=>"string"==typeof e))}async function It(e,t,n){if(!t.on||!t.queueOn?.length)return;const o=t.queueOn;t.queueOn=[];const s=n||t.config?.id||"unknown";for(const{type:n,data:r}of o)Mt(n)&&!Ht(e,t,n)||(await ce(t.on,t=>{if(t instanceof ie)throw t;e.status.failed++,e.logger.scope("source").error("source on flush failed",{sourceId:s,type:n,error:t})})(n,r),Mt(n)&&Rt(e,t,n))}function xt(e){return Boolean(e.config.init)&&!e.config.require?.length}async function Ot(e,t,n){const{code:o,config:s={},env:r={},primary:i,next:a,before:c,cache:u}=n,l=s.state??n.state,d=l?he(l):void 0,f=u,p=f?le({...f,stop:f.stop??!0}):void 0,g=qt(a)?yt(a,ht(e.transformers)):void 0,h=qt(c)?yt(c,ht(e.transformers)):void 0,m=r.push,y=m??e.push,v=Boolean(m),w=async(n,o,r)=>{let i;const u=h??(void 0!==c?(()=>{const t=ue(c,ge(r.ingest));return 0===t.length?[]:yt(1===t.length?t[0]:t,ht(e.transformers))})():[]);let l=[n];if(u.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const o=await kt(e,e.transformers,u,n,r.ingest,r.respond,`source.${t}.before`);if(null===o.event)return{ok:!0};if(o.stopped)return o.respond&&(r.respond=o.respond),{ok:!0};o.respond&&(r.respond=o.respond),l=Array.isArray(o.event)?o.event:[o.event]}if(p){const t=pt(p,e);if(t){const n=ge(r.ingest),o=await de(p,t,n);if(o){if("HIT"===o.status&&void 0!==o.value&&p.stop){let t=o.value;return o.rule.update&&(t=await pe(t,o.rule.update,{...n,cache:{status:"HIT"}},e)),r.respond?.(t),{ok:!0}}if("MISS"===o.status&&p.stop&&r.respond){const s=r.respond,a=o.rule.update,c={...n,cache:{status:"MISS"}},u=o.key,l=o.rule.ttl,d=n=>{fe(t,u,n,l),a?i=(async()=>{const t=await pe(n,a,c,e);s(t)})():s(n)};r.respond=d}"MISS"!==o.status||p.stop||fe(t,o.key,!0,o.rule.ttl)}}}const f=g?{kind:"single",preChain:g}:void 0!==a?(()=>{const t=ue(a,ge(r.ingest));return 0===t.length?{kind:"single",preChain:[]}:1===t.length?{kind:"single",preChain:yt(t[0],ht(e.transformers))}:{kind:"many",branches:t.map(t=>yt(t,ht(e.transformers)))}})():{kind:"single",preChain:[]};!v&&d&&d.length>0&&(l=await Promise.all(l.map(t=>me(d,t=>gt(t,e),t,e))));let m={ok:!0};for(const n of l)"many"===f.kind?(await Promise.all(f.branches.map((i,a)=>ce(async()=>v?y(n):y(n,{...o,id:t,ingest:bt(r.ingest,`${t}.${a}`),respond:void 0,mapping:s,preChain:i}),t=>(e.logger.scope("source:many").error(`many branch ${a} failed`,{error:t}),{ok:!0}))())),m={ok:!0}):m=v?await y(n):await y(n,{...o,id:t,ingest:r.ingest,respond:r.respond,mapping:s,preChain:f.preChain});return i&&await i,m},b=async n=>{const o=re(t);if(!s.ingest||void 0===n)return o;const r=await ae(n,s.ingest,{collector:e});return{...o,...r,_meta:o._meta}},k=e.logger.scope("source").scope(t),S={command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:k,...r,push:async(e,n={})=>{const o={ingest:re(t),respond:void 0};return w(e,n,o)}},q={collector:e,logger:k,id:t,config:s,env:S,withScope:async(e,t,n)=>{const o={ingest:await b(e),respond:t};return n({...S,push:(e,t={})=>w(e,t,o),ingest:o.ingest,respond:o.respond})},reportError:ft(e,"source",t,k)},I=await ce(o,n=>{if(n instanceof ie)throw n;e.status.failed++,e.logger.scope("source").error("source factory failed",{sourceId:t,error:n})})(q);if(!I)return;const x=I.type||"unknown",O=e.logger.scope(x).scope(t);return S.logger=O,i&&(I.config={...I.config,primary:i}),I}async function Ct(e){for(const[t,n]of Object.entries(e.sources)){if(xt(n))continue;const o=n.config.require;if(!o?.length)continue;const s=o.filter(t=>!$t(e,t));s.length!==o.length&&(n.config.require=s,xt(n)&&await It(e,n,t))}for(const[t,n]of Object.entries(e.pending.destinations)){if(!e.pending.destinations[t]||e.destinations[t])continue;const o=n.config?.require;if(!o)continue;const s=o.filter(t=>!$t(e,t));if(n.config&&(n.config.require=s),s.length>0)continue;delete e.pending.destinations[t];const r=nn(n);!1!==r.config.queue&&(r.queuePush=[...e.queue]),e.destinations[t]=r}}function Et(e){if("object"!=typeof e||null===e)return!1;if(!("logger"in e))return!1;const t=e.logger;return"object"==typeof t&&null!==t&&"scope"in t&&"function"==typeof t.scope}var Dt=!1;function Tt(){Dt||(Dt=!0,"undefined"!=typeof console&&"function"==typeof console.warn&&console.warn("walkerOS: ignored an on-dispatch call with a non-collector argument"))}function jt(e,t,n,o){if(n instanceof te)throw n;e.logger.scope("on").error("on callback failed",{kind:t,...o,error:n})}var At=[tt.Consent,tt.User,tt.Globals,tt.Custom];function Mt(e){return At.includes(e)}function Pt(e,t){switch(t){case tt.Consent:return Object.keys(e.consent).length>0;case tt.User:return Object.keys(e.user).length>0;case tt.Globals:return Object.keys(e.globals).length>0;case tt.Custom:return Object.keys(e.custom).length>0;default:return!1}}function $t(e,t){switch(t){case tt.Consent:case tt.User:case tt.Globals:case tt.Custom:return Pt(e,t);case tt.Run:case tt.Ready:return!0===e.allowed;default:return e.seenEvents.has(String(t))}}function _t(e,t){return e.cellVersion[String(t)]??0}function Rt(e,t,n){let o=e.delivery.get(t);o||(o={},e.delivery.set(t,o)),o[String(n)]=_t(e,n)}function Ht(e,t,n){return e.allowed&&_t(e,n)>function(e,t,n){const o=e.delivery.get(t),s=o?.[String(n)];return void 0===s?-1:s}(e,t,n)}function Gt(e,t,n){const o=e.cascade;if(!o)return!0;let s=o.counts.get(t);s||(s={},o.counts.set(t,s));const r=String(n),i=(s[r]||0)+1;return s[r]=i,i<=8||(9===i&&e.logger.error("state delivery did not converge",{type:r}),!1)}function Nt(e,t){return{collector:e,logger:e.logger.scope("on").scope(String(t))}}function zt(e,t,n,o,s){if(!t.on)return;const r=t.type||"unknown",i=e.logger.scope(r).scope("on").scope(o),a={collector:e,logger:i,id:n,config:t.config,data:s,env:on(t.env,t.config.env),reportError:ft(e,"destination",n,i,t)};ne(t.on,t=>jt(e,"destination",t,{destId:n,type:o}))(o,a)}function Bt(e,t,n,o){if(!Et(e))return void Tt();const s=Ut(e,t,o);if(n.length)switch(t){case tt.Consent:!function(e,t,n){const o=n||e.consent,s=Nt(e,tt.Consent);t.forEach(t=>{Ht(e,t,tt.Consent)&&Gt(e,t,tt.Consent)&&(Object.keys(o).filter(e=>e in t).forEach(n=>{ne(t[n],t=>jt(e,"consent",t,{key:n}))(o,s)}),Rt(e,t,tt.Consent))})}(e,n,o);break;case tt.Ready:!function(e,t){if(!e.allowed)return;const n=Nt(e,tt.Ready);t.forEach(t=>{ne(t,t=>jt(e,"ready",t))(void 0,n)})}(e,n);break;case tt.Run:!function(e,t){if(!e.allowed)return;const n=Nt(e,tt.Run);t.forEach(t=>{ne(t,t=>jt(e,"run",t))(void 0,n)})}(e,n);break;case tt.Session:!function(e,t){if(!e.session)return;const n=Nt(e,tt.Session);t.forEach(t=>{ne(t,t=>jt(e,"session",t))(e.session,n)})}(e,n);break;default:{const o=Nt(e,t),r=Mt(t);n.forEach(n=>{"function"==typeof n&&(r&&!Ht(e,n,t)||r&&!Gt(e,n,t)||(ne(n,n=>jt(e,"generic",n,{type:t}))(s,o),r&&Rt(e,n,t)))});break}}}function Ut(e,t,n){switch(t){case tt.Consent:return n||e.consent;case tt.Session:return e.session;case tt.User:return n||e.user;case tt.Custom:return n||e.custom;case tt.Globals:return n||e.globals;case tt.Config:return n||e.config;default:return}}async function Ft(e,t,n,o,s){if(!t.on)return!1;if(Mt(o)&&!Ht(e,t,o))return!1;if(Mt(o)&&!Gt(e,t,o))return!1;const r=await oe(t.on,t=>jt(e,"source",t,{sourceId:n,type:o}))(o,s);return Mt(o)&&Rt(e,t,o),!1===r}function Lt(e){return"number"==typeof e&&e>0?e:1e4}var Kt=class extends Error{constructor(e){super(e),this.name="DestinationTimeoutError"}};function Qt(e,t,n){let o;const s=new Promise((e,s)=>{o=setTimeout(()=>s(new Kt(n)),t)});return Promise.race([e,s]).finally(()=>{o&&clearTimeout(o)})}var Jt=Object.freeze({batched:!0});function Wt(e){return e===Jt}function Vt(e){return void 0===e?{}:"number"==typeof e?{wait:e}:{wait:e.wait,size:e.size,age:e.age}}function Yt(e,t,n){if(!e)return[];if(Array.isArray(e)&&e.every(e=>"string"==typeof e))return yt(e,t);if("string"==typeof e)return yt(e,t);const o=U(e,M(n));return 0===o.length?[]:1===o.length?yt(o[0],t):yt(o,t)}async function Xt(e,t,n={},o){const{allowed:s,consent:r,globals:i,user:a}=e;if(!s)return tn({ok:!1});if(t){const n=e.config.queueMax;if(void 0===n)throw new Error("Collector.Config.queueMax is undefined; defaults must be seeded by collector()");const o=ot(e.queue,t,{max:n});if(o.dropped>0){const t=dt(e.status,J("collector"),"queue",o.dropped);rt(e.queue,e.logger,"collector.queue overflow; oldest events dropped",{buffer:"queue",cap:n,droppedCount:t})}else e.queue.length<n&&it(e.queue);e.status.in++}o||(o=e.destinations);const c=e.transformers?ht(e.transformers):{},u=await Promise.all(Object.entries(o||{}).map(async([o,s])=>{if(s.config.disabled)return{id:o,destination:s,skipped:!0};const u=s.config.id||o,l=J("destination",u),d=ct(s.config.breaker);if(d&&function(e,t,n){const o=e[t];if(!o||"closed"===o.state)return!1;if("half-open"===o.state)return!0===o.probing;const s=at();return void 0!==o.openUntil&&s<o.openUntil||(o.state="half-open",o.probing=!0,o.openUntil=s+n,!1)}(e.status.breakers,l,d.cooldown))return{id:o,destination:s,skipped:!0};const f=t=>{d&&ut(e.status.breakers,l,t,d.threshold,d.cooldown)},p=()=>{d&&function(e,t){const n=e[t];n&&"half-open"===n.state&&!0===n.probing&&(n.state="open",n.probing=!1)}(e.status.breakers,l)};let g=(s.queuePush||[]).map(e=>({...e,consent:r}));s.queuePush=[],t&&g.push(P(t));const h=n.ingest?{...n.ingest,_meta:{...n.ingest._meta,path:[...n.ingest._meta.path]}}:H("unknown");if(!g.length&&!s.queueOn?.length)return p(),{id:o,destination:s,skipped:!0};if(!g.length&&s.queueOn?.length){if(!B(s.config.consent,r))return p(),{id:o,destination:s,skipped:!0};let t=!1;try{t=await Zt(e,s,o,!0)}catch(t){e.status.failed++;const n=s.type||"unknown";e.logger.scope(n).error("destination init failed",{error:t instanceof Error?t.message:String(t)}),f("transport-failure")}return p(),{id:o,destination:s,skipped:!t}}const m=[],y=g.filter(t=>{const n=B(s.config.consent,r,t.consent);if(n)return t.consent=n,m.push(t),!1;const i=nt(e,{stepId:J("destination",o),stepType:"destination",phase:"skip",eventId:"string"==typeof t.id?t.id:"",now:Date.now()});return i.skipReason="consent",r&&(i.consent={...r}),s.config.consent&&(i.meta={required:{...s.config.consent}}),N(e,i),!0});if(y.length>0){const t=s.queuePush,n=s.config.id||o,r={max:s.config.queueMax??1e3};let i=0;for(const e of y)i+=ot(t,e,r).dropped;if(i>0){lt(e,n);const o=dt(e.status,J("destination",n),"queue",i);rt(t,e.logger.scope(s.type||"unknown"),"destination.queuePush overflow; oldest events dropped",{buffer:"queuePush",destination:n,cap:r.max,droppedCount:o})}else t.length<r.max&&it(t)}if(!m.length)return p(),{id:o,destination:s,queue:g};let v,w,b=!1;try{b=await Zt(e,s,o,!0)}catch(t){e.status.failed++;const n=s.type||"unknown";e.logger.scope(n).error("destination init failed",{error:t instanceof Error?t.message:String(t)}),f("transport-failure")}if(!b)return p(),{id:o,destination:s,queue:g};s.dlq||(s.dlq=[]);const k=Yt(s.config.before,c,h),S=s.config.next,q=s.config?.cache,I=q?$(q):void 0,x=I?pt(I,e):void 0,O=s.config?.state?Y(s.config.state):void 0,C=O?.filter(e=>"get"===e.mode),E=O?.filter(e=>"set"===e.mode);let D=0,T=0;return await Promise.all(m.map(async t=>{let r;if(t.globals=A(i,t.globals),t.user=A(a,t.user),I?.stop&&x){const e=M(h,t),n=await _(I,x,e);if("HIT"===n?.status)return t;"MISS"===n?.status&&(r={key:n.key,ttl:n.rule.ttl})}let u=t,l=n.respond;if(k.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const s=await kt(e,e.transformers,k,t,h,n.respond,`destination.${o}.before`);if(null===s.event)return t;s.respond&&(l=s.respond),u=Array.isArray(s.event)?s.event[0]:s.event}if(I&&!I.stop&&x){const e=M(h,u),n=await _(I,x,e);if("HIT"===n?.status)return t;"MISS"===n?.status&&(r={key:n.key,ttl:n.rule.ttl})}C&&C.length>0&&u&&(u=await X(C,t=>gt(t,e),u,e));const d=Date.now();let f=!1;const p=await W(en,t=>{const n=s.type||"unknown";e.logger.scope(n).error("Push failed",{error:t,event:u.name}),v=t,f=!0;const r=s.dlq,i=s.config.id||o,a={max:s.config.dlqMax??100},c=ot(r,[u,t],a);if(c.dropped>0){lt(e,i);const t=dt(e.status,J("destination",i),"dlq",c.dropped);rt(r,e.logger.scope(s.type||"unknown"),"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:i,cap:a.max,droppedCount:t})}else r.length<a.max&&it(r)})(e,s,o,u,h,l);if(D+=Date.now()-d,r&&x&&void 0===s.config.mock&&R(x,r.key,p??!0,r.ttl),!f&&!Wt(p)&&E&&E.length>0&&u&&(u=await X(E,t=>gt(t,e),u,e)),void 0===p||Wt(p)||(w=p),Wt(p)&&T++,!f&&S){void 0!==p&&(h._response=p);const t=Yt(S,c,h);if(t.length>0&&e.transformers&&Object.keys(e.transformers).length>0){const n=await kt(e,e.transformers,t,u,h,l,`destination.${o}.next`);n.respond&&(l=n.respond)}}return t})),{id:o,destination:s,error:v,response:w,totalDuration:D,batchedCount:T,allowedCount:m.length,canonicalId:u,breakerConfig:d}})),l={},d={},f={};for(const t of u){if(t.skipped)continue;const n=t.destination,o={type:n.type||"unknown",data:t.response};lt(e,t.id);const s=e.status.destinations[t.id],r=Date.now();s.queuePushSize=n.queuePush?.length??0,s.dlqSize=n.dlq?.length??0;const i=t.breakerConfig,a=t.canonicalId?J("destination",t.canonicalId):void 0,c=t=>{i&&a&&ut(e.status.breakers,a,t,i.threshold,i.cooldown)};if(t.error)o.error=t.error,f[t.id]=o,s.failed++,s.lastAt=r,s.duration+=t.totalDuration||0,e.status.failed++,c("transport-failure");else if(t.queue&&t.queue.length)d[t.id]=o;else{const n=t.batchedCount??0,i=t.allowedCount??0;(Math.max(0,i-n)>0||0===i)&&(l[t.id]=o,s.count++,s.lastAt=r,s.duration+=t.totalDuration||0,e.status.out++,c("success"))}}return tn({event:t,...Object.keys(l).length&&{done:l},...Object.keys(d).length&&{queued:d},...Object.keys(f).length&&{failed:f}})}async function Zt(e,t,n,o=!1){if(t.init&&!t.config.init){if(!o&&function(e){const t=e.config.consent;return!!t&&Object.keys(t).length>0}(t))return e.logger.scope(t.type||"unknown").debug("init blocked: consent gate not cleared"),!1;const s=t.type||"unknown",r=e.logger.scope(s),i={collector:e,logger:r,id:n,config:t.config,env:on(t.env,t.config.env),reportError:ft(e,"destination",n,r,t)};r.debug("init");const a=Date.now();let c;N(e,nt(e,{stepId:J("destination",n),stepType:"destination",phase:"init",eventId:"",now:a}));try{c=await V(t.init,"DestinationInit",e.hooks,e.logger)(i)}catch(t){const o=Date.now(),s=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"error",eventId:"",now:o});throw s.durationMs=o-a,s.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},N(e,s),t}if(!1===c)return c;if(t.config={...c||t.config,init:!0},t.queueOn?.length){const o=t.queueOn;t.queueOn=[];for(const{type:s,data:r}of o)zt(e,t,n,s,r)}r.debug("init done")}return!0}async function en(e,t,n,o,s,r){const{config:i}=t,a=await Q(o,i,e);if(a.ignore)return!1;const c=t.type||"unknown",u=e.logger.scope(c),l={collector:e,logger:u,id:n,config:i,data:a.data,rule:a.mapping,ingest:s,env:{...on(t.env,i.env),...r?{respond:r}:{}},reportError:ft(e,"destination",n,u,t)};if(void 0!==i.mock)return u.debug("mock",{event:a.event.name}),i.mock;const d=a.mapping,f=void 0!==d?.batch,p=f?a.mappingKey||"* *":" batch-all";if((f||void 0!==i.batch)&&t.pushBatch&&void 0===i.mock){if(t.batches=t.batches||{},!t.batches[p]){const o={key:p,entries:[],events:[],data:[]},s=Vt(d?.batch),r=Vt(i.batch),a=s.wait??r.wait??3e4,c=s.size??r.size??1e3,l=s.age??r.age??3e4,g=on(t.env,i.env),h=G(async()=>{const o=t.batches[p],s=o.batched;if(0===s.entries.length)return;const r={key:s.key,entries:s.entries,events:s.events,data:s.data};s.entries=[],s.events=[],s.data=[];const a=r.entries[0],c={collector:e,logger:u,id:n,config:i,data:void 0,rule:o.isDefault?void 0:a.rule,ingest:a.ingest,env:{...g,...a.respond?{respond:a.respond}:{}},reportError:ft(e,"destination",n,u,t)};u.debug("push batch",{events:r.entries.length});const l=t.config.id||n,d=lt(e,l),f=ct(t.config.breaker),h=J("destination",l),m=t=>{f&&ut(e.status.breakers,h,t,f.threshold,f.cooldown)},y=Date.now(),v=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"flush",eventId:"",now:y});v.batch={size:r.entries.length,index:0},N(e,v);const w=n=>{const o=t.dlq=t.dlq||[],s={max:t.config.dlqMax??100};let r=0;for(const e of n)r+=ot(o,e,s).dropped;if(r>0){const t=dt(e.status,J("destination",l),"dlq",r);rt(o,u,"destination.dlq overflow; oldest entries dropped",{buffer:"dlq",destination:l,cap:s.max,droppedCount:t})}else o.length<s.max&&it(o);d.failed+=n.length,d.dlqSize=o.length,e.status.failed+=n.length};let b=r.entries.length;const k=Lt(i.timeout),S=await W((o,s)=>Qt(Promise.resolve(V(t.pushBatch,"DestinationPushBatch",e.hooks,e.logger)(o,s)),k,`Destination "${n}" batch delivery timed out after ${k}ms`),t=>{b=0;const o=Date.now(),s=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"error",eventId:"",now:o});s.durationMs=o-y,s.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},s.batch={size:r.entries.length,index:0},N(e,s),w(r.entries.map(e=>[e.event,t])),m("transport-failure"),u.error("Push batch failed",{error:t instanceof Error?t.message:String(t),entries:r.entries.length})})(r,c);if(K(q=S)&&Array.isArray(q.failed)&&S.failed.length>0){const e=[],t=new Set;for(const n of S.failed){const o=r.entries[n.index];o&&!t.has(n.index)&&(t.add(n.index),e.push([o.event,n.error??new Error(`Push batch entry ${n.index} failed (no per-row error provided)`)]))}e.length>0&&(w(e),b=Math.max(0,r.entries.length-e.length),u.error("Push batch partial failure",{failed:e.length,delivered:b,entries:r.entries.length}))}var q;u.debug("push batch done"),d.inFlightBatch=Math.max(0,(d.inFlightBatch??0)-r.entries.length),b>0&&(d.count+=b,d.lastAt=Date.now(),e.status.out+=b,m("success"))},{wait:a,size:c,age:l});t.batches[p]={batched:o,isDefault:!f,batchFn:()=>{h()},flush:async()=>{await h.flush()}}}const o=t.batches[p];o.batched.entries.push({event:a.event,ingest:s,respond:r,rule:d,data:a.data}),o.batched.events.push(a.event),F(a.data)&&o.batched.data.push(a.data);const c=t.config.id||n,l=lt(e,c);return l.inFlightBatch=(l.inFlightBatch??0)+1,o.batchFn(),Jt}{u.debug("push",{event:a.event.name});const o="string"==typeof a.event.id?a.event.id:"",s=Date.now(),r=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"in",eventId:o,now:s});a.mappingKey&&(r.mappingKey=a.mappingKey),a.event.consent&&(r.consent={...a.event.consent}),r.inEvent=a.event,N(e,r);try{const r=Lt(i.timeout),c=await Qt(Promise.resolve(V(t.push,"DestinationPush",e.hooks,e.logger)(a.event,l)),r,`Destination "${n}" delivery timed out after ${r}ms`),d=Date.now(),f=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"out",eventId:o,now:d});return f.durationMs=d-s,f.outEvent=a.event,F(c)&&(f.meta={...f.meta,response:c}),a.mappingKey&&(f.mappingKey=a.mappingKey),N(e,f),u.debug("push done"),c}catch(t){const r=Date.now(),i=nt(e,{stepId:J("destination",n),stepType:"destination",phase:"error",eventId:o,now:r});throw i.durationMs=r-s,i.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},a.mappingKey&&(i.mappingKey=a.mappingKey),N(e,i),t}}}function tn(e){return{ok:!e?.failed,...e}}function nn(e){const{code:t,config:n={},env:o={},cache:s,state:r}=e,{config:i}=mt(e,"before"),{config:a}=mt({...e,config:i},"next"),c={...t.config,...n,...a};s&&(c.cache=s),void 0!==r&&void 0===c.state&&(c.state=r);const u=on(t.env,o);return{...t,config:c,env:u}}function on(e,t){return e||t?t?e&&K(e)&&K(t)?{...e,...t}:t:e:{}}async function sn(e,t,n){const o=Object.entries(e).map(async([e,o])=>{const s=o.destroy;if(!s)return;const r=o.type||"unknown",i=n.scope(r),a={id:e,config:o.config,env:o.env??{},logger:i};let c;try{await Promise.race([s(a),new Promise((n,o)=>{c=setTimeout(()=>o(new Error(`${t} '${e}' destroy timed out`)),5e3)})])}catch(n){i.error(`${t} '${e}' destroy failed: ${n}`)}finally{c&&clearTimeout(c)}});await Promise.allSettled(o)}function rn(e,t){e.stateVersion++,e.cellVersion[t]=e.stateVersion}async function an(e,t,n){let o,s,r=!1;const i=function(e){return e.cascade?()=>{}:(e.cascade={counts:new WeakMap},()=>{e.cascade=void 0})}(e);try{return await async function(){switch(t){case tt.Config:He(n)&&(Me(e.config,n,{shallow:!1}),s=n,r=!0);break;case tt.Consent:if(He(n)){const{update:t}=function(e,t){const n={};return Object.entries(t).forEach(([e,t])=>{n[e]=!!t}),e.consent=D(e.consent,n),{update:n}}(e,n);rn(e,tt.Consent),s=t,r=!0}break;case tt.Custom:He(n)&&(e.custom=Me(e.custom,n),rn(e,tt.Custom),s=n,r=!0);break;case tt.Destination:He(n)&&"code"in n&&He(n.code)&&(o=await async function(e,t){const{code:n,config:o={},env:s={},before:r,next:i,cache:a,state:c}=t;if(!L(n.push))return tn({ok:!1,failed:{invalid:{type:"invalid",error:"Destination code must have a push method"}}});const u=o||{init:!1};let l=r?{...u,before:r}:{...u};i&&(l={...l,next:i}),a&&(l={...l,cache:a}),void 0!==c&&void 0===l.state&&(l={...l,state:c});let d=l.id;if(!d)do{d=z(5,"abcdefghijklmnopqrstuvwxyz")}while(e.destinations[d]||e.pending.destinations[d]);if(l.require?.length){e.pending.destinations[d]=t,await Ct(e);const n=e.destinations[d];return n?Xt(e,void 0,{},{[d]:n}):tn({ok:!0})}const f={...n,config:l,env:on(n.env,s)};return e.destinations[d]=f,!1!==f.config.queue&&(f.queuePush=[...e.queue]),Xt(e,void 0,{},{[d]:f})}(e,n));break;case tt.Globals:He(n)&&(e.globals=Me(e.globals,n),rn(e,tt.Globals),s=n,r=!0);break;case tt.Hook:if(He(n)&&Re(n.name)&&_e(n.fn)){const{name:t,fn:o}=n;e.hooks[t]=o,s=n,r=!0}break;case tt.On:if(He(n)&&Re(n.type)){const{type:t,rules:o}=n;await async function(e,t,n){if(!Et(e))return void Tt();const o=e.on,s=o[t]||[],r=ee(n)?n:[n];r.forEach(e=>{s.push(e)}),o[t]=s,Bt(e,t,r)}(e,t,o)}break;case tt.Ready:r=!0;break;case tt.Run:o=await async function(e,t){return e.allowed=!0,e.timing=Date.now(),e.trace=$e(),e.count=0,t&&(t.consent&&(e.consent=Me(e.consent,t.consent),rn(e,tt.Consent)),t.user&&(e.user=Me(e.user,t.user),rn(e,tt.User)),t.globals&&(e.globals=Me(e.config.globalsStatic||{},t.globals),rn(e,tt.Globals)),t.custom&&(e.custom=Me(e.custom,t.custom),rn(e,tt.Custom))),Object.values(e.destinations).forEach(e=>{e.queuePush=[]}),e.queue=[],e.round++,await Ct(e),await async function(e){if(Et(e))for(const t of At){if(!Pt(e,t))continue;const n=Ut(e,t);Bt(e,t,e.on[t]||[]);for(const[o,s]of Object.entries(e.sources))xt(s)&&await Ft(e,s,o,t,n)}else Tt()}(e),await Xt(e)}(e,n),r=!0;break;case tt.Session:r=!0;break;case tt.Shutdown:e.hasShutdown||(e.hasShutdown=!0,await async function(e){const t=e.logger;await sn(e.sources,"source",t),await async function(e,t){const n=Object.entries(e).flatMap(([e,n])=>{const o=n.batches;if(!o)return[];const s=t.scope(n.type||"destination");return Object.values(o).map(async t=>{let n;try{await Promise.race([t.flush(),new Promise((t,o)=>{n=setTimeout(()=>o(new Error(`destination '${e}' batch flush timed out`)),5e3)})])}catch(t){s.error(`destination '${e}' batch flush failed: ${t}`)}finally{n&&clearTimeout(n)}})});await Promise.allSettled(n)}(e.destinations,t),await sn(e.destinations,"destination",t),await sn(e.transformers,"transformer",t),await sn(e.stores,"store",t)}(e));break;case tt.User:He(n)&&(Me(e.user,n,{shallow:!1}),rn(e,tt.User),s=n,r=!0)}return r&&(await async function(e,t,n,o){if(!Et(e))return Tt(),!0;e.seenEvents.add(String(t));let s=n||[];n||(s=e.on[t]||[]);const r=Ut(e,t,o);let i=!1;for(const[n,o]of Object.entries(e.sources)){if(o.config.require?.length){const e=o.config.require.indexOf(t);-1!==e&&o.config.require.splice(e,1)}o.on&&(xt(o)?await Ft(e,o,n,t,r)&&(i=!0):(o.queueOn=o.queueOn||[],o.queueOn.push({type:t,data:r})))}Object.entries(e.destinations).forEach(([n,o])=>{if(o.on){if(!o.config.init)return o.queueOn=o.queueOn||[],void o.queueOn.push({type:t,data:r});zt(e,o,n,t,r)}});for(const[t,n]of Object.entries(e.sources))xt(n)&&n.queueOn?.length&&await It(e,n,t);const a=Object.values(e.sources).some(e=>!xt(e)&&e.config.require?.length);return(Object.keys(e.pending.destinations).length>0||a)&&await Ct(e),Bt(e,t,s,o),!i}(e,t,void 0,s),o=await Xt(e)),o||tn({ok:!0})}()}finally{i()}}function cn(e,t){return{timing:Math.round((Date.now()-e.timing)/10)/100,source:{type:"collector",schema:"4",version:"4.2.1"},...t}}function un(e,t){if(!t.name)throw new Error("Event name is required");const[n,o]=t.name.split(" ");if(!n||!o)throw new Error("Event name is invalid");const{timestamp:s=Date.now(),name:r=`${n} ${o}`,data:i={},context:a={},globals:c=e.globals,custom:u={},user:l=e.user,nested:d=[],consent:f=e.consent,id:p=Pe(),trigger:g="",entity:h=n,action:m=o,timing:y=0,source:v={type:"collector",schema:"4"}}=t,w=v.count??(e.count+=1),b=v.trace??e.trace,k={...v,count:w};return void 0!==b&&(k.trace=b),{name:r,data:i,context:a,globals:c,custom:u,user:l,nested:d,consent:f,id:p,trigger:g,entity:h,action:m,timestamp:s,timing:y,source:k}}function ln(e,t){const n=Le(async(n,o={})=>await Fe(async()=>{const s=Date.now(),{id:r,ingest:i,respond:a,mapping:c,preChain:u,include:l,exclude:d}=o;let f=a,p=n;const g=l||d?function(e,t,n){let o=e;return t&&(o=Object.fromEntries(Object.entries(o).filter(([e])=>t.includes(e)))),n&&(o=Object.fromEntries(Object.entries(o).filter(([e])=>!n.includes(e)))),o}(e.destinations,l,d):void 0,h=i??Ge(r||"unknown");if(c){const t=await Ue(p,c,e);if(t.ignore)return tn({ok:!0});if(c.consent&&!Be(c.consent,e.consent,t.event.consent))return tn({ok:!0});p=t.event}if(u?.length&&e.transformers&&Object.keys(e.transformers).length>0){const n=await kt(e,e.transformers,u,p,h,f,r?`source.${r}.next`:void 0);if(null===n.event)return tn({ok:!0});if(n.stopped)return n.respond&&(f=n.respond),tn({ok:!0});if(n.respond&&(f=n.respond),Array.isArray(n.event)){const o=await Promise.all(n.event.map(async n=>{const o=t(n),s=un(e,o);return Xt(e,s,{id:r,ingest:h,respond:f},g)}));if(r){e.status.sources[r]||(e.status.sources[r]={count:0,duration:0});const t=e.status.sources[r];t.count+=n.event.length,t.lastAt=Date.now(),t.duration+=Date.now()-s}return o[0]??tn({ok:!0})}p=n.event}const m=function(e,t){return un(e,cn(e,t))}(e,p),y=await Xt(e,m,{id:r,ingest:h,respond:f},g);if(r){e.status.sources[r]||(e.status.sources[r]={count:0,duration:0});const t=e.status.sources[r];t.count++,t.lastAt=Date.now(),t.duration+=Date.now()-s}return y},t=>{if(t instanceof ze)throw t;return e.status.failed++,e.logger.error("push failed",{event:n,ingest:o.ingest,error:t}),tn({ok:!1})})(),"Push",e.hooks,e.logger);return async(t,o)=>{const s="string"==typeof t.id?t.id:"",r=Date.now(),i=nt(e,{stepId:"collector.push",stepType:"collector",phase:"in",eventId:s,now:r});i.inEvent=t,Ne(e,i);try{const i=await n(t,o),a=Date.now(),c=nt(e,{stepId:"collector.push",stepType:"collector",phase:"out",eventId:s,now:a});return c.durationMs=a-r,c.outEvent=i,Ne(e,c),i}catch(t){const n=Date.now(),o=nt(e,{stepId:"collector.push",stepType:"collector",phase:"error",eventId:s,now:n});throw o.durationMs=n-r,o.error=t instanceof Error?{name:t.name,message:t.message}:{message:String(t)},Ne(e,o),t}}}function dn(e={}){const t=e.maxEntries??1e4,n=e.lowWaterMark??.8,o=e.sweepIntervalMs??6e4,s=Math.floor(t*n),r=new Map,i={hits:0,misses:0,populates:0,writes:0,deletes:0,evictions_entries:0,evictions_ttl:0};let a;return o>0&&(a=setInterval(function(){const e=Date.now();let t=0;for(const[n,o]of r)void 0!==o.expires&&o.expires<=e&&(r.delete(n),t++);i.evictions_ttl+=t},o),a&&"function"==typeof a.unref&&a.unref()),{type:"memory",config:{},get(e){const t=r.get(e);if(t)return void 0!==t.expires&&t.expires<=Date.now()?(r.delete(e),i.evictions_ttl++,void i.misses++):(r.delete(e),r.set(e,t),i.hits++,t.value);i.misses++},set(e,n,o){const a=!r.has(e);a||r.delete(e),r.set(e,{value:n,expires:void 0!==o?Date.now()+o:void 0}),i.writes++,a&&i.populates++,r.size>t&&function(){if(r.size<=t)return;const e=r.size-s;let n=0;for(const t of r.keys()){if(n>=e)break;r.delete(t),n++}i.evictions_entries+=n}()},delete(e){r.delete(e)&&i.deletes++},get counters(){return{...i}},destroy(){void 0!==a&&(clearInterval(a),a=void 0),r.clear()}}}function fn(e,t){const{cacheConfig:n,cacheStore:o,namespace:s,logger:r,storeId:i,collector:a}=t,c=(e,t)=>{if(!a)return;const n=nt(a,{stepId:`store.${i}`,stepType:"store",phase:"in",eventId:"",now:Date.now()});n.meta={op:"cache",cached:"hit"===t,status:t,key:e},Xe(a,n)},u={hits:0,misses:0,populates:0,writes:0,deletes:0,inflight_dedups:0},l=n.rules.map(e=>({match:e.match?Ye(e.match):()=>!0,ttl:e.ttl})),d=e=>`${s}:${e}`;function f(e,t){const n=void 0===t?{key:e}:{key:e,value:t};return l.find(e=>e.match(n))}const p=new Map;return{type:e.type,config:e.config,setup:e.setup,get counters(){return{...u}},async get(t){const n=d(t),s=await o.get(n),r=Ze(s);if(void 0!==r){if(!("expired"in r))return u.hits++,c(t,"hit"),r.value;try{await o.delete(n)}catch(e){g("delete",t,e)}}const i=p.get(n);if(i)return u.inflight_dedups++,c(t,"hit"),i;u.misses++,c(t,"miss");const a=(async()=>{try{const s=await e.get(t);if(void 0===s)return;const r=f(t,s);if(r)try{const e=1e3*r.ttl;await o.set(n,et(s,e),e),u.populates++}catch(e){g("set",t,e)}return s}finally{p.delete(n)}})();return p.set(n,a),a},async set(t,n,s){u.writes++,await e.set(t,n,s);const r=f(t,n);if(r)try{const e=1e3*r.ttl;await o.set(d(t),et(n,e),e)}catch(e){g("set",t,e)}},async delete(t){u.deletes++,await e.delete(t);try{await o.delete(d(t))}catch(e){g("delete",t,e)}}};function g(e,t,n){const o=`store-cache(${i}): cache ${e} failed for "${t}"; backing succeeded, continuing`;r?r.warn(o,{error:n}):console.warn(o,n)}}function pn(e,t,n){const o=`store.${n}`,s=Ve(t.get,"StoreGet",e.hooks,e.logger),r=Ve(t.set,"StoreSet",e.hooks,e.logger),i=Ve(t.delete,"StoreDelete",e.hooks,e.logger);t.get=async t=>{const n=Date.now(),r=nt(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:n});r.meta={op:"get",key:t},We(e,r);try{const r=await s(t),i=Date.now(),a=nt(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:i});return a.durationMs=i-n,a.meta={op:"get",key:t},We(e,a),r}catch(s){const r=Date.now(),i=nt(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:r});throw i.durationMs=r-n,i.meta={op:"get",key:t},i.error=s instanceof Error?{name:s.name,message:s.message}:{message:String(s)},We(e,i),s}},t.set=async(t,n,s)=>{const i=Date.now(),a=nt(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:i});a.meta={op:"set",key:t},We(e,a);try{await r(t,n,s);const a=Date.now(),c=nt(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:a});c.durationMs=a-i,c.meta={op:"set",key:t},We(e,c)}catch(n){const s=Date.now(),r=nt(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:s});throw r.durationMs=s-i,r.meta={op:"set",key:t},r.error=n instanceof Error?{name:n.name,message:n.message}:{message:String(n)},We(e,r),n}},t.delete=async t=>{const n=Date.now(),s=nt(e,{stepId:o,stepType:"store",phase:"in",eventId:"",now:n});s.meta={op:"delete",key:t},We(e,s);try{await i(t);const s=Date.now(),r=nt(e,{stepId:o,stepType:"store",phase:"out",eventId:"",now:s});r.durationMs=s-n,r.meta={op:"delete",key:t},We(e,r)}catch(s){const r=Date.now(),i=nt(e,{stepId:o,stepType:"store",phase:"error",eventId:"",now:r});throw i.durationMs=r-n,i.meta={op:"delete",key:t},i.error=s instanceof Error?{name:s.name,message:s.message}:{message:String(s)},We(e,i),s}}}async function gn(e){const t=T({globalsStatic:{},sessionStatic:{},run:!0,queueMax:1e3},e,{merge:!1,extend:!1}),n={level:e.logger?.level,handler:e.logger?.handler},o=j(n),s={...t.globalsStatic,...e.globals},r={allowed:!1,config:t,consent:e.consent||{},custom:e.custom||{},destinations:{},transformers:{},stores:{},globals:s,hooks:e.hooks||{},observers:new Set,logger:o,on:{},queue:[],round:0,count:0,stateVersion:0,cellVersion:{},delivery:new WeakMap,session:void 0,status:{startedAt:Date.now(),in:0,out:0,failed:0,sources:{},destinations:{},dropped:{},connectionErrors:{},breakers:{}},timing:Date.now(),user:e.user||{},sources:{},pending:{destinations:{}},hasShutdown:!1,seenEvents:new Set,push:void 0,command:void 0};var i,a;r.push=ln(r,e=>cn(r,e)),r.command=(a=an,Qe(async(e,t,n)=>await Je(async()=>await a(i,e,t,n),n=>{if(n instanceof Ke)throw n;return i.status.failed++,i.logger.error("command failed",{command:e,data:t,error:n}),tn({ok:!1})})(),"Command",(i=r).hooks,i.logger));const c=e.stores||{};return r.stores=await async function(e,t={}){const n={};for(const[o,s]of Object.entries(t)){const{code:t,config:r={},env:i={}}=s,a=e.logger.scope("store").scope(o),c={collector:e,logger:a,id:o,config:r,env:i,reportError:ft(e,"store",o,a)},u=await t(c);n[o]=u}const o=t,s=function(e){const t={};for(const n of Object.keys(e))t[n]="WHITE";const n=[],o=[];function s(r){const i=t[r];if("BLACK"===i)return;if("GRAY"===i){const e=o.indexOf(r),t=o.slice(-1===e?0:e).concat(r).join(" -> ");throw new Error(`Cycle in cache.store chain: ${t}`)}t[r]="GRAY",o.push(r);const a=e[r].cache?.store;if(void 0!==a){if(!(a in e))throw new Error(`Store "${r}" cache.store references "${a}", which is not declared in flow.stores`);s(a)}o.pop(),t[r]="BLACK",n.push(r)}for(const n of Object.keys(e))"WHITE"===t[n]&&s(n);return n}(o);for(const t of s){const s=o[t].cache;if(!s)continue;let r,i;void 0!==s.store?(r=n[s.store],i=s.store):(n.__cache||(n.__cache=dn()),r=n.__cache,i="__cache");const a=s.namespace??t;e.logger.scope("store-cache").scope(t).info(`store "${t}" caches with namespace "${a}:" via ${i}`),n[t]=fn(n[t],{storeId:t,cacheConfig:s,cacheStore:r,namespace:a,logger:e.logger.scope("store-cache").scope(t),collector:e})}for(const[t,o]of Object.entries(n))"__cache"!==t&&pn(e,o,t);return n}(r,c),function(e,t,n){const o=new Map;for(const[n,s]of Object.entries(e))t[n]&&o.set(s,t[n]);if(0!==o.size)for(const e of[n.transformers,n.destinations,n.sources])if(e)for(const t of Object.values(e))s(t.env);function s(e){if(e)for(const[t,n]of Object.entries(e))if("object"==typeof n&&null!==n){const s=o.get(n);s&&(e[t]=s)}}}(c,r.stores,e),r.stores.__cache||(r.stores.__cache=dn()),r.destinations=await async function(e,t={}){const n={};for(const[o,s]of Object.entries(t))s.config?.require?.length?e.pending.destinations[o]=s:n[o]=nn(s);return n}(r,e.destinations||{}),r.transformers=await async function(e,t={}){const n={};for(const[o,s]of Object.entries(t)){const{code:t,env:r={}}=s,i=De(s,"Transformer");if(!i.ok){e.logger.warn(`Transformer ${o} invalid (${i.code}): ${i.reason}. Skipping.`);continue}const{config:a}=mt(s,"before"),{config:c}=mt({...s,config:a},"next"),u=Object.keys(r).length>0?{...c,env:r}:c,{cache:l}=s,d=l?{...u,cache:l}:u,f=s.config?.state??s.state,p=void 0!==f&&void 0===d.state?{...d,state:f}:d,g=e.logger.scope("transformer").scope(o),h={collector:e,logger:g,id:o,ingest:ye(o),config:p,env:r,reportError:ft(e,"transformer",o,g)},m=t??(e=>{const t=s.mapping;if(t){const n=[];if(void 0!==t.data&&n.push("data"),t.mapping)for(const[e,o]of Object.entries(t.mapping))if("object"==typeof o&&null!==o)for(const[t,s]of Object.entries(o)){if("object"!=typeof s||null===s)continue;const o=s;void 0!==o.data&&n.push(`mapping[${e}][${t}].data`),void 0!==o.silent&&n.push(`mapping[${e}][${t}].silent`)}return n.length>0&&e.collector.logger.warn(`Transformer ${o}: \`${n.join(", ")}\` ignored at transformer position (only event-mutating fields apply).`),{type:"pass",config:e.config,push:async n=>{const o=await Te(n,t,e.collector);return!o.ignore&&{event:o.event}}}}return{type:"pass",config:e.config,push:e=>({event:e})}}),y=await m(h);void 0!==s.before&&void 0===y.config?.before&&(y.config={...y.config??{},before:s.before}),void 0!==s.next&&void 0===y.config?.next&&(y.config={...y.config??{},next:s.next}),void 0!==f&&void 0===y.config?.state&&(y.config={...y.config??{},state:f}),n[o]=y}return n}(r,e.transformers||{}),r}async function hn(e){e=e||{};const t=await gn(e),n=(o=t,{type:"elb",config:{},push:async(e,t,n,s,r)=>{if("string"==typeof e&&e.startsWith("walker ")){const n=e.replace("walker ","");return o.command(n,t)}let i;if("string"==typeof e)i={name:e},t&&"object"==typeof t&&!Array.isArray(t)&&(i.data=t);else{if(!e||"object"!=typeof e)return tn({ok:!1});i=e,t&&"object"==typeof t&&!Array.isArray(t)&&(i.data={...i.data||{},...t})}return n&&"object"==typeof n&&(i.context=n),s&&Array.isArray(s)&&(i.nested=s),r&&"object"==typeof r&&(i.custom=r),o.push(i)}});var o;t.sources.elb=n,await async function(e,t={}){const n={};for(const[o,s]of Object.entries(t)){const t=await Ot(e,o,s);if(!t)continue;const r=s.config?.require;t.config={...t.config,init:!1,...r?{require:[...r]}:{}},n[o]=t}Object.assign(e.sources,n);for(const t of Object.keys(n)){const n=e.sources[t];let o=!1;n.init&&await ce(n.init.bind(n),n=>{if(n instanceof ie)throw n;o=!0,e.status.failed++,e.logger.scope("source").error("source init failed",{sourceId:t,error:n})})(),o||(n.config.init=!0,xt(n)&&await It(e,n,t))}return await Ct(e),n}(t,e.sources||{});const{consent:s,user:r,globals:i,custom:a}=e;s&&await t.command("consent",s),r&&await t.command("user",r),i&&await t.command("globals",i),a&&await t.command("custom",a),t.config.run&&await t.command("run");let c=n.push;const u=Object.values(t.sources).filter(e=>"elb"!==e.type),l=u.find(e=>e.config.primary);return l?c=l.push:u.length>0&&(c=u[0].push),{collector:t,elb:c}}var mn=async e=>{let t;return{get flow(){return t},trigger:()=>async n=>{if(!t){const n=await hn(e);t={collector:n.collector,elb:n.elb}}const o=function(e){for(const t of Object.values(e.sources||{}))if("lambda"===t.type)return t}(t.collector);if(!o)throw new Error("Lambda source not found in collector");const s={awsRequestId:`test-${Date.now()}`},r=o.push,i=await r(n,s);let a;try{a=JSON.parse(i.body||"{}")}catch{a=i.body}const c={};if(i.headers)for(const[e,t]of Object.entries(i.headers))void 0!==t&&(c[e]=String(t));return{statusCode:i.statusCode,body:a,headers:c}}}};function yn(e){return async t=>{const n={...t};if(n.body&&"string"==typeof n.body){const e=JSON.parse(n.body);e.name&&!e.event&&(n.body=JSON.stringify({...e,event:e.name,name:void 0}))}return e.push(n,{awsRequestId:"test-req"})}}var vn={};t(vn,{createTrigger:()=>jn,env:()=>wn,step:()=>xn});var wn={};t(wn,{push:()=>qn,simulation:()=>In});var bn=()=>{},kn={error:bn,warn:bn,info:bn,debug:bn,throw:e=>{throw"string"==typeof e?new Error(e):e},json:bn,scope:()=>kn},Sn=()=>()=>Promise.resolve({ok:!0}),qn={get push(){return Sn()},get command(){return Sn()},get elb(){return Sn()},logger:kn},In=["AWS.SQSClient"],xn={};t(xn,{decoderText:()=>En,malformedJson:()=>Dn,orderComplete:()=>Cn,pageView:()=>On});var On={title:"Page view from SQS",description:"A standard SQS message body containing a walker elb event payload as JSON.",in:{MessageId:"m-1",Body:JSON.stringify({event:"page view",data:{title:"Documentation",url:"https://example.com/docs"}})},out:[["message.ack","m-1"]]},Cn={title:"Order complete from SQS",description:"Order complete event flowing through the long-poll loop.",in:{MessageId:"m-2",Body:JSON.stringify({event:"order complete",data:{id:"ORD-500",total:199.99,currency:"EUR"}})},out:[["message.ack","m-2"]]},En={title:"Text decoder",description:'When decoder is "text", the body string flows under data.payload.',in:{MessageId:"m-3",Body:"raw text payload"},out:[["message.ack","m-3"]]},Dn={title:"Malformed JSON nacks",description:"Default decoder is JSON. A malformed body throws DecoderError; the source nacks (skips DeleteMessage) so the message redelivers.",in:{MessageId:"m-4",Body:"{not json"},out:[["message.nack","m-4"]]};function Tn(e){if("object"!=typeof e||null===e)return!1;const t=e;return"sqs"===t.type&&"function"==typeof t.push}var jn=async e=>{let t;return{get flow(){return t},trigger:()=>async n=>{if(!t){const n=await hn(e);t={collector:n.collector,elb:n.elb}}const o=function(e){for(const t of Object.values(e.sources??{}))if(Tn(t))return t}(t.collector);if(!o)throw new Error("sqs source not registered in collector, ensure it is configured in sources");const s={MessageId:n.MessageId,Body:n.Body,ReceiptHandle:n.ReceiptHandle,Attributes:n.Attributes,MessageAttributes:n.MessageAttributes},r=await o.push(s),i=[];return r&&"object"==typeof r&&(r.acked&&i.push(["message.ack",n.MessageId]),r.nacked&&i.push(["message.nack",n.MessageId])),i}}};export{w as examples,n as schemas,vn as sqsExamples};//# sourceMappingURL=dev.mjs.map
|
package/dist/walkerOS.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walkeros/server-source-aws",
|
|
3
3
|
"description": "AWS server sources for walkerOS (Lambda, API Gateway, Function URLs)",
|
|
4
|
-
"version": "4.2.1
|
|
4
|
+
"version": "4.2.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@aws-sdk/client-sqs": "^3.952.0",
|
|
25
25
|
"@aws-sdk/client-sns": "^3.952.0",
|
|
26
|
-
"@walkeros/core": "4.2.1
|
|
26
|
+
"@walkeros/core": "4.2.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@types/aws-lambda": "^8.10.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/aws-lambda": "^8.10.159",
|
|
33
|
-
"@walkeros/collector": "4.2.1
|
|
33
|
+
"@walkeros/collector": "4.2.1"
|
|
34
34
|
},
|
|
35
35
|
"repository": {
|
|
36
36
|
"url": "git+https://github.com/elbwalker/walkerOS.git",
|