@walkeros/collector 4.1.2 → 4.1.3-next-1779963694449

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/types/code.ts","../src/constants.ts","../src/consent.ts","../src/collector.ts","../src/destination.ts","../src/observerEmit.ts","../src/on.ts","../src/pending.ts","../src/source.ts","../src/transformer.ts","../src/cache.ts","../src/buffers.ts","../src/handle.ts","../src/shutdown.ts","../src/push.ts","../src/command.ts","../src/store.ts","../src/cache-store.ts","../src/store-cache-wrapper.ts","../src/elb.ts","../src/flow.ts","../src/wrapEnv.ts"],"sourcesContent":["export * from './types';\n\nexport * from './constants';\n\nexport * from './consent';\nexport * from './flow';\nexport * from './push';\nexport * from './destination';\nexport * from './handle';\nexport * from './on';\nexport * from './source';\nexport {\n runTransformerChain,\n transformerPush,\n transformerInit,\n} from './transformer';\nexport { wrapEnv } from './wrapEnv';\nexport { getCacheStore } from './cache';\n","import type { Destination, Mapping, On, WalkerOS } from '@walkeros/core';\n\nexport interface Settings {\n scripts?: string[];\n init?: string;\n on?: string;\n push?: string;\n pushBatch?: string;\n}\n\nexport interface CodeMapping extends Mapping.Rule<CodeMapping> {\n push?: string;\n pushBatch?: string;\n}\n\nexport type Types = Destination.Types<Settings, CodeMapping>;\nexport type Config = Destination.Config<Types>;\nexport type Context = Destination.Context<Types>;\nexport type PushContext = Destination.PushContext<Types>;\nexport type PushBatchContext = Destination.PushBatchContext<Types>;\n\nexport type InitFn = (context: Context) => void;\nexport type OnFn = (type: On.Types, context: Context) => void;\nexport type PushFn = (event: WalkerOS.Event, context: PushContext) => void;\nexport type PushBatchFn = (\n batch: Destination.Batch<CodeMapping>,\n context: PushBatchContext,\n) => void;\n","import type { Collector } from '@walkeros/core';\nimport type { CommandTypes, StorageType } from './types/collector';\n\nexport const Commands: Record<CommandTypes, Collector.CommandType> = {\n Action: 'action',\n Actions: 'actions',\n Config: 'config',\n Consent: 'consent',\n Context: 'context',\n Custom: 'custom',\n Destination: 'destination',\n Elb: 'elb',\n Globals: 'globals',\n Hook: 'hook',\n Init: 'init',\n Link: 'link',\n On: 'on',\n Prefix: 'data-elb',\n Ready: 'ready',\n Run: 'run',\n Session: 'session',\n Shutdown: 'shutdown',\n User: 'user',\n Walker: 'walker',\n} as const;\n\nconst UtilsStorage: { [key: string]: StorageType } = {\n Cookie: 'cookie',\n Local: 'local',\n Session: 'session',\n} as const;\n\nconst Utils = {\n Storage: UtilsStorage,\n};\n\nexport const Const = {\n Commands,\n Utils,\n};\n\nexport default Const;\n","import type { Collector, WalkerOS } from '@walkeros/core';\nimport { assign } from '@walkeros/core';\n\n/**\n * Processes consent data: coerces to boolean, updates collector state.\n * Does NOT notify or process queues — caller handles that.\n */\nexport function processConsent(\n collector: Collector.Instance,\n data: WalkerOS.Consent,\n): { update: WalkerOS.Consent } {\n const update: WalkerOS.Consent = {};\n Object.entries(data).forEach(([name, granted]) => {\n update[name] = !!granted;\n });\n\n collector.consent = assign(collector.consent, update);\n\n return { update };\n}\n","import type { Collector, Logger, WalkerOS } from '@walkeros/core';\nimport { assign, createLogger } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations } from './destination';\nimport { initTransformers } from './transformer';\nimport { createPush } from './push';\nimport { createCommand } from './command';\nimport { initSources } from './source';\nimport { initStores, resolveStoreReferences } from './store';\nimport { createCacheStore } from './cache-store';\n\n// Replaced at build time by tsup's `define` (see packages/config/tsup).\ndeclare const __VERSION__: string;\n\nexport async function collector(\n initConfig: Collector.InitConfig,\n): Promise<Collector.Instance> {\n const defaultConfig: Collector.Config = {\n globalsStatic: {},\n sessionStatic: {},\n run: true,\n queueMax: 1_000,\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n // Create logger with config from initConfig\n const loggerConfig: Logger.Config = {\n level: initConfig.logger?.level,\n handler: initConfig.logger?.handler,\n };\n const logger = createLogger(loggerConfig);\n\n // Enhanced globals with static globals from config\n const finalGlobals = { ...config.globalsStatic, ...initConfig.globals };\n\n const collector: Collector.Instance = {\n allowed: false,\n config,\n consent: initConfig.consent || {},\n custom: initConfig.custom || {},\n destinations: {},\n transformers: {},\n stores: {},\n globals: finalGlobals,\n hooks: initConfig.hooks || {},\n observers: new Set(),\n logger,\n on: {},\n queue: [],\n round: 0,\n session: undefined,\n status: {\n startedAt: Date.now(),\n in: 0,\n out: 0,\n failed: 0,\n sources: {},\n destinations: {},\n dropped: {},\n },\n timing: Date.now(),\n user: initConfig.user || {},\n sources: {},\n pending: { destinations: {} },\n push: undefined as unknown as Collector.PushFn, // Placeholder, will be set below\n command: undefined as unknown as Collector.CommandFn, // Placeholder, will be set below\n };\n\n // Set the push and command functions with the collector reference\n collector.push = createPush(\n collector,\n (event: WalkerOS.DeepPartialEvent): WalkerOS.PartialEvent =>\n ({\n timing: Math.round((Date.now() - collector.timing) / 10) / 100,\n source: { type: 'collector', schema: '4', version: __VERSION__ },\n ...event,\n }) as WalkerOS.PartialEvent,\n );\n\n collector.command = createCommand(collector, commonHandleCommand);\n\n // Initialize stores (first - other components may depend on them)\n const rawStores = initConfig.stores || {};\n collector.stores = await initStores(collector, rawStores);\n\n // Resolve store references in component env values.\n // The bundler emits `$store.gcs` as a direct reference to `stores.gcs`\n // (the raw {code, config} definition). After initialization, replace\n // these raw references with the actual Store.Instance objects.\n resolveStoreReferences(rawStores, collector.stores, initConfig);\n\n // Create default cache store for steps that use cache without explicit store.\n // Uses LRU + entry cap + batched eviction + active TTL sweep. See\n // `cache-store.ts` for the full semantics.\n if (!collector.stores.__cache) {\n collector.stores.__cache = createCacheStore();\n }\n\n // Initialize destinations after collector is fully created\n // Sources are initialized in startFlow after ELB source is created\n collector.destinations = await initDestinations(\n collector,\n initConfig.destinations || {},\n );\n\n // Initialize transformers\n collector.transformers = await initTransformers(\n collector,\n initConfig.transformers || {},\n );\n\n return collector;\n}\n","import type {\n Cache,\n Collector,\n WalkerOS,\n Elb,\n Destination,\n Transformer,\n Ingest,\n} from '@walkeros/core';\nimport {\n assign,\n buildCacheContext,\n clone,\n compileCache,\n checkCache,\n storeCache,\n createIngest,\n debounce,\n emitStep,\n getId,\n getGrantedConsent,\n getNextSteps,\n isDefined,\n isFunction,\n isObject,\n processEventMapping,\n stepId,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { buildBaseState } from './observerEmit';\nimport { callDestinationOn } from './on';\nimport {\n runTransformerChain,\n walkChain,\n extractTransformerNextMap,\n extractChainProperty,\n} from './transformer';\nimport { getCacheStore } from './cache';\nimport { pushBounded, resetOverflowFlag, warnOverflowOnce } from './buffers';\n\nconst DEFAULT_QUEUE_MAX = 1_000;\nconst DEFAULT_DLQ_MAX = 100;\n/** Default upper-bound on entries per batch. Caps unbounded growth under sustained load. */\nconst DEFAULT_BATCH_SIZE = 1_000;\n/** Default upper-bound on batch age in ms. Forces flush even if debounce keeps resetting. */\nconst DEFAULT_BATCH_AGE = 30_000;\n\n/**\n * Sentinel returned by {@link destinationPush} when an event was enqueued\n * into a batch (not delivered synchronously). The aggregation pass in\n * {@link pushToDestinations} reads this to skip the per-event `count`\n * increment; counters are bumped by the flush callback instead, after\n * `pushBatch` resolves. Per PROD-004 plan Q9: increment on successful\n * flush per entry, not on enqueue.\n */\nconst BATCHED_RESULT: { batched: true } = Object.freeze({ batched: true });\n\nfunction isBatchedResult(value: unknown): boolean {\n return value === BATCHED_RESULT;\n}\n\n/**\n * Normalize a batch config value to the canonical `{ wait?, size?, age? }`\n * shape. A bare number is treated as `wait` (legacy form). `undefined`\n * normalizes to an empty object so callers can chain `??` lookups.\n */\nfunction normalizeBatchOptions(\n value: number | Destination.BatchOptions | undefined,\n): { wait?: number; size?: number; age?: number } {\n if (value === undefined) return {};\n if (typeof value === 'number') return { wait: value };\n return { wait: value.wait, size: value.size, age: value.age };\n}\n\n/**\n * Ensure a per-destination status entry exists and return it.\n * Mirrors the shape used elsewhere in this file.\n */\nfunction ensureDestStatus(\n collector: Collector.Instance,\n destId: string,\n): Collector.DestinationStatus {\n if (!collector.status.destinations[destId]) {\n collector.status.destinations[destId] = {\n count: 0,\n failed: 0,\n duration: 0,\n queuePushSize: 0,\n dlqSize: 0,\n };\n }\n return collector.status.destinations[destId];\n}\n\n/**\n * Bump a drop counter under `status.dropped[stepId][buffer]`. Lazily\n * creates the per-step entry; returns the new counter value so callers\n * can pass it straight into the warn-once log payload.\n */\nfunction bumpDropped(\n status: Collector.Status,\n id: string,\n buffer: 'queue' | 'dlq',\n n: number,\n): number {\n if (!status.dropped[id]) status.dropped[id] = {};\n const entry = status.dropped[id];\n entry[buffer] = (entry[buffer] ?? 0) + n;\n return entry[buffer]!;\n}\n\n/**\n * Resolves transformer chain for a destination.\n *\n * `getNextSteps` returns the immediate next-step ids for the given Route in\n * the supplied context. `walkChain` then follows static `.next` links from\n * each entry to produce the full ordered chain. The WeakMap inside\n * `getNextSteps` caches the compiled form, so we don't re-compile per event.\n *\n * post-collector destination.before disallows `many` (enforced at the schema\n * layer via `RouteWithoutManySchema`), so we never see more than one id here\n * unless a user passes an explicit string[] chain — in which case we want to\n * treat it as the explicit chain (no further walking).\n *\n * `transformerNextMap` is computed once per `pushToDestinations` call (it depends\n * only on `collector.transformers`) and passed in to avoid rebuilding it for\n * every destination's before and next chain resolution.\n */\nfunction resolveDestinationChain(\n before: Transformer.Route | undefined,\n transformerNextMap: ReturnType<typeof extractTransformerNextMap>,\n ingest?: Ingest,\n): string[] {\n if (!before) return [];\n // Static string[] chains pass through unchanged — they are explicit and\n // suppress `.next` walking. Static single-string starts are walked.\n if (\n Array.isArray(before) &&\n before.every((entry) => typeof entry === 'string')\n ) {\n return walkChain(before, transformerNextMap);\n }\n if (typeof before === 'string') {\n return walkChain(before, transformerNextMap);\n }\n // Conditional shape — resolve per-event, walk single-id result.\n const ids = getNextSteps(before, buildCacheContext(ingest));\n if (ids.length === 0) return [];\n if (ids.length === 1) return walkChain(ids[0], transformerNextMap);\n // Multiple ids from a conditional shape: treat as explicit chain.\n // (destination.before disallows `many`; this path is reached only if a\n // RouteConfig.next resolves to a string[], which is then the user's\n // declared chain.)\n return walkChain(ids, transformerNextMap);\n}\n\n/**\n * Adds a new destination to the collector.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The destination's init data.\n * @returns The result of the push operation.\n */\nexport async function addDestination(\n collector: Collector.Instance,\n data: Destination.Init,\n): Promise<Elb.PushResult> {\n const { code, config: dataConfig = {}, env = {}, before, next, cache } = data;\n\n // Validate that code has a push method\n if (!isFunction(code.push)) {\n return createPushResult({\n ok: false,\n failed: {\n invalid: {\n type: 'invalid',\n error: 'Destination code must have a push method',\n },\n },\n });\n }\n\n const baseConfig = dataConfig || { init: false };\n // Merge before, next, and cache into config if provided at root level\n let config = before ? { ...baseConfig, before } : { ...baseConfig };\n if (next) config = { ...config, next };\n if (cache) config = { ...config, cache };\n\n const destination: Destination.Instance = {\n ...code,\n config,\n env: mergeEnvironments(code.env, env),\n };\n\n let id = destination.config.id; // Use given id\n if (!id) {\n // Generate a new id if none was given (lowercase alpha only for readability)\n do {\n id = getId(5, 'abcdefghijklmnopqrstuvwxyz');\n } while (collector.destinations[id]);\n }\n\n // Add the destination\n collector.destinations[id] = destination;\n\n // Process previous events if not disabled\n if (destination.config.queue !== false)\n destination.queuePush = [...collector.queue];\n\n return pushToDestinations(collector, undefined, {}, { [id]: destination });\n}\n\n/**\n * Pushes an event to all or a subset of destinations.\n *\n * @param collector - The walkerOS collector instance.\n * @param event - The event to push.\n * @param meta - Optional metadata with id and ingest.\n * @param destinations - The destinations to push to.\n * @returns The result of the push operation.\n */\nexport async function pushToDestinations(\n collector: Collector.Instance,\n event?: WalkerOS.Event,\n meta: {\n id?: string;\n ingest?: Ingest;\n respond?: import('@walkeros/core').RespondFn;\n } = {},\n destinations?: Collector.Destinations,\n): Promise<Elb.PushResult> {\n const { allowed, consent, globals, user } = collector;\n\n // Check if collector is allowed to push\n if (!allowed) return createPushResult({ ok: false });\n\n // Add event to the collector queue (bounded; FIFO drop-oldest on overflow)\n if (event) {\n const queueMax = collector.config.queueMax;\n if (queueMax === undefined) {\n throw new Error(\n 'Collector.Config.queueMax is undefined; defaults must be seeded by collector()',\n );\n }\n const result = pushBounded(collector.queue, event, { max: queueMax });\n if (result.dropped > 0) {\n const droppedCount = bumpDropped(\n collector.status,\n stepId('collector'),\n 'queue',\n result.dropped,\n );\n warnOverflowOnce(\n collector.queue,\n collector.logger,\n 'collector.queue overflow; oldest events dropped',\n {\n buffer: 'queue',\n cap: queueMax,\n droppedCount,\n },\n );\n } else if (collector.queue.length < queueMax) {\n resetOverflowFlag(collector.queue);\n }\n collector.status.in++;\n }\n\n // Use given destinations or use internal destinations\n if (!destinations) destinations = collector.destinations;\n\n // Precompute the transformer next map once per push (shared across all\n // destinations in this batch, used for both before and next chain resolution).\n // Guarded because tests and partially-initialized collectors may pass\n // `transformers` as undefined.\n const transformerNextMap = collector.transformers\n ? extractTransformerNextMap(collector.transformers)\n : {};\n\n const results = await Promise.all(\n // Process all destinations in parallel\n Object.entries(destinations || {}).map(async ([id, destination]) => {\n // Disabled destinations are completely skipped — no queuing, no init, no processing\n if (destination.config.disabled) {\n return { id, destination, skipped: true };\n }\n\n // Queued events: refresh consent (full replace — stale consent must not persist).\n // User/globals merge happens for all events below in allowedEvents.map.\n let currentQueue = (destination.queuePush || []).map((event) => ({\n ...event,\n consent,\n }));\n destination.queuePush = [];\n\n // Current event: added as-is (consent is already fresh from createEvent).\n if (event) currentQueue.push(clone(event));\n\n // Clone ingest for this destination (prevents cross-destination races in Promise.all)\n const destIngest: Ingest = meta.ingest\n ? {\n ...meta.ingest,\n _meta: { ...meta.ingest._meta, path: [...meta.ingest._meta.path] },\n }\n : createIngest('unknown');\n\n // If no events and no queued on events, skip this destination\n if (!currentQueue.length && !destination.queueOn?.length) {\n return { id, destination, skipped: true };\n }\n\n // If only on events queued (no push events), still init to flush queueOn.\n // Direct try/catch + logger.error here is intentional. Previously this\n // used tryCatchAsync(destinationInit) without an onError callback, which\n // silently returned undefined when init threw, hiding real failures on\n // the queueOn-only path. Mirrors the same pattern used below at the main\n // init call site so failures are never silent on either branch.\n if (!currentQueue.length && destination.queueOn?.length) {\n let isInitialized = false;\n try {\n isInitialized = await destinationInit(collector, destination, id);\n } catch (err) {\n collector.status.failed++;\n const destType = destination.type || 'unknown';\n collector.logger.scope(destType).error('destination init failed', {\n error: err instanceof Error ? err.message : String(err),\n });\n }\n return { id, destination, skipped: !isInitialized };\n }\n\n const allowedEvents: WalkerOS.Events = [];\n const skippedEvents = currentQueue.filter((queuedEvent) => {\n const grantedConsent = getGrantedConsent(\n destination.config.consent, // Required\n consent, // Current collector state\n queuedEvent.consent, // Individual event state\n );\n\n if (grantedConsent) {\n queuedEvent.consent = grantedConsent; // Save granted consent states only\n\n allowedEvents.push(queuedEvent); // Add to allowed queue\n return false; // Remove from destination queue\n }\n\n // Emit a skip state for the consent-denied event so observers can\n // see the gate decision per-event.\n const skipState = buildBaseState(collector, {\n stepId: stepId('destination', id),\n stepType: 'destination',\n phase: 'skip',\n eventId: typeof queuedEvent.id === 'string' ? queuedEvent.id : '',\n now: Date.now(),\n });\n skipState.skipReason = 'consent';\n if (consent) skipState.consent = { ...consent };\n if (destination.config.consent) {\n skipState.meta = { required: { ...destination.config.consent } };\n }\n emitStep(collector, skipState);\n\n return true; // Keep denied events in the queue\n });\n\n // Add skipped (consent-denied) events back to the queue.\n // Bounded; FIFO drop-oldest on overflow.\n if (skippedEvents.length > 0) {\n const queuePush = destination.queuePush;\n const destId = destination.config.id || id;\n const bound = {\n max: destination.config.queueMax ?? DEFAULT_QUEUE_MAX,\n };\n let totalDropped = 0;\n for (const skipped of skippedEvents) {\n const r = pushBounded(queuePush, skipped, bound);\n totalDropped += r.dropped;\n }\n if (totalDropped > 0) {\n // Ensure status entry exists for early-overflow paths.\n ensureDestStatus(collector, destId);\n const droppedCount = bumpDropped(\n collector.status,\n stepId('destination', destId),\n 'queue',\n totalDropped,\n );\n warnOverflowOnce(\n queuePush,\n collector.logger.scope(destination.type || 'unknown'),\n 'destination.queuePush overflow; oldest events dropped',\n {\n buffer: 'queuePush',\n destination: destId,\n cap: bound.max,\n droppedCount,\n },\n );\n } else if (queuePush.length < bound.max) {\n resetOverflowFlag(queuePush);\n }\n }\n\n // Execution shall not pass if no events are allowed\n if (!allowedEvents.length) {\n return { id, destination, queue: currentQueue }; // Don't push if not allowed\n }\n\n // Initialize the destination if needed.\n // Direct try/catch + logger.error here is intentional. Previously this\n // used tryCatchAsync(destinationInit) without an onError callback, which\n // silently returned undefined when init threw, hiding real failures. The\n // destination itself may also log a more specific error before throwing;\n // this is the boundary safety net so failures are never silent.\n let isInitialized = false;\n try {\n isInitialized = await destinationInit(collector, destination, id);\n } catch (err) {\n collector.status.failed++;\n const destType = destination.type || 'unknown';\n collector.logger.scope(destType).error('destination init failed', {\n error: err instanceof Error ? err.message : String(err),\n });\n }\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error: unknown;\n let response: unknown;\n if (!destination.dlq) destination.dlq = [];\n\n // Resolve the before chain once per destination batch (the per-event\n // resolution inside getNextSteps is WeakMap-cached, so this is cheap).\n const before = destination.config.before;\n const postChain = resolveDestinationChain(\n before,\n transformerNextMap,\n destIngest,\n );\n\n // Capture the next chain config; resolution happens per-event below.\n const nextConfig = destination.config.next;\n\n // Compile destination cache once per batch (not per-event).\n // Destination caches operate on events (HIT/MISS keyed by event fields),\n // so the rule shape is always EventCacheRule, not StoreCacheRule.\n const destCacheConfig = destination.config?.cache as\n | Cache.Cache<Cache.EventCacheRule>\n | undefined;\n const compiledDCache = destCacheConfig\n ? compileCache(destCacheConfig)\n : undefined;\n const dCacheStore = compiledDCache\n ? getCacheStore(compiledDCache, collector)\n : undefined;\n\n // Process allowed events and store failed ones in the dead letter queue (DLQ)\n let totalDuration = 0;\n // Count of events enqueued into a batch in this pass; the aggregation\n // below uses this to skip the synchronous `count++` for batched events\n // (counters move to the flush callback per PROD-004 plan Q9).\n let batchedCount = 0;\n await Promise.all(\n allowedEvents.map(async (event) => {\n // Merge collector state into event (collector as base, event overrides)\n event.globals = assign(globals, event.globals);\n event.user = assign(user, event.user);\n\n // Full cache check: before the before chain (skips everything on HIT)\n let cacheMiss: { key: string; ttl: number } | undefined;\n if (compiledDCache?.stop && dCacheStore) {\n const cacheContext = buildCacheContext(destIngest, event);\n const cacheResult = await checkCache(\n compiledDCache,\n dCacheStore,\n cacheContext,\n );\n if (cacheResult?.status === 'HIT') {\n return event; // Skip before chain + push\n }\n if (cacheResult?.status === 'MISS') {\n cacheMiss = { key: cacheResult.key, ttl: cacheResult.rule.ttl };\n }\n }\n\n // Run post-collector transformer chain if configured for this destination\n let processedEvent: WalkerOS.Event | null = event;\n let destRespond = meta.respond;\n if (\n postChain.length > 0 &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const chainResult = await runTransformerChain(\n collector,\n collector.transformers,\n postChain,\n event,\n destIngest,\n meta.respond,\n `destination.${id}.before`,\n );\n\n if (chainResult.event === null) {\n // Chain stopped - skip this event for this destination\n return event;\n }\n\n // Update respond if the chain produced a wrapped one\n if (chainResult.respond) destRespond = chainResult.respond;\n\n // Use the processed event (cast back to full Event type)\n // Before chains use first result if fan-out occurred\n processedEvent = (\n Array.isArray(chainResult.event)\n ? chainResult.event[0]\n : chainResult.event\n ) as WalkerOS.Event;\n }\n\n // Step-level cache check: after before chain, skip only push on HIT\n if (compiledDCache && !compiledDCache.stop && dCacheStore) {\n const cacheContext = buildCacheContext(destIngest, processedEvent);\n const cacheResult = await checkCache(\n compiledDCache,\n dCacheStore,\n cacheContext,\n );\n if (cacheResult?.status === 'HIT') {\n return event; // Skip push — deduplicated\n }\n if (cacheResult?.status === 'MISS') {\n cacheMiss = { key: cacheResult.key, ttl: cacheResult.rule.ttl };\n }\n }\n\n const pushStart = Date.now();\n let pushFailed = false;\n const result = await tryCatchAsync(destinationPush, (err) => {\n // Log the error with destination scope\n const destType = destination.type || 'unknown';\n collector.logger.scope(destType).error('Push failed', {\n error: err,\n event: processedEvent!.name,\n });\n error = err; // oh no\n pushFailed = true;\n\n // Add failed event to destinations DLQ (bounded; FIFO drop-oldest)\n const dlq = destination.dlq!;\n const destId = destination.config.id || id;\n const dlqBound = {\n max: destination.config.dlqMax ?? DEFAULT_DLQ_MAX,\n };\n const dlqResult = pushBounded(\n dlq,\n [processedEvent!, err],\n dlqBound,\n );\n if (dlqResult.dropped > 0) {\n ensureDestStatus(collector, destId);\n const droppedCount = bumpDropped(\n collector.status,\n stepId('destination', destId),\n 'dlq',\n dlqResult.dropped,\n );\n warnOverflowOnce(\n dlq,\n collector.logger.scope(destination.type || 'unknown'),\n 'destination.dlq overflow; oldest entries dropped',\n {\n buffer: 'dlq',\n destination: destId,\n cap: dlqBound.max,\n droppedCount,\n },\n );\n } else if (dlq.length < dlqBound.max) {\n resetOverflowFlag(dlq);\n }\n\n return undefined;\n })(\n collector,\n destination,\n id,\n processedEvent!,\n destIngest,\n destRespond,\n );\n totalDuration += Date.now() - pushStart;\n\n // Destination cache MISS: store the push result after attempt\n if (\n cacheMiss &&\n dCacheStore &&\n destination.config.mock === undefined\n ) {\n storeCache(\n dCacheStore,\n cacheMiss.key,\n result ?? true,\n cacheMiss.ttl,\n );\n }\n\n // Capture the last response (for single event pushes).\n // Batched-enqueue sentinel is NOT a real response; don't surface it.\n if (result !== undefined && !isBatchedResult(result)) {\n response = result;\n }\n if (isBatchedResult(result)) batchedCount++;\n\n // Run destination.next chain after successful push\n if (!pushFailed && nextConfig) {\n // Write push response to ingest for destination.next transformers\n if (result !== undefined) {\n destIngest._response = result;\n }\n\n const nextChain = resolveDestinationChain(\n nextConfig,\n transformerNextMap,\n destIngest,\n );\n\n if (\n nextChain.length > 0 &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const nextResult = await runTransformerChain(\n collector,\n collector.transformers,\n nextChain,\n processedEvent!,\n destIngest,\n destRespond,\n `destination.${id}.next`,\n );\n if (nextResult.respond) destRespond = nextResult.respond;\n }\n }\n\n return event;\n }),\n );\n\n return {\n id,\n destination,\n error,\n response,\n totalDuration,\n batchedCount,\n allowedCount: allowedEvents.length,\n };\n }),\n );\n\n // Build result objects\n const done: Record<string, Destination.Ref> = {};\n const queued: Record<string, Destination.Ref> = {};\n const failed: Record<string, Destination.Ref> = {};\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n const ref: Destination.Ref = {\n type: destination.type || 'unknown',\n data: result.response, // Capture push() return value\n };\n\n // Ensure destination status entry exists\n ensureDestStatus(collector, result.id);\n const destStatus = collector.status.destinations[result.id];\n const now = Date.now();\n\n // Refresh point-in-time buffer sizes after the destination's push pass.\n destStatus.queuePushSize = destination.queuePush?.length ?? 0;\n destStatus.dlqSize = destination.dlq?.length ?? 0;\n\n if (result.error) {\n ref.error = result.error;\n failed[result.id] = ref;\n destStatus.failed++;\n destStatus.lastAt = now;\n destStatus.duration += result.totalDuration || 0;\n collector.status.failed++;\n } else if (result.queue && result.queue.length) {\n // Events already re-queued at destination.queuePush via skippedEvents push\n queued[result.id] = ref;\n } else {\n // If every allowed event was enqueued into a batch, success counters\n // belong to the flush callback (PROD-004 plan Q9): don't increment\n // here and don't mark `done`. The flush bumps `count` and `out` when\n // pushBatch resolves. If only some events were batched, count the\n // synchronously-delivered ones.\n const batchedCount = result.batchedCount ?? 0;\n const allowedCount = result.allowedCount ?? 0;\n const syncDelivered = Math.max(0, allowedCount - batchedCount);\n if (syncDelivered > 0 || allowedCount === 0) {\n done[result.id] = ref;\n // For non-batched destinations preserve the historical semantics\n // (one bump per pushToDestinations call, regardless of allowed\n // events count, since the original code only bumped once).\n destStatus.count++;\n destStatus.lastAt = now;\n destStatus.duration += result.totalDuration || 0;\n collector.status.out++;\n }\n }\n }\n\n return createPushResult({\n event,\n ...(Object.keys(done).length && { done }),\n ...(Object.keys(queued).length && { queued }),\n ...(Object.keys(failed).length && { failed }),\n });\n}\n\n/**\n * Initializes a destination.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to initialize.\n * @param destId - The destination ID.\n * @returns Whether the destination was initialized successfully.\n */\nexport async function destinationInit<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n destId: string,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n // Create scoped logger for this destination: [type:id] or [unknown:id]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context: Destination.Context = {\n collector,\n logger: destLogger,\n id: destId,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n destLogger.debug('init');\n\n const initStarted = Date.now();\n emitStep(\n collector,\n buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'init',\n eventId: '',\n now: initStarted,\n }),\n );\n\n let configResult;\n try {\n configResult = await useHooks(\n destination.init,\n 'DestinationInit',\n collector.hooks,\n collector.logger,\n )(context);\n } catch (err) {\n const initErrFinished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'error',\n eventId: '',\n now: initErrFinished,\n });\n errState.durationMs = initErrFinished - initStarted;\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n\n // Actively check for errors (when false)\n if (configResult === false) return configResult; // don't push if init is false\n\n // Update the destination config if it was returned\n destination.config = {\n ...(configResult || destination.config),\n init: true, // Remember that the destination was initialized\n };\n\n // Flush queued on() events now that destination is initialized\n if (destination.queueOn?.length) {\n const queueOn = destination.queueOn;\n destination.queueOn = [];\n\n for (const { type, data } of queueOn) {\n callDestinationOn(collector, destination, destId, type, data);\n }\n }\n\n destLogger.debug('init done');\n }\n\n return true; // Destination is ready to push\n}\n\n/**\n * Pushes an event to a single destination.\n * Handles mapping, batching, and consent checks.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to push to.\n * @param destId - The destination ID.\n * @param event - The event to push.\n * @param ingest - Mutable ingest context flowing through the pipeline.\n * @returns Whether the event was pushed successfully.\n */\nexport async function destinationPush<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n destId: string,\n event: WalkerOS.Event,\n ingest?: Ingest,\n respond?: import('@walkeros/core').RespondFn,\n): Promise<unknown> {\n const { config } = destination;\n\n const processed = await processEventMapping(event, config, collector);\n\n if (processed.ignore) return false;\n\n // Create scoped logger for this destination: [type] or [unknown]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context: Destination.PushContext = {\n collector,\n logger: destLogger,\n id: destId,\n config,\n data: processed.data,\n rule: processed.mapping,\n ingest: ingest!,\n env: {\n ...mergeEnvironments(destination.env, config.env),\n ...(respond ? { respond } : {}),\n },\n };\n\n // Mock interception — replaces the actual destination.push() call\n if (config.mock !== undefined) {\n destLogger.debug('mock', { event: processed.event.name });\n return config.mock;\n }\n\n const eventMapping = processed.mapping;\n const mappingKey = processed.mappingKey || '* *';\n\n if (\n eventMapping?.batch &&\n destination.pushBatch &&\n config.mock === undefined\n ) {\n // Initialize batch registry on destination (not on shared mapping config)\n destination.batches = destination.batches || {};\n\n // Get or create batch state for this mapping key\n if (!destination.batches[mappingKey]) {\n const batched: Destination.Batch<unknown> = {\n key: mappingKey,\n entries: [],\n events: [],\n data: [],\n };\n\n // Resolve scheduling options: mapping-level overrides destination-level.\n // Mapping rule `batch` (number form = wait; object = wait/size/age).\n // Destination config `batch` (number = wait; object = wait/size/age).\n const ruleOpts = normalizeBatchOptions(eventMapping.batch);\n const destOpts = normalizeBatchOptions(config.batch);\n const wait =\n ruleOpts.wait ??\n destOpts.wait ??\n // No wait at either layer means \"rely on size/age only\"; pick a\n // long debounce so wait is effectively never the trigger.\n DEFAULT_BATCH_AGE;\n const size = ruleOpts.size ?? destOpts.size ?? DEFAULT_BATCH_SIZE;\n const age = ruleOpts.age ?? destOpts.age ?? DEFAULT_BATCH_AGE;\n\n // Capture references the flush closure needs. ingest, respond, and\n // per-event eventMapping are read from `entries`, NOT from this scope,\n // so the closure does NOT leak the first event's context.\n const baseEnv = mergeEnvironments(destination.env, config.env);\n\n const flushBatch = async (): Promise<void> => {\n const batchState = destination.batches![mappingKey];\n const currentBatched = batchState.batched;\n if (currentBatched.entries.length === 0) return;\n\n const snapshot: Destination.Batch<unknown> = {\n key: currentBatched.key,\n entries: currentBatched.entries,\n events: currentBatched.events,\n data: currentBatched.data,\n };\n currentBatched.entries = [];\n currentBatched.events = [];\n currentBatched.data = [];\n\n const rep = snapshot.entries[0];\n const batchContext: Destination.PushBatchContext = {\n collector,\n logger: destLogger,\n id: destId,\n config,\n data: undefined,\n rule: rep.rule,\n ingest: rep.ingest!,\n env: {\n ...baseEnv,\n ...(rep.respond ? { respond: rep.respond } : {}),\n },\n };\n\n destLogger.debug('push batch', { events: snapshot.entries.length });\n\n const destIdResolved = destination.config.id || destId;\n const destStatus = ensureDestStatus(collector, destIdResolved);\n\n const flushStarted = Date.now();\n const flushState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'flush',\n eventId: '',\n now: flushStarted,\n });\n flushState.batch = { size: snapshot.entries.length, index: 0 };\n emitStep(collector, flushState);\n\n let succeeded = true;\n await tryCatchAsync(\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n collector.hooks,\n collector.logger,\n ),\n (err) => {\n succeeded = false;\n const errFinished = Date.now();\n const batchErrState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'error',\n eventId: '',\n now: errFinished,\n });\n batchErrState.durationMs = errFinished - flushStarted;\n batchErrState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n batchErrState.batch = {\n size: snapshot.entries.length,\n index: 0,\n };\n emitStep(collector, batchErrState);\n // Defect 2 fix: route the entire batch to DLQ on failure.\n const dlq = (destination.dlq = destination.dlq || []);\n const dlqBound = {\n max: destination.config.dlqMax ?? DEFAULT_DLQ_MAX,\n };\n let totalDropped = 0;\n for (const entry of snapshot.entries) {\n const r = pushBounded(dlq, [entry.event, err], dlqBound);\n totalDropped += r.dropped;\n }\n if (totalDropped > 0) {\n const droppedCount = bumpDropped(\n collector.status,\n stepId('destination', destIdResolved),\n 'dlq',\n totalDropped,\n );\n warnOverflowOnce(\n dlq,\n destLogger,\n 'destination.dlq overflow; oldest entries dropped',\n {\n buffer: 'dlq',\n destination: destIdResolved,\n cap: dlqBound.max,\n droppedCount,\n },\n );\n } else if (dlq.length < dlqBound.max) {\n resetOverflowFlag(dlq);\n }\n destStatus.failed += snapshot.entries.length;\n destStatus.dlqSize = dlq.length;\n collector.status.failed += snapshot.entries.length;\n destLogger.error('Push batch failed', {\n error: err instanceof Error ? err.message : String(err),\n entries: snapshot.entries.length,\n });\n return undefined;\n },\n )(snapshot, batchContext);\n\n destLogger.debug('push batch done');\n\n // Decrement in-flight regardless of outcome.\n destStatus.inFlightBatch = Math.max(\n 0,\n (destStatus.inFlightBatch ?? 0) - snapshot.entries.length,\n );\n\n if (succeeded) {\n destStatus.count += snapshot.entries.length;\n destStatus.lastAt = Date.now();\n collector.status.out += snapshot.entries.length;\n }\n };\n\n const scheduler = debounce(flushBatch, {\n wait,\n size,\n age,\n });\n\n destination.batches[mappingKey] = {\n batched,\n batchFn: () => {\n void scheduler();\n },\n flush: async () => {\n await scheduler.flush();\n },\n };\n }\n\n // Add per-event entry into the batch.\n const batchState = destination.batches[mappingKey];\n batchState.batched.entries.push({\n event: processed.event,\n ingest,\n respond,\n rule: eventMapping,\n data: processed.data,\n });\n batchState.batched.events.push(processed.event);\n if (isDefined(processed.data)) batchState.batched.data.push(processed.data);\n\n // In-flight bookkeeping for operational visibility.\n const destIdResolved = destination.config.id || destId;\n const destStatus = ensureDestStatus(collector, destIdResolved);\n destStatus.inFlightBatch = (destStatus.inFlightBatch ?? 0) + 1;\n\n // Trigger debounced batch (also handles size/age caps internally).\n batchState.batchFn();\n\n // Signal \"enqueued to batch, not delivered\" so the aggregation pass\n // in pushToDestinations skips the synchronous `count` increment.\n return BATCHED_RESULT;\n } else {\n destLogger.debug('push', { event: processed.event.name });\n\n // Emit a per-event observer pair around the destination.push call so\n // observers see the work this destination did for this event.\n const eventIdValue =\n typeof processed.event.id === 'string' ? processed.event.id : '';\n const pushStarted = Date.now();\n const inState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'in',\n eventId: eventIdValue,\n now: pushStarted,\n });\n if (processed.mappingKey) inState.mappingKey = processed.mappingKey;\n if (processed.event.consent) {\n inState.consent = { ...processed.event.consent };\n }\n emitStep(collector, inState);\n\n try {\n // It's time to go to the destination's side now\n const response = await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n collector.logger,\n )(processed.event, context);\n\n const pushFinished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'out',\n eventId: eventIdValue,\n now: pushFinished,\n });\n outState.durationMs = pushFinished - pushStarted;\n outState.outEvent = response;\n if (processed.mappingKey) outState.mappingKey = processed.mappingKey;\n emitStep(collector, outState);\n\n destLogger.debug('push done');\n\n return response;\n } catch (err) {\n const pushFinished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'error',\n eventId: eventIdValue,\n now: pushFinished,\n });\n errState.durationMs = pushFinished - pushStarted;\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n if (processed.mappingKey) errState.mappingKey = processed.mappingKey;\n emitStep(collector, errState);\n throw err;\n }\n }\n}\n\n/**\n * Creates a standardized result object for push operations.\n *\n * @param partialResult - A partial result to merge with the default result.\n * @returns The push result.\n */\nexport function createPushResult(\n partialResult?: Partial<Elb.PushResult>,\n): Elb.PushResult {\n return {\n ok: !partialResult?.failed,\n ...partialResult,\n };\n}\n\n/**\n * Register a single destination from its init definition.\n * Merges code config, user config, and chain config.\n * Used by initDestinations and activatePending.\n */\nexport function registerDestination(\n def: Destination.Init,\n): Destination.Instance {\n const { code, config = {}, env = {}, cache } = def;\n const { config: configWithBefore } = extractChainProperty(def, 'before');\n const { config: configWithChains } = extractChainProperty(\n { ...def, config: configWithBefore },\n 'next',\n );\n const mergedConfig = { ...code.config, ...config, ...configWithChains };\n // Merge definition-level cache into config for runtime access\n if (cache) mergedConfig.cache = cache;\n const mergedEnv = mergeEnvironments(code.env, env);\n return { ...code, config: mergedConfig, env: mergedEnv };\n}\n\n/**\n * Initializes a map of destinations using ONLY the unified code/config/env pattern.\n * Does NOT call destination.init() - that happens later during push with proper consent checks.\n *\n * @param destinations - The destinations to initialize.\n * @param collector - The collector instance for destination init context.\n * @returns The initialized destinations.\n */\nexport async function initDestinations(\n collector: Collector.Instance,\n destinations: Destination.InitDestinations = {},\n): Promise<Collector.Destinations> {\n const result: Collector.Destinations = {};\n\n for (const [id, def] of Object.entries(destinations)) {\n if (def.config?.require?.length) {\n collector.pending.destinations[id] = def;\n continue;\n }\n result[id] = registerDestination(def);\n }\n\n return result;\n}\n\n/**\n * Merges destination environment with config environment\n * Config env takes precedence over destination env for overrides\n */\nexport function mergeEnvironments(\n destinationEnv?: Destination.Env,\n configEnv?: Destination.Env,\n): Destination.Env {\n // If neither environment exists, return empty object\n if (!destinationEnv && !configEnv) return {};\n\n // If only one exists, return it\n if (!configEnv) return destinationEnv!;\n if (!destinationEnv) return configEnv;\n\n // Both exist - merge objects with configEnv taking precedence\n if (isObject(destinationEnv) && isObject(configEnv)) {\n return { ...destinationEnv, ...configEnv };\n }\n\n // If they're not both objects, config env overrides destination env\n return configEnv;\n}\n","import type { Collector, FlowState } from '@walkeros/core';\nimport { emitStep } from '@walkeros/core';\n\nexport interface BuildBaseStateArgs {\n stepId: string;\n stepType: FlowState['stepType'];\n phase: FlowState['phase'];\n eventId: string;\n now: number;\n}\n\n/**\n * Build a `FlowState` carrying the six always-populated fields. Callers\n * fill in additional fields (consent, batch, error, meta, inEvent,\n * outEvent, mappingKey, durationMs) as relevant for the step site.\n *\n * `flowId` defaults to a literal `'default'` until flow-id wiring is\n * threaded through the collector instance. Treat as a forward-compatible\n * placeholder, not a final shape.\n */\nexport function buildBaseState(\n collector: Collector.Instance,\n args: BuildBaseStateArgs,\n): FlowState {\n const startedAt = collector.status.startedAt;\n return {\n flowId: 'default',\n stepId: args.stepId,\n stepType: args.stepType,\n phase: args.phase,\n eventId: args.eventId,\n timestamp: new Date(args.now).toISOString(),\n elapsedMs: args.now - startedAt,\n };\n}\n\n/**\n * Convenience wrapper: build the base state and fan out to observers in\n * one call. Returns no value; callers that need to add trailing fields\n * before observers see them should call `buildBaseState` + `emitStep`\n * directly instead.\n */\nexport function emit(\n collector: Collector.Instance,\n args: BuildBaseStateArgs,\n): void {\n emitStep(collector, buildBaseState(collector, args));\n}\n","import type { Collector, On, WalkerOS, Destination } from '@walkeros/core';\nimport { isArray, FatalError } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch, tryCatchAsync } from '@walkeros/core';\nimport { mergeEnvironments } from './destination';\nimport { activatePending } from './pending';\nimport { flushSourceQueueOn, isSourceStarted } from './source';\n\ntype OnCallbackKind =\n | 'destination'\n | 'generic'\n | 'source'\n | 'consent'\n | 'ready'\n | 'run'\n | 'session';\n\n/**\n * Log a thrown error from a user-supplied `on` callback.\n *\n * Category B (user code): visibility via the scoped 'on' logger only.\n * `status.failed` is reserved for pipeline failures and stays untouched\n * here so it remains a clean health signal.\n *\n * Rethrows `FatalError` to let runtime supervisors fail fast on explicit\n * abort signals. Both `tryCatch` and `tryCatchAsync` propagate throws\n * raised inside onError, so this rethrow surfaces at the caller.\n */\nfunction logOnCallbackError(\n collector: Collector.Instance,\n kind: OnCallbackKind,\n error: unknown,\n extra?: Record<string, unknown>,\n): void {\n if (error instanceof FatalError) throw error;\n collector.logger.scope('on').error('on callback failed', {\n kind,\n ...extra,\n error,\n });\n}\n\n/**\n * Build the unified On.Context passed to every subscription callback.\n * Mirrors the Mapping.Context posture: collector + scoped logger only.\n */\nfunction buildOnContext(\n collector: Collector.Instance,\n type: On.Types,\n): On.Context {\n return {\n collector,\n logger: collector.logger.scope('on').scope(String(type)),\n };\n}\n\n/**\n * Registers a callback for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to listen for.\n * @param option The callback function or an array of callback functions.\n */\nexport async function on(\n collector: Collector.Instance,\n type: On.Types,\n option: WalkerOS.SingleOrArray<On.Subscription>,\n) {\n const on = collector.on;\n const onType: Array<On.Subscription> = on[type] || [];\n const options = isArray(option) ? option : [option];\n\n options.forEach((option) => {\n onType.push(option);\n });\n\n // Update collector on state\n (on[type] as typeof onType) = onType;\n\n // Execute the on function directly\n fireCallbacks(collector, type, options);\n}\n\n/**\n * Calls a destination's on() handler with proper context.\n * Used by both onApply() for immediate calls and destinationInit() for flushing queued events.\n */\nexport function callDestinationOn(\n collector: Collector.Instance,\n destination: Destination.Instance,\n destId: string,\n type: On.Types,\n data: unknown,\n) {\n if (!destination.on) return;\n\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType).scope('on').scope(type);\n\n const context: Destination.Context = {\n collector,\n logger: destLogger,\n id: destId,\n config: destination.config,\n data: data as Destination.Data,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n tryCatch(destination.on, (err) =>\n logOnCallbackError(collector, 'destination', err, { destId, type }),\n )(type, context);\n}\n\n/**\n * Fire a set of registered `on` callbacks against current collector state.\n *\n * Used by both `on()` (when registering a new callback, to fire it against\n * current state) and `onApply()` (when dispatching a state-change command to\n * every registered callback of that type). Separating this from `onApply`\n * ensures `on()` does NOT trigger `onApply`'s source/destination broadcast,\n * which would cause infinite recursion if a source's `on` handler registers\n * another callback of the same type.\n */\nfunction fireCallbacks(\n collector: Collector.Instance,\n type: On.Types,\n options: Array<On.Subscription>,\n config?: unknown,\n): void {\n // Calculate context data once for all sources and destinations\n let contextData: unknown;\n\n switch (type) {\n case Const.Commands.Consent:\n contextData = config || collector.consent;\n break;\n case Const.Commands.Session:\n contextData = collector.session;\n break;\n case Const.Commands.User:\n contextData = config || collector.user;\n break;\n case Const.Commands.Custom:\n contextData = config || collector.custom;\n break;\n case Const.Commands.Globals:\n contextData = config || collector.globals;\n break;\n case Const.Commands.Config:\n contextData = config || collector.config;\n break;\n case Const.Commands.Ready:\n case Const.Commands.Run:\n default:\n contextData = undefined;\n break;\n }\n\n if (!options.length) return;\n\n switch (type) {\n case Const.Commands.Consent:\n onConsent(\n collector,\n options as Array<On.ConsentRule>,\n config as WalkerOS.Consent,\n );\n break;\n case Const.Commands.Ready:\n onReady(collector, options as Array<On.ReadyFn>);\n break;\n case Const.Commands.Run:\n onRun(collector, options as Array<On.RunFn>);\n break;\n case Const.Commands.Session:\n onSession(collector, options as Array<On.SessionFn>);\n break;\n default: {\n // Generic handler for user, custom, globals, config, and arbitrary events\n const ctx = buildOnContext(collector, type);\n options.forEach((func) => {\n if (typeof func === 'function') {\n tryCatch(func as On.GenericFn, (err) =>\n logOnCallbackError(collector, 'generic', err, { type }),\n )(contextData, ctx);\n }\n });\n break;\n }\n }\n}\n\n/**\n * Applies all registered callbacks for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to apply the callbacks for.\n * @param options The options for the callbacks.\n * @param config The consent configuration.\n */\nexport async function onApply(\n collector: Collector.Instance,\n type: On.Types,\n options?: Array<On.Subscription>,\n config?: unknown,\n): Promise<boolean> {\n // Use the optionally provided options\n let onConfig = options || [];\n\n if (!options) {\n // Get the collector on events\n onConfig = collector.on[type] || [];\n }\n\n // Calculate context data once for source/destination broadcast\n let contextData: unknown;\n\n switch (type) {\n case Const.Commands.Consent:\n contextData = config || collector.consent;\n break;\n case Const.Commands.Session:\n contextData = collector.session;\n break;\n case Const.Commands.User:\n contextData = config || collector.user;\n break;\n case Const.Commands.Custom:\n contextData = config || collector.custom;\n break;\n case Const.Commands.Globals:\n contextData = config || collector.globals;\n break;\n case Const.Commands.Config:\n contextData = config || collector.config;\n break;\n case Const.Commands.Ready:\n case Const.Commands.Run:\n default:\n contextData = undefined;\n break;\n }\n\n let vetoed = false;\n // Per-source require decrement + gated on() delivery.\n // Sources are not \"started\" until config.init === true AND config.require is empty.\n // Unstarted sources have their on() events queued in instance.queueOn\n // and replayed once they start.\n for (const [sourceId, source] of Object.entries(collector.sources)) {\n if (source.config.require?.length) {\n const idx = source.config.require.indexOf(type);\n if (idx !== -1) source.config.require.splice(idx, 1);\n }\n\n if (!source.on) continue;\n\n if (isSourceStarted(source)) {\n const result = await tryCatchAsync(source.on, (err) =>\n logOnCallbackError(collector, 'source', err, { sourceId, type }),\n )(type, contextData);\n if (result === false) vetoed = true;\n } else {\n source.queueOn = source.queueOn || [];\n source.queueOn.push({ type, data: contextData });\n }\n }\n\n Object.entries(collector.destinations).forEach(([destId, destination]) => {\n if (destination.on) {\n // Queue if destination not yet initialized\n if (!destination.config.init) {\n destination.queueOn = destination.queueOn || [];\n destination.queueOn.push({ type, data: contextData });\n return;\n }\n callDestinationOn(collector, destination, destId, type, contextData);\n }\n });\n\n // Sources whose require was just emptied AND init has run: flush their\n // queueOn now (the require-completing event was queued in the gated\n // branch above, so flushing here delivers it without losing ordering).\n for (const [sourceId, source] of Object.entries(collector.sources)) {\n if (isSourceStarted(source) && source.queueOn?.length) {\n await flushSourceQueueOn(collector, source, sourceId);\n }\n }\n\n // Activate pending destinations whose require conditions are met.\n // (Pending sources are gone — their require is tracked in source.config.require\n // and gated via queueOn above.)\n if (Object.keys(collector.pending.destinations).length > 0) {\n await activatePending(collector, type);\n }\n\n fireCallbacks(collector, type, onConfig, config);\n\n return !vetoed;\n}\n\nfunction onConsent(\n collector: Collector.Instance,\n onConfig: Array<On.ConsentRule>,\n currentConsent?: WalkerOS.Consent,\n): void {\n const consentState = currentConsent || collector.consent;\n const ctx = buildOnContext(collector, Const.Commands.Consent);\n\n onConfig.forEach((rule) => {\n // Execute every handler whose consent key is present in the current state.\n Object.keys(consentState)\n .filter((key) => key in rule)\n .forEach((key) => {\n tryCatch(rule[key], (err) =>\n logOnCallbackError(collector, 'consent', err, { key }),\n )(consentState, ctx);\n });\n });\n}\n\nfunction onReady(\n collector: Collector.Instance,\n onConfig: Array<On.ReadyFn>,\n): void {\n if (!collector.allowed) return;\n const ctx = buildOnContext(collector, Const.Commands.Ready);\n onConfig.forEach((func) => {\n tryCatch(func, (err) => logOnCallbackError(collector, 'ready', err))(\n undefined,\n ctx,\n );\n });\n}\n\nfunction onRun(collector: Collector.Instance, onConfig: Array<On.RunFn>): void {\n if (!collector.allowed) return;\n const ctx = buildOnContext(collector, Const.Commands.Run);\n onConfig.forEach((func) => {\n tryCatch(func, (err) => logOnCallbackError(collector, 'run', err))(\n undefined,\n ctx,\n );\n });\n}\n\nfunction onSession(\n collector: Collector.Instance,\n onConfig: Array<On.SessionFn>,\n): void {\n if (!collector.session) return;\n const ctx = buildOnContext(collector, Const.Commands.Session);\n onConfig.forEach((func) => {\n tryCatch(func, (err) => logOnCallbackError(collector, 'session', err))(\n collector.session,\n ctx,\n );\n });\n}\n","import type { Collector } from '@walkeros/core';\nimport { registerDestination } from './destination';\n\n/**\n * Activate pending destinations whose require conditions are met.\n * Called from onApply after each non-vetoed event.\n *\n * Mutates require arrays in place — removes the fulfilled event type.\n * When require is empty, registers and moves to active map.\n *\n * Re-entrancy safe: delete-before-init ensures nested calls see clean state.\n *\n * Sources are no longer pending — their lifecycle is tracked per-instance\n * via `Source.Config.init` and `Source.Instance.queueOn`. See on.ts.\n */\nexport async function activatePending(\n collector: Collector.Instance,\n type: string,\n): Promise<void> {\n for (const [id, def] of Object.entries(collector.pending.destinations)) {\n if (!collector.pending.destinations[id] || collector.destinations[id])\n continue;\n\n const require = def.config?.require;\n if (!require) continue;\n\n const idx = require.indexOf(type);\n if (idx === -1) continue;\n require.splice(idx, 1);\n\n if (require.length > 0) continue;\n\n delete collector.pending.destinations[id];\n const instance = registerDestination(def);\n if (instance.config.queue !== false) {\n instance.queuePush = [...collector.queue];\n }\n collector.destinations[id] = instance;\n }\n}\n","import type {\n Cache,\n Collector,\n Elb,\n Ingest,\n Source,\n WalkerOS,\n} from '@walkeros/core';\nimport type { RespondFn, RespondOptions } from '@walkeros/core';\nimport {\n createIngest,\n FatalError,\n getMappingValue,\n tryCatchAsync,\n getNextSteps,\n compileCache,\n checkCache,\n storeCache,\n applyUpdate,\n buildCacheContext,\n} from '@walkeros/core';\nimport {\n walkChain,\n extractTransformerNextMap,\n runTransformerChain,\n cloneIngest,\n} from './transformer';\n\n/**\n * A Route is \"static\" when it's a transformer-ID string or an array of\n * transformer-ID strings. Static routes can be resolved once at init and\n * walked synchronously; conditional shapes (RouteConfig, mixed arrays)\n * depend on per-event context and resolve via getNextSteps at dispatch.\n */\nfunction isStaticRoute(\n route: import('@walkeros/core').Transformer.Route | undefined,\n): route is string | string[] {\n if (typeof route === 'string') return true;\n if (\n Array.isArray(route) &&\n route.every((entry) => typeof entry === 'string')\n ) {\n return true;\n }\n return false;\n}\nimport { getCacheStore } from './cache';\n\n/**\n * Flush a source's queueOn buffer. Called when the source becomes \"started\"\n * (config.init === true AND config.require is empty/absent). Idempotent:\n * the buffer is cleared before iteration, so re-entry from within an `on`\n * handler does not re-fire the same items.\n *\n * A throw inside `source.on` is treated as a pipeline failure: log via the\n * scoped 'source' logger and increment `status.failed`. The flush itself\n * is walkerOS-orchestrated startup; the throw represents the source's\n * inability to consume a buffered state-change event.\n */\nexport async function flushSourceQueueOn(\n collector: Collector.Instance,\n source: Source.Instance,\n sourceId?: string,\n): Promise<void> {\n if (!source.on || !source.queueOn?.length) return;\n const queue = source.queueOn;\n source.queueOn = [];\n const id = sourceId || source.config?.id || 'unknown';\n for (const { type, data } of queue) {\n await tryCatchAsync(source.on, (err: unknown): undefined => {\n if (err instanceof FatalError) throw err;\n collector.status.failed++;\n collector.logger.scope('source').error('source on flush failed', {\n sourceId: id,\n type,\n error: err,\n });\n return undefined;\n })(type, data);\n }\n}\n\n/**\n * A source is \"started\" — eligible to receive on() events directly — when\n * its init has run and any require gate is satisfied.\n */\nexport function isSourceStarted(source: Source.Instance): boolean {\n return Boolean(source.config.init) && !source.config.require?.length;\n}\n\n/**\n * Initialize a single source. Extracted from the initSources loop body\n * so it can be reused by the pending-source activator.\n */\nexport async function initSource(\n collector: Collector.Instance,\n sourceId: string,\n sourceDefinition: Source.InitSource,\n): Promise<Source.Instance | undefined> {\n const {\n code,\n config = {},\n env = {},\n primary,\n next,\n before,\n cache,\n } = sourceDefinition;\n\n // Compile source cache config (if configured).\n // Source caches operate on events (request-scoped HIT/MISS keyed by event\n // fields), so the rule shape is always EventCacheRule, not StoreCacheRule.\n const sourceCacheConfig = cache as\n | Cache.Cache<Cache.EventCacheRule>\n | undefined;\n const compiledSourceCache = sourceCacheConfig\n ? compileCache({\n ...sourceCacheConfig,\n stop: sourceCacheConfig.stop ?? true,\n })\n : undefined;\n\n // Resolve transformer chain for this source.\n // Static (string / string[]) chains pre-walk at init (optimization).\n // Conditional shapes (case / gate) require per-request context — see wrappedPush.\n const staticPreChain = isStaticRoute(next)\n ? walkChain(next, extractTransformerNextMap(collector.transformers))\n : undefined;\n\n // Resolve before chain for this source (consent-exempt, pre-source preprocessing).\n const staticBeforeChain = isStaticRoute(before)\n ? walkChain(before, extractTransformerNextMap(collector.transformers))\n : undefined;\n\n // Terminal push: where the source pipeline ends. Defaults to\n // `collector.push`. Tests (and rare advanced consumers) may override by\n // passing `push` in the source's `env`; in that case the override\n // replaces the collector and receives the raw event with no pipeline\n // options. Per-scope ingest/respond is invisible to overriders by\n // design: overriders are responsible for their own pipeline shape.\n const userTerminalPush = (env as { push?: Collector.PushFn }).push;\n const terminalPush: Collector.PushFn = userTerminalPush ?? collector.push;\n const hasUserTerminalPush = Boolean(userTerminalPush);\n\n /**\n * Execute the source pipeline for a single push call. Operates ONLY on\n * the per-call `scope` parameter — never reads source-factory closure\n * variables for ingest/respond. The scope is the unit of cross-request\n * isolation.\n *\n * The function may mutate `scope.respond` (cache MISS wraps it to\n * intercept the cached value before forwarding). That mutation is\n * scope-local: a concurrent call with its own scope is unaffected.\n */\n const executePush = async (\n rawEvent: WalkerOS.DeepPartialEvent,\n options: Collector.PushOptions,\n scope: { ingest: Ingest; respond: RespondFn | undefined },\n ): Promise<Elb.PushResult> => {\n let pendingRespond: Promise<void> | undefined;\n\n // Resolve before chain (static or conditional).\n // Single-id results walk static `.next` links; multi-id results are\n // explicit chains (fan-out from `many` is handled by the engine).\n const beforeChain =\n staticBeforeChain ??\n (before !== undefined\n ? (() => {\n const ids = getNextSteps(before, buildCacheContext(scope.ingest));\n if (ids.length === 0) return [];\n const start = ids.length === 1 ? ids[0] : ids;\n return walkChain(\n start,\n extractTransformerNextMap(collector.transformers),\n );\n })()\n : []);\n\n // The before chain may fan out (return an array of events). The cache\n // check and destination push must run once per event so fan-out is\n // preserved end-to-end. Cache logic is request-scoped (keyed by the\n // scope's ingest), so it lives outside the loop. The actual pipeline\n // (preChain + collector.push) runs inside the loop, once per event.\n let events: WalkerOS.DeepPartialEvent[] = [rawEvent];\n\n // Run source.before chain (consent-exempt, pre-source preprocessing)\n if (\n beforeChain.length > 0 &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const beforeResult = await runTransformerChain(\n collector,\n collector.transformers,\n beforeChain,\n rawEvent,\n scope.ingest,\n scope.respond,\n `source.${sourceId}.before`,\n );\n if (beforeResult.event === null) {\n return { ok: true } as Elb.PushResult;\n }\n // Pipeline-halt signal from a `cache.stop: true` HIT inside the\n // source.before chain. Do NOT invoke collector.push — drop the event\n // before it enters the collector pipeline.\n if (beforeResult.stopped) {\n if (beforeResult.respond) scope.respond = beforeResult.respond;\n return { ok: true } as Elb.PushResult;\n }\n if (beforeResult.respond) scope.respond = beforeResult.respond;\n events = Array.isArray(beforeResult.event)\n ? beforeResult.event\n : [beforeResult.event];\n }\n\n // Source cache check (full=true by default for sources)\n if (compiledSourceCache) {\n const cacheStore = getCacheStore(compiledSourceCache, collector);\n if (cacheStore) {\n const cacheContext = buildCacheContext(scope.ingest);\n const cacheResult = await checkCache(\n compiledSourceCache,\n cacheStore,\n cacheContext,\n // no per-step prefix — cache keys honor user-provided namespace only\n );\n\n if (cacheResult) {\n if (cacheResult.status === 'HIT' && cacheResult.value !== undefined) {\n if (compiledSourceCache.stop) {\n // stop=true (default): respond with cached value, skip pipeline\n let respondValue: unknown = cacheResult.value;\n if (cacheResult.rule.update) {\n respondValue = await applyUpdate(\n respondValue,\n cacheResult.rule.update as Record<string, unknown>,\n { ...cacheContext, cache: { status: 'HIT' } },\n collector,\n );\n }\n scope.respond?.(respondValue as Record<string, unknown>);\n return { ok: true } as Elb.PushResult;\n }\n // stop=false: cached value unused — HIT signals \"seen before\", pipeline continues\n }\n\n if (\n cacheResult.status === 'MISS' &&\n compiledSourceCache.stop &&\n scope.respond\n ) {\n // stop=true MISS: wrap respond to intercept and cache the value.\n // Store original in cache, then apply update rules with MISS\n // status before responding (mirrors HIT path which applies\n // with HIT status).\n //\n // When `update` is configured the update step is async, so\n // the wrapper captures its promise in `pendingRespond`.\n // `executePush` awaits that promise before returning, so any\n // source fallback that runs after `await env.push(...)` (e.g.\n // the express source's transparent-GIF default) sees\n // `createRespond`'s first-call-wins flag already set and\n // correctly no-ops. Without this, the fallback would win\n // the race and the real response would be lost.\n const unwrappedRespond = scope.respond;\n const missUpdate = cacheResult.rule.update;\n const missContext = { ...cacheContext, cache: { status: 'MISS' } };\n const missKey = cacheResult.key;\n const missTtl = cacheResult.rule.ttl;\n\n const missRespond: RespondFn = (respondOptions) => {\n storeCache(cacheStore, missKey, respondOptions, missTtl);\n\n if (!missUpdate) {\n unwrappedRespond(respondOptions);\n return;\n }\n\n pendingRespond = (async () => {\n const updated = await applyUpdate(\n respondOptions,\n missUpdate as Record<string, unknown>,\n missContext,\n collector,\n );\n unwrappedRespond(updated as RespondOptions);\n })();\n };\n\n scope.respond = missRespond;\n }\n\n // stop=false MISS: store sentinel so subsequent requests get a HIT\n if (cacheResult.status === 'MISS' && !compiledSourceCache.stop) {\n storeCache(cacheStore, cacheResult.key, true, cacheResult.rule.ttl);\n }\n }\n }\n }\n\n // Resolve chain: static (pre-computed) or conditional (per-event).\n // Three dispatch shapes from `getNextSteps`:\n // - [] → no route matched; passthrough to collector with no\n // pre-chain.\n // - ['x'] → walk static `.next` links from x and run as a single\n // sequential subchain inside `collector.push`.\n // - ['a','b',…] → `many` fan-out. Each id is an INDEPENDENT terminal\n // subchain dispatched via its own `collector.push` call\n // with a per-branch cloned ingest and `respond` cleared\n // (no-respond-across-many doctrine). Error isolation\n // per branch via tryCatchAsync.\n //\n // Note: a plain `next: ['a','b','c']` is `isStaticRoute` → pre-walked\n // by `staticPreChain` as the legacy explicit sequential chain. Only\n // `{ many: [...] }` reaches the multi-id branch here.\n type Dispatch =\n | { kind: 'single'; preChain: string[] }\n | { kind: 'many'; branches: string[][] };\n\n const dispatch: Dispatch = staticPreChain\n ? { kind: 'single', preChain: staticPreChain }\n : next !== undefined\n ? (() => {\n const ids = getNextSteps(next, buildCacheContext(scope.ingest));\n if (ids.length === 0)\n return { kind: 'single', preChain: [] } as Dispatch;\n if (ids.length === 1)\n return {\n kind: 'single',\n preChain: walkChain(\n ids[0],\n extractTransformerNextMap(collector.transformers),\n ),\n } as Dispatch;\n return {\n kind: 'many',\n branches: ids.map((id) =>\n walkChain(\n id,\n extractTransformerNextMap(collector.transformers),\n ),\n ),\n } as Dispatch;\n })()\n : ({ kind: 'single', preChain: [] } as Dispatch);\n\n // Push each event independently through the post-before pipeline.\n // For non-fan-out (single event) this is a one-iteration loop and\n // behaves exactly like the previous implementation.\n let pushResult: Elb.PushResult = { ok: true } as Elb.PushResult;\n for (const event of events) {\n if (dispatch.kind === 'many') {\n // `many` fan-out: each branch is an independent terminal flow.\n // Per-branch ingest clone, no respond propagation, error isolation\n // via tryCatchAsync. Branch results are awaited and discarded;\n // scope.respond is NOT updated from any branch.\n await Promise.all(\n dispatch.branches.map((branchChain, idx) =>\n tryCatchAsync(\n async () =>\n hasUserTerminalPush\n ? terminalPush(event)\n : terminalPush(event, {\n ...options,\n id: sourceId,\n ingest: cloneIngest(scope.ingest, `${sourceId}.${idx}`),\n respond: undefined,\n mapping: config,\n preChain: branchChain,\n }),\n (err) => {\n collector.logger\n .scope('source:many')\n .error(`many branch ${idx} failed`, { error: err });\n return { ok: true } as Elb.PushResult;\n },\n )(),\n ),\n );\n // `many` is fan-out, not enrichment — surface a generic OK.\n pushResult = { ok: true } as Elb.PushResult;\n } else if (hasUserTerminalPush) {\n // User override: bypass the pipeline, deliver raw events. This\n // preserves the `env.push: mockPush` test spy pattern.\n pushResult = await terminalPush(event);\n } else {\n pushResult = await terminalPush(event, {\n ...options,\n id: sourceId,\n ingest: scope.ingest,\n respond: scope.respond,\n mapping: config,\n preChain: dispatch.preChain,\n });\n }\n }\n\n // Wait for any deferred MISS update work to land on the source's\n // respond sender before returning control to the source. This\n // ensures source-level fallbacks (e.g. transparent GIFs) run after\n // the real response has been committed via first-call-wins.\n if (pendingRespond) await pendingRespond;\n\n return pushResult;\n };\n\n /**\n * Build a fresh per-scope `Ingest` from raw scope input by applying\n * `config.ingest` mapping if present. Always produces a typed Ingest\n * with valid `_meta`. Pure: returns a new object, never reads or\n * writes source-factory state.\n */\n const extractIngest = async (rawScope: unknown): Promise<Ingest> => {\n const fresh = createIngest(sourceId);\n if (!config.ingest || rawScope === undefined) return fresh;\n const extracted = await getMappingValue(rawScope, config.ingest, {\n collector,\n });\n return {\n ...fresh,\n ...(extracted as Record<string, unknown>),\n _meta: fresh._meta, // protect _meta from being overwritten\n };\n };\n\n // Factory-default push: each call gets a fresh Ingest and no respond.\n // Sources with a single logical scope (browser, dataLayer) call this\n // directly via `env.push`. Server sources handling concurrent requests\n // call `context.withScope(...)` instead, which threads a per-scope\n // ingest/respond into the same pipeline.\n const wrappedPush: Collector.PushFn = async (\n rawEvent: WalkerOS.DeepPartialEvent,\n options: Collector.PushOptions = {},\n ) => {\n const scope = {\n ingest: createIngest(sourceId),\n respond: undefined as RespondFn | undefined,\n };\n return executePush(rawEvent, options, scope);\n };\n\n // Create initial logger scoped to sourceId (type will be added after init)\n const initialLogger = collector.logger.scope('source').scope(sourceId);\n\n // Build cleanEnv. User-supplied env can override every field; we\n // immediately overwrite `push` with the source-pipeline `wrappedPush`.\n // Any user-supplied `env.push` was captured above as `terminalPush`\n // (the pipeline's terminus, not the source's outward-facing push).\n const cleanEnv: Source.Env = {\n command: collector.command,\n sources: collector.sources,\n elb: collector.sources.elb.push,\n logger: initialLogger,\n ...env,\n push: wrappedPush,\n };\n\n /**\n * Bind ingest and respond to a single scope of work. Each invocation\n * builds a fresh `Ingest`, captures the given `respond`, and runs the\n * caller's `body` with a per-scope env whose `push` carries both. The\n * scope is the unit of cross-call isolation — concurrent withScope\n * invocations never share ingest or respond.\n */\n const withScope: Source.Context['withScope'] = async (\n rawScope,\n respond,\n body,\n ) => {\n const scope: { ingest: Ingest; respond: RespondFn | undefined } = {\n ingest: await extractIngest(rawScope),\n respond,\n };\n const scopePush: Collector.PushFn = (rawEvent, options = {}) =>\n executePush(rawEvent, options, scope);\n const scopeEnv: Source.ScopeEnv = {\n ...cleanEnv,\n push: scopePush,\n ingest: scope.ingest,\n respond: scope.respond,\n };\n return body(scopeEnv);\n };\n\n const sourceContext: Source.Context = {\n collector,\n logger: initialLogger,\n id: sourceId,\n config,\n env: cleanEnv,\n withScope,\n };\n\n const sourceInstance = await tryCatchAsync(\n code,\n (err: unknown): undefined => {\n if (err instanceof FatalError) throw err;\n collector.status.failed++;\n collector.logger.scope('source').error('source factory failed', {\n sourceId,\n error: err,\n });\n return undefined;\n },\n )(sourceContext);\n if (!sourceInstance) return undefined;\n\n const sourceType = sourceInstance.type || 'unknown';\n const sourceLogger = collector.logger.scope(sourceType).scope(sourceId);\n cleanEnv.logger = sourceLogger;\n\n if (primary) {\n sourceInstance.config = { ...sourceInstance.config, primary };\n }\n\n return sourceInstance;\n}\n\n/**\n * Initialize sources. Sources with `require` are deferred to collector.pending.\n */\nexport async function initSources(\n collector: Collector.Instance,\n sources: Source.InitSources = {},\n): Promise<Collector.Sources> {\n const result: Collector.Sources = {};\n\n // Pass 1: register every source via its factory.\n for (const [sourceId, sourceDefinition] of Object.entries(sources)) {\n const sourceInstance = await initSource(\n collector,\n sourceId,\n sourceDefinition,\n );\n if (!sourceInstance) continue;\n // Propagate orchestration fields from the user's source definition into\n // the registered instance config. The factory does not know about\n // `require` — it's an InitSource-level concern that the collector owns.\n // Clone the array so per-source decrement (in onApply) doesn't mutate\n // the caller's config.\n const userRequire = sourceDefinition.config?.require;\n sourceInstance.config = {\n ...sourceInstance.config,\n init: false,\n ...(userRequire ? { require: [...userRequire] } : {}),\n };\n result[sourceId] = sourceInstance;\n }\n\n // Merge into collector.sources BEFORE pass 2 so that any onApply\n // broadcast triggered during init can find every source.\n Object.assign(collector.sources, result);\n\n // Pass 2: init each source. Side effects allowed here.\n for (const sourceId of Object.keys(result)) {\n const instance = collector.sources[sourceId];\n let initFailed = false;\n if (instance.init) {\n await tryCatchAsync(instance.init.bind(instance), (err: unknown) => {\n if (err instanceof FatalError) throw err;\n initFailed = true;\n collector.status.failed++;\n collector.logger.scope('source').error('source init failed', {\n sourceId,\n error: err,\n });\n })();\n }\n // Control-flow fix: a throw inside `init()` previously left the source\n // marked `config.init = true` despite never having completed setup.\n // Operators reading `source.config.init` would see a healthy source\n // that was actually broken. Skip the rest of the loop on failure so\n // the source stays in `config.init = false` and is visibly stuck.\n if (initFailed) continue;\n instance.config.init = true;\n if (isSourceStarted(instance)) {\n await flushSourceQueueOn(collector, instance, sourceId);\n }\n }\n\n return result;\n}\n","/**\n * @module transformer\n *\n * Transformer Chain Utilities\n * ==========================\n *\n * This module provides the unified implementation for transformer chains in walkerOS.\n * Chains are used at two points in the data flow:\n *\n * 1. Pre-collector chains (source.next):\n * Source → [Transformer Chain] → Collector\n * Events are processed before the collector sees them.\n *\n * 2. Post-collector chains (destination.before):\n * Collector → [Transformer Chain] → Destination\n * Events are processed before reaching specific destinations.\n *\n * Key Functions:\n * - extractTransformerNextMap(): Extracts next links from transformer instances\n * - extractChainProperty(): Unified extraction of chain properties from definitions\n * - walkChain(): Resolves chain IDs from starting point\n * - runTransformerChain(): Executes a chain of transformers on an event\n *\n * Chain Resolution:\n * - String start: Walk transformer.next links until chain ends\n * - Array start: Use array directly (explicit chain, ignores transformer.next)\n *\n * Chain Termination:\n * - Transformer returns false → chain stops, event is dropped\n * - Transformer throws error → chain stops, event is dropped\n * - Transformer returns void → continue with unchanged event\n * - Transformer returns event → continue with modified event\n */\nimport type {\n Cache,\n Collector,\n Transformer,\n WalkerOS,\n Ingest,\n} from '@walkeros/core';\nimport {\n createIngest,\n emitStep,\n FatalError,\n isObject,\n stepId,\n tryCatchAsync,\n useHooks,\n getNextSteps,\n compileCache,\n checkCache,\n storeCache,\n buildCacheContext,\n validateStepEntry,\n processEventMapping,\n} from '@walkeros/core';\nimport { buildBaseState } from './observerEmit';\nimport { getCacheStore } from './cache';\n\n/**\n * Extracts transformer next configuration for chain walking.\n * Maps transformer instances to their config.next values.\n *\n * This is the single source of truth for extracting chain links.\n * Used by both source.ts (pre-collector chains) and destination.ts (post-collector chains).\n *\n * @param transformers - Map of transformer instances\n * @returns Map of transformer IDs to their next configuration\n */\nexport function extractTransformerNextMap(\n transformers: Transformer.Transformers,\n): Record<string, { next?: string | string[] }> {\n const result: Record<string, { next?: string | string[] }> = {};\n for (const [id, transformer] of Object.entries(transformers)) {\n const next = transformer.config?.next;\n // Static shapes are recorded for synchronous chain walking.\n // Conditional shapes (RouteConfig, mixed arrays) resolve per-event via\n // getNextSteps at dispatch time; they get an empty entry here so the\n // chain walker stops at this hop rather than following a stale link.\n if (typeof next === 'string') {\n result[id] = { next };\n } else if (\n Array.isArray(next) &&\n next.every((entry) => typeof entry === 'string')\n ) {\n result[id] = { next: next as string[] };\n } else {\n result[id] = {};\n }\n }\n return result;\n}\n\n/**\n * Extracts chain property from definition and merges into config.\n * Provides unified handling for source.next, destination.before, and transformer.next.\n *\n * @param definition - Component definition with optional chain property\n * @param propertyName - Name of chain property ('next' or 'before')\n * @returns Object with merged config and extracted chain value\n */\nexport function extractChainProperty<\n T extends { config?: Record<string, unknown>; [key: string]: unknown },\n>(\n definition: T,\n propertyName: 'next' | 'before',\n): {\n config: Record<string, unknown>;\n chainValue: string | string[] | undefined;\n} {\n const config = (definition.config || {}) as Record<string, unknown>;\n const chainValue = definition[propertyName] as string | string[] | undefined;\n\n if (chainValue !== undefined) {\n return {\n config: { ...config, [propertyName]: chainValue },\n chainValue,\n };\n }\n\n return { config, chainValue: undefined };\n}\n\n/**\n * Walks a transformer chain starting from a given transformer ID.\n * Returns ordered array of transformer IDs in the chain.\n *\n * Used for on-demand chain resolution:\n * - Called from destination.ts with destination.config.before\n * - Called from source.ts with source.config.next\n *\n * @param startId - First transformer in chain, or explicit array of transformer IDs\n * @param transformers - Available transformer configs with optional `next` field\n * @returns Ordered array of transformer IDs to execute\n *\n * @example\n * // Single transformer\n * walkChain('redact', { redact: {} }) // ['redact']\n *\n * @example\n * // Chain via next\n * walkChain('a', { a: { next: 'b' }, b: { next: 'c' }, c: {} }) // ['a', 'b', 'c']\n *\n * @example\n * // Explicit array\n * walkChain(['x', 'y'], {}) // ['x', 'y']\n */\nexport function walkChain(\n startId: string | string[] | undefined,\n transformers: Record<string, { next?: string | string[] }> = {},\n): string[] {\n if (!startId) return [];\n\n // If array provided, use it directly (explicit chain)\n if (Array.isArray(startId)) {\n return startId;\n }\n\n // Walk the chain via transformer.next links\n const chain: string[] = [];\n const visited = new Set<string>();\n let current: string | undefined = startId;\n\n while (current && transformers[current]) {\n if (visited.has(current)) {\n // Circular reference detected - stop walking\n break;\n }\n visited.add(current);\n chain.push(current);\n\n const next: string | string[] | undefined = transformers[current].next;\n\n // If transformer has array next, append it and stop walking\n if (Array.isArray(next)) {\n chain.push(...next);\n break;\n }\n\n current = next;\n }\n\n return chain;\n}\n\n/**\n * Initializes transformer instances from configuration.\n * Does NOT call transformer.init() - that happens lazily before first push.\n *\n * @param collector - The collector instance\n * @param initTransformers - Transformer initialization configurations\n * @returns Initialized transformer instances\n */\nexport async function initTransformers(\n collector: Collector.Instance,\n initTransformers: Transformer.InitTransformers = {},\n): Promise<Transformer.Transformers> {\n const result: Transformer.Transformers = {};\n\n for (const [transformerId, transformerDef] of Object.entries(\n initTransformers,\n )) {\n const { code, env = {} } = transformerDef;\n\n // Validate the entry via the shared predicate. A code-less entry must\n // declare at least one operative field (package, before, next, cache,\n // mapping). Unknown keys and code+package conflicts are also rejected.\n const validation = validateStepEntry(\n transformerDef as Record<string, unknown>,\n 'Transformer',\n );\n if (!validation.ok) {\n collector.logger.warn(\n `Transformer ${transformerId} invalid (${validation.code}): ${validation.reason}. Skipping.`,\n );\n continue;\n }\n\n // Use unified chain property extractor for both before and next\n const { config: configWithBefore } = extractChainProperty(\n transformerDef,\n 'before',\n );\n const { config: configWithChain } = extractChainProperty(\n { ...transformerDef, config: configWithBefore },\n 'next',\n );\n\n // Merge definition-level env into config so it's available during push.\n // transformerPush reads transformer.config.env to build the push context.\n const configWithEnv =\n Object.keys(env).length > 0\n ? { ...configWithChain, env: env as Transformer.Env }\n : configWithChain;\n\n // Merge definition-level cache into config for runtime access\n const { cache } = transformerDef;\n const configWithCache = cache ? { ...configWithEnv, cache } : configWithEnv;\n\n // Build transformer context for init\n const transformerLogger = collector.logger\n .scope('transformer')\n .scope(transformerId);\n\n const context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n ingest: createIngest(transformerId),\n config: configWithCache,\n env: env as Transformer.Env,\n };\n\n // Synthesize a passthrough instance when `code` is absent.\n // This makes the entry a \"pass\" — a named, code-less hop. Two flavors:\n // 1. mapping-aware: when `mapping` is declared, the synthesized push\n // runs `processEventMapping` and forwards the transformed event\n // (or drops it when a rule has `ignore: true`).\n // 2. plain passthrough: when only `before` / `next` / `cache` are\n // declared, the push returns the event unchanged.\n const codeFn =\n code ??\n ((ctx: Transformer.Context) => {\n const stepMapping = transformerDef.mapping;\n if (stepMapping) {\n // Warn once per init if vendor-payload fields are present at the\n // transformer position. Only event-mutating fields apply here.\n // Note: `MappingConfig` has no top-level `silent` field — that\n // lives on `Rule` only, so the config-level check is `data` only.\n const meaninglessFields: string[] = [];\n if (stepMapping.data !== undefined) meaninglessFields.push('data');\n // Walk rules for per-rule data/silent\n if (stepMapping.mapping) {\n for (const [entity, actions] of Object.entries(\n stepMapping.mapping,\n )) {\n if (typeof actions !== 'object' || actions === null) continue;\n for (const [action, rule] of Object.entries(\n actions as Record<string, unknown>,\n )) {\n if (typeof rule !== 'object' || rule === null) continue;\n const r = rule as Record<string, unknown>;\n if (r.data !== undefined)\n meaninglessFields.push(`mapping[${entity}][${action}].data`);\n if (r.silent !== undefined)\n meaninglessFields.push(\n `mapping[${entity}][${action}].silent`,\n );\n }\n }\n }\n if (meaninglessFields.length > 0) {\n ctx.collector.logger.warn(\n `Transformer ${transformerId}: \\`${meaninglessFields.join(', ')}\\` ignored at transformer position (only event-mutating fields apply).`,\n );\n }\n\n return {\n type: 'pass',\n config: ctx.config,\n push: async (event: WalkerOS.DeepPartialEvent) => {\n const r = await processEventMapping(\n event,\n stepMapping,\n ctx.collector,\n );\n if (r.ignore) return false;\n return { event: r.event };\n },\n };\n }\n return {\n type: 'pass',\n config: ctx.config,\n push: (event: WalkerOS.DeepPartialEvent) => ({ event }),\n };\n });\n\n // Initialize the transformer instance with context\n const instance = await codeFn(context);\n\n // Bug 2 fix: propagate def-level before/next to instance.config when\n // not already set by the code function. The recursive chain walker\n // reads instance.config.before; for synthesized pass-throughs and\n // well-behaved user code that returns a fresh config object, the\n // def-level value needs to land on instance.config explicitly.\n // User-supplied code that sets its own config.before is preserved.\n if (\n transformerDef.before !== undefined &&\n instance.config?.before === undefined\n ) {\n instance.config = {\n ...(instance.config ?? {}),\n before: transformerDef.before,\n };\n }\n if (\n transformerDef.next !== undefined &&\n instance.config?.next === undefined\n ) {\n instance.config = {\n ...(instance.config ?? {}),\n next: transformerDef.next,\n };\n }\n\n result[transformerId] = instance;\n }\n\n return result;\n}\n\n/**\n * Initializes a transformer if it hasn't been initialized yet.\n * Called lazily before first push.\n *\n * @param collector - The collector instance\n * @param transformer - The transformer to initialize\n * @param transformerId - The transformer ID\n * @returns Whether initialization succeeded\n */\nexport async function transformerInit(\n collector: Collector.Instance,\n transformer: Transformer.Instance,\n transformerId: string,\n): Promise<boolean> {\n // Check if already initialized\n if (transformer.init && !transformer.config.init) {\n const transformerType = transformer.type || 'unknown';\n const transformerLogger = collector.logger.scope(\n `transformer:${transformerType}`,\n );\n\n const context: Transformer.Context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n ingest: createIngest(transformerId),\n config: transformer.config,\n env: mergeTransformerEnvironments(transformer.config.env),\n };\n\n transformerLogger.debug('init');\n\n const configResult = await useHooks(\n transformer.init,\n 'TransformerInit',\n collector.hooks,\n collector.logger,\n )(context);\n\n // Check for initialization failure\n if (configResult === false) return false;\n\n // Update config if returned, preserving env from definition\n transformer.config = {\n ...(configResult || transformer.config),\n env:\n ((configResult as Record<string, unknown>)?.env as Transformer.Env) ||\n transformer.config.env,\n init: true,\n };\n\n transformerLogger.debug('init done');\n }\n\n return true;\n}\n\n/**\n * Pushes an event through a single transformer.\n *\n * @param collector - The collector instance\n * @param transformer - The transformer to push to\n * @param transformerId - The transformer ID\n * @param event - The event to process\n * @param ingest - Mutable ingest context flowing through the pipeline\n * @returns The processed event, void for passthrough, or false to stop chain\n */\nexport async function transformerPush(\n collector: Collector.Instance,\n transformer: Transformer.Instance,\n transformerId: string,\n event: WalkerOS.DeepPartialEvent,\n ingest?: Ingest,\n respond?: import('@walkeros/core').RespondFn,\n): Promise<Transformer.Result | Transformer.Result[] | false | void> {\n const transformerType = transformer.type || 'unknown';\n const transformerLogger = collector.logger.scope(\n `transformer:${transformerType}`,\n );\n\n const context: Transformer.Context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n ingest: ingest!, // Mutable shared context\n config: transformer.config,\n env: {\n ...mergeTransformerEnvironments(transformer.config.env),\n ...(respond ? { respond } : {}),\n },\n };\n\n transformerLogger.debug('push', { event: (event as { name?: string }).name });\n\n const eventId = typeof event.id === 'string' ? event.id : '';\n const started = Date.now();\n const inState = buildBaseState(collector, {\n stepId: stepId('transformer', transformerId),\n stepType: 'transformer',\n phase: 'in',\n eventId,\n now: started,\n });\n emitStep(collector, inState);\n\n try {\n const result = await useHooks(\n transformer.push,\n 'TransformerPush',\n collector.hooks,\n collector.logger,\n )(event, context);\n\n const finished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: stepId('transformer', transformerId),\n stepType: 'transformer',\n phase: 'out',\n eventId,\n now: finished,\n });\n outState.durationMs = finished - started;\n outState.outEvent = result;\n emitStep(collector, outState);\n\n transformerLogger.debug('push done');\n\n return result;\n } catch (err) {\n const finished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepId('transformer', transformerId),\n stepType: 'transformer',\n phase: 'error',\n eventId,\n now: finished,\n });\n errState.durationMs = finished - started;\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n}\n\n/**\n * Clone an ingest for an independent branch (e.g. a `many` fan-out branch).\n *\n * Each branch needs its own `_meta.path` so cycle protection and the\n * MAX_PATH_LENGTH safety valve operate per-branch rather than colliding\n * across sibling forks. The top-level object and `_meta` are shallow-copied;\n * `_meta.path` is duplicated so appends in one branch do not leak into others.\n *\n * `branchId` is reserved for future per-branch labelling (Task 4.1) and is\n * not currently written into `_meta`; it is accepted now so callers don't\n * need to change their call sites when error-isolation lands.\n */\nexport function cloneIngest(\n ingest: Ingest | undefined,\n branchId: string,\n): Ingest {\n if (!ingest) return createIngest(branchId);\n return {\n ...ingest,\n _meta: { ...ingest._meta, path: [...ingest._meta.path] },\n };\n}\n\n/**\n * Runs an event through a chain of transformers.\n *\n * @param collector - The collector instance with transformers\n * @param transformers - Map of transformer instances\n * @param chain - Ordered array of transformer IDs to execute\n * @param event - The event to process\n * @param ingest - Mutable ingest context flowing through the pipeline\n * @returns The processed event or null if chain was stopped\n */\nexport async function runTransformerChain(\n collector: Collector.Instance,\n transformers: Transformer.Transformers,\n chain: string[],\n event: WalkerOS.DeepPartialEvent,\n ingest?: Ingest,\n respond?: import('@walkeros/core').RespondFn,\n chainContext?: string,\n): Promise<Transformer.ChainResult> {\n const MAX_PATH_LENGTH = 256;\n\n // Ensure an ingest exists so the per-branch path budget engages\n // regardless of caller. Production callers (source/push/destination)\n // always pass one; this guards direct test invocations and any future\n // entrypoint that omits it. Without an ingest, the safety valve below\n // can never trip — leaving cyclic `many` graphs unbounded.\n if (!ingest) {\n ingest = createIngest(chain[0] ?? 'chain');\n }\n\n if (chainContext && ingest._meta) {\n ingest._meta.chainPath = chainContext;\n }\n\n let processedEvent = event;\n let currentRespond = respond;\n\n for (const transformerName of chain) {\n const transformer = transformers[transformerName];\n if (!transformer) {\n collector.logger.warn(`Transformer not found: ${transformerName}`);\n continue;\n }\n\n // Safety valve: prevent unbounded path growth\n if (ingest && ingest._meta && ingest._meta.path.length > MAX_PATH_LENGTH) {\n collector.logger.error(`Max path length exceeded at ${transformerName}`);\n return { event: null, respond: currentRespond };\n }\n\n // Track step in _meta (runtime-managed)\n if (ingest && ingest._meta) {\n ingest._meta.hops++;\n ingest._meta.path.push(transformerName);\n }\n\n // Initialize transformer if needed. The wrap surfaces a thrown init\n // (misconfiguration, missing env, etc.) with full cause via the scoped\n // logger and counts it on `status.failed`. A non-throw `false` return\n // from transformerInit itself flows through the same early-return below\n // (handled by the destination's own log; counter remains untouched on\n // the deliberate-false path).\n const isInitialized = await tryCatchAsync(\n transformerInit,\n (err: unknown): boolean => {\n if (err instanceof FatalError) throw err;\n collector.status.failed++;\n collector.logger\n .scope(`transformer:${transformer.type || 'unknown'}`)\n .error('transformer init failed', {\n transformer: transformerName,\n error: err,\n });\n return false;\n },\n )(collector, transformer, transformerName);\n\n if (!isInitialized) {\n // Stop chain on init failure. Thrown cases were already logged with\n // full cause via the onError above; deliberate-false returns leave\n // the chain stop signal intact without extra noise.\n return { event: null, respond: currentRespond };\n }\n\n // Path-specific mock check (takes precedence)\n if (\n chainContext &&\n transformer.config?.chainMocks?.[chainContext] !== undefined\n ) {\n const chainMock = transformer.config.chainMocks[chainContext];\n collector.logger\n .scope(`transformer:${transformer.type || 'unknown'}`)\n .debug('chainMock', { chain: chainContext });\n processedEvent = chainMock as WalkerOS.DeepPartialEvent;\n continue;\n }\n\n // Global mock check\n if (transformer.config?.mock !== undefined) {\n collector.logger\n .scope(`transformer:${transformer.type || 'unknown'}`)\n .debug('mock');\n processedEvent = transformer.config.mock as WalkerOS.DeepPartialEvent;\n continue;\n }\n\n // Disabled check\n if (transformer.config?.disabled) {\n continue;\n }\n\n // Compile transformer cache once (reused for HIT check and MISS store).\n // Transformer caches operate on events (step-level HIT/MISS keyed by event\n // fields), so the rule shape is always EventCacheRule, not StoreCacheRule.\n const tCacheConfig = transformer.config?.cache as\n | Cache.Cache<Cache.EventCacheRule>\n | undefined;\n const compiledTCache = tCacheConfig\n ? compileCache(tCacheConfig)\n : undefined;\n const tCacheStore = compiledTCache\n ? getCacheStore(compiledTCache, collector)\n : undefined;\n\n // Check transformer cache (step-level: skip push, continue chain)\n let cacheMiss: { key: string; ttl: number } | undefined;\n if (compiledTCache && tCacheStore) {\n const cacheContext = buildCacheContext(ingest, processedEvent);\n const cacheResult = await checkCache(\n compiledTCache,\n tCacheStore,\n cacheContext,\n );\n\n if (cacheResult?.status === 'HIT' && cacheResult.value) {\n processedEvent = cacheResult.value as WalkerOS.DeepPartialEvent;\n if (compiledTCache.stop)\n // stop=true → stop chain AND halt pipeline at this position.\n // Caller branches on `stopped` to skip downstream stages\n // (collector.push, destinations); see push.ts and source.ts.\n return {\n event: processedEvent,\n respond: currentRespond,\n stopped: true,\n };\n continue; // stop=false → next transformer\n }\n\n if (cacheResult?.status === 'MISS') {\n cacheMiss = { key: cacheResult.key, ttl: cacheResult.rule.ttl };\n }\n }\n\n // Run transformer.before chain if configured.\n //\n // Dispatch uses `getNextSteps`:\n // - [] → no route matched; skip the before chain (passthrough).\n // - ['x'] → sequential continuation; walk static .next links from x\n // and run as a single subchain. Preserves cache.stop and\n // null/respond propagation from the nested chain.\n // - ['a','b',...] → `many` fan-out. Each branch is an independent\n // terminal subchain with a cloned ingest (per-branch\n // cycle protection). No merge: many is fan-out, not\n // enrichment, so parent processedEvent is unchanged.\n // Per-branch error isolation lands in Task 4.1;\n // respond suppression lands in Task 4.2.\n const transformerBefore = transformer.config.before;\n if (transformerBefore) {\n const beforeIds = getNextSteps(\n transformerBefore,\n buildCacheContext(ingest, processedEvent),\n );\n if (beforeIds.length === 1) {\n const beforeChainIds = walkChain(\n beforeIds[0],\n extractTransformerNextMap(transformers),\n );\n if (beforeChainIds.length > 0) {\n const beforeResult = await runTransformerChain(\n collector,\n transformers,\n beforeChainIds,\n processedEvent,\n ingest,\n currentRespond,\n chainContext,\n );\n if (beforeResult.event === null)\n return {\n event: null,\n respond: beforeResult.respond ?? currentRespond,\n }; // Before chain stopped\n // Propagate pipeline-halt from a nested `cache.stop: true` HIT in\n // the before chain. The outer caller (push.ts / source.ts) drops\n // the event before destinations see it.\n if (beforeResult.stopped) {\n return {\n event: Array.isArray(beforeResult.event)\n ? beforeResult.event[0]\n : beforeResult.event,\n respond: beforeResult.respond ?? currentRespond,\n stopped: true,\n };\n }\n if (beforeResult.respond) currentRespond = beforeResult.respond;\n // Before chains use first result if fan-out occurred\n processedEvent = Array.isArray(beforeResult.event)\n ? beforeResult.event[0]\n : beforeResult.event;\n }\n } else if (beforeIds.length > 1) {\n // many: independent terminal subchains. Each branch walks to its own\n // exit with a per-branch ingest clone. Per-branch error isolation\n // (Task 4.1): wrap each branch dispatch in `tryCatchAsync` so a\n // throw in one branch (init failure, unforeseen runtime error) does\n // not reject the surrounding `Promise.all` and starve siblings.\n // No-respond-across-many: respond ownership cannot be unambiguously\n // assigned when one inbound request fans out to N terminal flows.\n // Branch dispatch passes `undefined` instead of `currentRespond`, and\n // branch results are awaited and discarded — currentRespond is NOT\n // updated from any branch's wrapped respond.\n await Promise.all(\n beforeIds.map((id) =>\n tryCatchAsync(runTransformerChain, (err) => {\n collector.logger\n .scope('transformer:many')\n .error(`many branch ${id} failed`, { error: err });\n return { event: null, respond: undefined };\n })(\n collector,\n transformers,\n walkChain(id, extractTransformerNextMap(transformers)),\n processedEvent,\n cloneIngest(ingest, id),\n undefined,\n chainContext,\n ),\n ),\n );\n // No merge: many is fan-out, not enrichment. Parent processedEvent\n // unchanged.\n }\n }\n\n // Run the transformer\n const result = await tryCatchAsync(transformerPush, (err) => {\n collector.logger\n .scope(`transformer:${transformer.type || 'unknown'}`)\n .error('Push failed', { error: err });\n return false as const; // Stop chain on error\n })(\n collector,\n transformer,\n transformerName,\n processedEvent,\n ingest,\n currentRespond,\n );\n\n // Handle result\n if (result === false) {\n // Transformer explicitly stopped the chain\n return { event: null, respond: currentRespond };\n }\n\n // Handle Result array (fan-out) — MUST be before typeof === 'object'\n if (Array.isArray(result)) {\n const remainingChain = chain.slice(chain.indexOf(transformerName) + 1);\n\n const forkResults = await Promise.all(\n result.map(async (forkResult) => {\n const forkEvent = forkResult.event || processedEvent;\n // Clone ingest per fork to prevent cross-fork contamination\n const forkIngest = cloneIngest(ingest, 'unknown');\n\n if (forkResult.next) {\n // Fork has explicit routing. Dispatch uses `getNextSteps`:\n // - [] → no route matched; passthrough this fork's\n // event without entering any subchain (fork\n // has explicit routing, so we do NOT fall\n // through to remainingChain).\n // - ['x'] → walk static .next from x and run that as a\n // single subchain. Preserves the existing\n // \"fork has explicit routing terminates the\n // main chain at this branch\" semantic — the\n // subchain's ChainResult is this fork's\n // result.\n // - ['a','b',...] → `many` fan-out. Each id dispatches as its\n // own terminal subchain with a per-branch\n // cloned ingest. Returns an array of\n // ChainResults; the outer `.flat()` in the\n // aggregation loop folds them into the\n // surrounding flatEvents collection.\n const forkIds = getNextSteps(\n forkResult.next,\n buildCacheContext(forkIngest, forkEvent),\n );\n if (forkIds.length === 0) {\n return { event: forkEvent, respond: currentRespond };\n }\n if (forkIds.length === 1) {\n const branchedChain = walkChain(\n forkIds[0],\n extractTransformerNextMap(transformers),\n );\n if (branchedChain.length > 0) {\n return runTransformerChain(\n collector,\n transformers,\n branchedChain,\n forkEvent,\n forkIngest,\n currentRespond,\n chainContext,\n );\n }\n return { event: forkEvent, respond: currentRespond };\n }\n // Terminal fan-out. Each branch walks to its own exit with a\n // per-branch ingest clone. Per-branch error isolation\n // (Task 4.1): wrap each branch dispatch in `tryCatchAsync` so a\n // throw in one branch does not reject the surrounding\n // `Promise.all` and starve siblings.\n // No-respond-across-many: respond ownership cannot be unambiguously\n // assigned when one inbound request fans out to N terminal flows.\n // Branches are dispatched with `respond: undefined`, and the\n // ChainResults returned to the outer aggregation are stripped of\n // any branch-internal respond so the outer fork's combined result\n // never propagates a branch's wrapped respond back to the caller.\n const branchResults = await Promise.all(\n forkIds.map((id) =>\n tryCatchAsync(runTransformerChain, (err) => {\n collector.logger\n .scope('transformer:many')\n .error(`many branch ${id} failed`, { error: err });\n return { event: null, respond: undefined };\n })(\n collector,\n transformers,\n walkChain(id, extractTransformerNextMap(transformers)),\n forkEvent,\n cloneIngest(forkIngest, id),\n undefined,\n chainContext,\n ),\n ),\n );\n // Strip per-branch side-channels (respond, stopped) at the many\n // boundary. The outer aggregation only learns about events from\n // branch ChainResults; respond and stopped are branch-internal\n // concerns and must not leak back to the surrounding fork's\n // combined result.\n return branchResults.map(\n (br): Transformer.ChainResult => ({\n event: br.event,\n respond: undefined,\n }),\n );\n }\n\n // Fork continues through remaining chain\n if (remainingChain.length > 0) {\n return runTransformerChain(\n collector,\n transformers,\n remainingChain,\n forkEvent,\n forkIngest,\n currentRespond,\n chainContext,\n );\n }\n return { event: forkEvent, respond: currentRespond };\n }),\n );\n\n // Collect events from ChainResult objects and track last respond\n let lastForkRespond = currentRespond;\n const flatEvents: WalkerOS.DeepPartialEvent[] = [];\n for (const fr of forkResults.flat()) {\n if (fr === null) continue;\n if (fr && typeof fr === 'object' && 'event' in fr) {\n const cr = fr as Transformer.ChainResult;\n if (cr.respond) lastForkRespond = cr.respond;\n if (cr.event === null) continue;\n if (Array.isArray(cr.event)) flatEvents.push(...cr.event);\n else flatEvents.push(cr.event);\n } else {\n flatEvents.push(fr as WalkerOS.DeepPartialEvent);\n }\n }\n if (flatEvents.length === 0)\n return { event: null, respond: lastForkRespond };\n if (flatEvents.length === 1)\n return { event: flatEvents[0], respond: lastForkRespond };\n return { event: flatEvents, respond: lastForkRespond };\n }\n\n if (result && typeof result === 'object') {\n // Unified TransformerResult handling\n const { event: resultEvent, respond: resultRespond, next } = result;\n\n // Update respond if transformer provided a wrapper\n if (resultRespond) {\n currentRespond = resultRespond;\n }\n\n // Handle chain branching.\n //\n // Dispatch uses `getNextSteps`:\n // - [] → no route matched; passthrough (continue main chain\n // with resultEvent if provided).\n // - ['x'] → walk static .next from x and run that as a single\n // subchain. The branched subchain's ChainResult\n // becomes this transformer's final result; the main\n // chain terminates here (explicit routing wins).\n // - ['a','b',...] → `many` fan-out. Terminal: each branch dispatches\n // as its own subchain with a per-branch ingest\n // clone. Main chain terminates here. Per-branch\n // error isolation arrives in Task 4.1; respond\n // suppression in 4.2.\n if (next !== undefined) {\n const nextIds = getNextSteps(\n next,\n buildCacheContext(ingest, processedEvent),\n );\n if (nextIds.length === 0) {\n // No route matched → passthrough (continue chain)\n if (resultEvent) processedEvent = resultEvent;\n continue;\n }\n if (nextIds.length === 1) {\n const branchedChain = walkChain(\n nextIds[0],\n extractTransformerNextMap(transformers),\n );\n if (branchedChain.length > 0) {\n return runTransformerChain(\n collector,\n transformers,\n branchedChain,\n resultEvent || processedEvent,\n ingest,\n currentRespond,\n chainContext,\n );\n }\n // Branch target not found — drop event (fail-safe).\n collector.logger.warn(\n `Branch target not found: ${JSON.stringify(next)}`,\n );\n return { event: null, respond: currentRespond };\n }\n // many: terminal fan-out. Main chain terminates here. Per-branch\n // error isolation (Task 4.1): wrap each branch dispatch in\n // `tryCatchAsync` so a throw in one branch does not reject the\n // surrounding `Promise.all` and starve siblings.\n // No-respond-across-many: respond ownership cannot be unambiguously\n // assigned when one inbound request fans out to N terminal flows.\n // Branches are dispatched with `respond: undefined`, branch results\n // are awaited and discarded, and the outer return has\n // `respond: undefined` so the parent caller (source) sees no\n // wrapped respond.\n // No-stopped-across-many (Task 4.2 / regression-guarded by Task 4.3):\n // branch results — including any `stopped: true` from a nested\n // `cache.stop` HIT inside one branch — are discarded here. The outer\n // return omits `stopped`, so a cache.stop HIT in one branch does NOT\n // halt sibling branches. See the regression test\n // `transformer.test.ts > many: cache.stop in one branch does not\n // halt sibling branches`.\n await Promise.all(\n nextIds.map((id) =>\n tryCatchAsync(runTransformerChain, (err) => {\n collector.logger\n .scope('transformer:many')\n .error(`many branch ${id} failed`, { error: err });\n return { event: null, respond: undefined };\n })(\n collector,\n transformers,\n walkChain(id, extractTransformerNextMap(transformers)),\n resultEvent || processedEvent,\n cloneIngest(ingest, id),\n undefined,\n chainContext,\n ),\n ),\n );\n return { event: null, respond: undefined };\n }\n\n // Update event if provided\n if (resultEvent) {\n processedEvent = resultEvent;\n }\n }\n // If result is undefined (void), continue with current event unchanged\n\n // Cache MISS: store the processed event after push\n if (cacheMiss && tCacheStore) {\n storeCache(tCacheStore, cacheMiss.key, processedEvent, cacheMiss.ttl);\n }\n\n // If transformer didn't return { next } but has a conditional\n // config.next (one / gate / sequence / many), resolve it per-request\n // via `getNextSteps`. Static (string / string[]) chains are wired\n // statically via the next-map and pre-baked into `chain` by the\n // caller (or by `walkChain` when an explicit chain array is passed);\n // re-dispatching them here would override an explicit caller chain.\n //\n // Dispatch (conditional variants only):\n // - [] → no match; chain ends here (passthrough).\n // - ['x'] → continue main chain via static walk from x.\n // - ['a','b',...] → `many` fan-out. Terminal: each branch dispatches\n // as its own subchain with a per-branch ingest\n // clone. Main chain terminates here.\n const configNext = transformer.config.next;\n const isStaticConfigNext =\n typeof configNext === 'string' ||\n (Array.isArray(configNext) &&\n configNext.every((entry) => typeof entry === 'string'));\n const isConditionalConfigNext =\n configNext !== undefined && !isStaticConfigNext;\n if (\n (!result || (typeof result === 'object' && !result.next)) &&\n isConditionalConfigNext\n ) {\n const configNextIds = getNextSteps(\n transformer.config.next,\n buildCacheContext(ingest, processedEvent),\n );\n if (configNextIds.length === 1) {\n const continuationChain = walkChain(\n configNextIds[0],\n extractTransformerNextMap(transformers),\n );\n if (continuationChain.length > 0) {\n return runTransformerChain(\n collector,\n transformers,\n continuationChain,\n processedEvent,\n ingest,\n currentRespond,\n chainContext,\n );\n }\n // Target not found → chain ends here (passthrough)\n return { event: processedEvent, respond: currentRespond };\n }\n if (configNextIds.length > 1) {\n // many: terminal fan-out. Main chain terminates here. Per-branch\n // error isolation (Task 4.1): wrap each branch dispatch in\n // `tryCatchAsync` so a throw in one branch does not reject the\n // surrounding `Promise.all` and starve siblings.\n // No-respond-across-many: respond ownership cannot be unambiguously\n // assigned when one inbound request fans out to N terminal flows.\n // Branches are dispatched with `respond: undefined`, branch results\n // are awaited and discarded, and the outer return has\n // `respond: undefined` so the parent caller (source) sees no\n // wrapped respond.\n await Promise.all(\n configNextIds.map((id) =>\n tryCatchAsync(runTransformerChain, (err) => {\n collector.logger\n .scope('transformer:many')\n .error(`many branch ${id} failed`, { error: err });\n return { event: null, respond: undefined };\n })(\n collector,\n transformers,\n walkChain(id, extractTransformerNextMap(transformers)),\n processedEvent,\n cloneIngest(ingest, id),\n undefined,\n chainContext,\n ),\n ),\n );\n return { event: null, respond: undefined };\n }\n // configNextIds.length === 0: no match → chain ends here\n return { event: processedEvent, respond: currentRespond };\n }\n }\n\n return { event: processedEvent, respond: currentRespond };\n}\n\n/**\n * Merges transformer environments.\n */\nfunction mergeTransformerEnvironments(\n configEnv?: Transformer.Env,\n): Transformer.Env {\n if (!configEnv) return {};\n if (isObject(configEnv)) return configEnv;\n return {};\n}\n","import type { Collector, Store } from '@walkeros/core';\nimport type { CompiledCache } from '@walkeros/core';\n\n/**\n * Returns the store for a compiled cache config.\n * Uses the explicit store reference if provided, otherwise falls back to the\n * collector's default __cache store.\n */\nexport function getCacheStore(\n compiled: CompiledCache,\n collector: Collector.Instance,\n): Store.Instance | undefined {\n if (compiled.storeId && collector.stores[compiled.storeId]) {\n return collector.stores[compiled.storeId];\n }\n return collector.stores.__cache;\n}\n","import type { Logger } from '@walkeros/core';\n\n/**\n * Bounded-append helpers for collector internal buffers.\n *\n * Three collector buffers are size-bounded:\n * - `collector.queue` (replay buffer for late-registered destinations)\n * - `destination.queuePush` (consent-denied buffer, per destination)\n * - `destination.dlq` (failed-push dead-letter queue, per destination)\n *\n * All three share the same FIFO ring-buffer eviction semantics, so the\n * append logic lives in one place. `pushBounded` performs the size check,\n * evicts oldest entries (or refuses the new one for `dropNewest`), and\n * reports drops back to the caller via the typed result + optional callback.\n *\n * Caller responsibility: increment the appropriate status counter\n * under `status.dropped[stepId]` (see `stepId()` in @walkeros/core)\n * and emit the warn-once-on-transition log. The helper stays pure: no logger\n * coupling, no collector reference.\n */\n\nexport type BufferOverflowPolicy = 'dropOldest' | 'dropNewest';\n\nexport interface BufferBound {\n max: number;\n onOverflow?: BufferOverflowPolicy;\n}\n\nexport interface PushBoundedResult {\n /** Whether the new item was appended to the buffer. */\n appended: boolean;\n /** Number of items dropped on this call (0 in the happy path). */\n dropped: number;\n}\n\n/**\n * Append `item` to `buffer`, respecting `bound.max`. On overflow, evict\n * per `bound.onOverflow` (defaults to `'dropOldest'`).\n *\n * @param buffer - In-place mutated array.\n * @param item - Item to append.\n * @param bound - Cap + overflow policy.\n * @param onDrop - Optional callback receiving the dropped items (oldest\n * evictions on `dropOldest`, or the rejected new item on `dropNewest`).\n * Called once per overflow event with all dropped items batched.\n * @returns `{ appended, dropped }`.\n */\nexport function pushBounded<T>(\n buffer: T[],\n item: T,\n bound: BufferBound,\n onDrop?: (dropped: T[]) => void,\n): PushBoundedResult {\n if (!Number.isFinite(bound.max) || bound.max <= 0) {\n throw new Error(`pushBounded: max must be > 0 (got ${bound.max})`);\n }\n\n const policy: BufferOverflowPolicy = bound.onOverflow ?? 'dropOldest';\n\n if (policy === 'dropNewest') {\n if (buffer.length >= bound.max) {\n if (onDrop) onDrop([item]);\n return { appended: false, dropped: 1 };\n }\n buffer.push(item);\n return { appended: true, dropped: 0 };\n }\n\n // dropOldest\n const dropped: T[] = [];\n while (buffer.length >= bound.max) {\n // Length-guarded shift; never undefined here (max > 0, length > 0).\n dropped.push(buffer.shift()!);\n }\n buffer.push(item);\n if (dropped.length > 0 && onDrop) onDrop(dropped);\n return { appended: true, dropped: dropped.length };\n}\n\n/**\n * Per-buffer overflow log state. Used to emit a single warn when a buffer\n * crosses from below-cap to at-cap, suppressing further warns until the\n * buffer drains below cap and overflows again (per Q13).\n */\nconst overflowState = new WeakMap<object, boolean>();\n\n/**\n * Emit a warn-once log on the transition into overflow. Subsequent drops\n * within the same overflow window stay silent until the buffer drains\n * (the caller signals \"below-cap again\" by calling `resetOverflow`).\n *\n * The cumulative drop counter is still incremented on every drop by the\n * caller, so operators retain rate signal via `collector.status.dropped[stepId]`.\n */\nexport function warnOverflowOnce(\n buffer: object,\n logger: Logger.Instance,\n message: string,\n context: Record<string, unknown>,\n): void {\n if (overflowState.get(buffer)) return;\n overflowState.set(buffer, true);\n logger.warn(message, context);\n}\n\n/**\n * Reset the overflow flag when a buffer drains below cap, so the next\n * overflow transition will warn again.\n */\nexport function resetOverflowFlag(buffer: object): void {\n overflowState.delete(buffer);\n}\n","import type {\n Collector,\n WalkerOS,\n Destination,\n Elb,\n Hooks,\n On,\n} from '@walkeros/core';\nimport { Const } from './constants';\nimport {\n addDestination,\n pushToDestinations,\n createPushResult,\n} from './destination';\nimport { assign, getSpanId, isFunction, isString } from '@walkeros/core';\nimport { isObject } from '@walkeros/core';\nimport { processConsent } from './consent';\nimport { on, onApply } from './on';\nimport { destroyAllSteps } from './shutdown';\nimport type { RunState } from './types/collector';\n\n/**\n * Handles common commands.\n *\n * @param collector The walkerOS collector instance.\n * @param action The action to handle.\n * @param data The data to handle.\n * @returns A promise that resolves with the push result or undefined.\n */\nexport async function commonHandleCommand(\n collector: Collector.Instance,\n action: string,\n data?: unknown,\n): Promise<Elb.PushResult> {\n let result: Elb.PushResult | undefined;\n let onData: unknown;\n let shouldNotify = false;\n\n switch (action) {\n case Const.Commands.Config:\n if (isObject(data)) {\n assign(collector.config, data as Partial<Collector.Config>, {\n shallow: false,\n });\n onData = data;\n shouldNotify = true;\n }\n break;\n\n case Const.Commands.Consent:\n if (isObject(data)) {\n const { update } = processConsent(collector, data as WalkerOS.Consent);\n onData = update;\n shouldNotify = true;\n }\n break;\n\n case Const.Commands.Custom:\n if (isObject(data)) {\n collector.custom = assign(\n collector.custom,\n data as WalkerOS.Properties,\n );\n onData = data;\n shouldNotify = true;\n }\n break;\n\n case Const.Commands.Destination:\n if (\n isObject(data) &&\n 'code' in data &&\n isObject((data as Destination.Init).code)\n ) {\n result = await addDestination(collector, data as Destination.Init);\n }\n break;\n\n case Const.Commands.Globals:\n if (isObject(data)) {\n collector.globals = assign(\n collector.globals,\n data as WalkerOS.Properties,\n );\n onData = data;\n shouldNotify = true;\n }\n break;\n\n case Const.Commands.Hook:\n if (\n isObject(data) &&\n isString((data as { name?: unknown }).name) &&\n isFunction((data as { fn?: unknown }).fn)\n ) {\n const { name, fn } = data as {\n name: string;\n fn: WalkerOS.AnyFunction;\n };\n collector.hooks[name as keyof Hooks.Functions] = fn;\n onData = data;\n shouldNotify = true;\n }\n break;\n\n case Const.Commands.On:\n if (isObject(data) && isString((data as { type?: unknown }).type)) {\n const { type, rules } = data as {\n type: On.Types;\n rules: WalkerOS.SingleOrArray<On.Subscription>;\n };\n await on(collector, type, rules);\n }\n break;\n\n case Const.Commands.Ready:\n shouldNotify = true;\n break;\n\n case Const.Commands.Run:\n result = await runCollector(collector, data as RunState);\n shouldNotify = true;\n break;\n\n case Const.Commands.Session:\n shouldNotify = true;\n break;\n\n case Const.Commands.Shutdown:\n await destroyAllSteps(collector);\n break;\n\n case Const.Commands.User:\n if (isObject(data)) {\n assign(collector.user, data as WalkerOS.User, { shallow: false });\n onData = data;\n shouldNotify = true;\n }\n break;\n }\n\n // Single notification + flush point for all state-mutation commands\n if (shouldNotify) {\n await onApply(collector, action as On.Types, undefined, onData);\n result = await pushToDestinations(collector);\n }\n\n return result || createPushResult({ ok: true });\n}\n\n/**\n * Creates a full event from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param partialEvent The partial event to transform.\n * @returns The full event.\n */\nexport function createEvent(\n collector: Collector.Instance,\n partialEvent: WalkerOS.PartialEvent,\n): WalkerOS.Event {\n if (!partialEvent.name) throw new Error('Event name is required');\n\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n const {\n timestamp = Date.now(),\n name = `${entityValue} ${actionValue}`,\n data = {},\n context = {},\n globals = collector.globals,\n custom = {},\n user = collector.user,\n nested = [],\n consent = collector.consent,\n id = getSpanId(),\n trigger = '',\n entity = entityValue,\n action = actionValue,\n timing = 0,\n source = { type: 'collector', schema: '4' },\n } = partialEvent;\n\n return {\n name,\n data,\n context,\n globals,\n custom,\n user,\n nested,\n consent,\n id,\n trigger,\n entity,\n action,\n timestamp,\n timing,\n source,\n };\n}\n\n/**\n * Runs the collector by setting it to allowed state and processing queued events.\n *\n * @param collector The walkerOS collector instance.\n * @param state Optional state to merge with the collector (user, globals, consent, custom).\n * @returns A promise that resolves with the push result.\n */\nexport async function runCollector(\n collector: Collector.Instance,\n state?: RunState,\n): Promise<Elb.PushResult> {\n // Set the collector to allowed state\n collector.allowed = true;\n\n // Update timing for this run\n collector.timing = Date.now();\n\n // Update collector state if provided\n if (state) {\n // Update consent if provided\n if (state.consent) {\n collector.consent = assign(collector.consent, state.consent);\n }\n\n // Update user if provided\n if (state.user) {\n collector.user = assign(collector.user, state.user);\n }\n\n // Update globals if provided\n if (state.globals) {\n collector.globals = assign(\n collector.config.globalsStatic || {},\n state.globals,\n );\n }\n\n // Update custom if provided\n if (state.custom) {\n collector.custom = assign(collector.custom, state.custom);\n }\n }\n\n // Reset destination queues\n Object.values(collector.destinations).forEach((destination) => {\n destination.queuePush = [];\n });\n\n // Reset collector queue for this run\n collector.queue = [];\n\n // Increase round counter\n collector.round++;\n\n // Process any queued events now that the collector is allowed\n const result = await pushToDestinations(collector);\n\n return result;\n}\n","import type { Collector, Lifecycle, Logger } from '@walkeros/core';\n\nconst STEP_TIMEOUT = 5000;\n\n/**\n * Destroy all steps in pipeline order: sources → destinations → transformers.\n * Called by the collector's `shutdown` command handler.\n */\nexport async function destroyAllSteps(\n collector: Collector.Instance,\n): Promise<void> {\n const logger = collector.logger;\n\n // Phase 1: Sources (stop intake)\n await destroyStepGroup(collector.sources, 'source', logger);\n\n // Phase 2: Destinations (close connections)\n await destroyStepGroup(collector.destinations, 'destination', logger);\n\n // Phase 3: Transformers (release caches)\n await destroyStepGroup(collector.transformers, 'transformer', logger);\n\n // Phase 4: Stores (release storage — last, so transformers can flush during their destroy)\n await destroyStepGroup(collector.stores, 'store', logger);\n}\n\nasync function destroyStepGroup<\n T extends { config: unknown; env?: unknown; type?: string },\n>(\n steps: Record<string, T>,\n label: string,\n rootLogger: Logger.Instance,\n): Promise<void> {\n const promises = Object.entries(steps).map(async ([id, step]) => {\n // Access destroy via cast: its DestroyContext<C,E> generic is contravariant,\n // so concrete step types aren't assignable to a structural destroy signature.\n // Safe because we pass each step's own config/env back to its own destroy.\n const destroy = (\n step as {\n destroy?: (ctx: Lifecycle.DestroyContext) => void | Promise<void>;\n }\n ).destroy;\n if (!destroy) return;\n\n const stepType = step.type || 'unknown';\n const logger = rootLogger.scope(stepType);\n\n const context: Lifecycle.DestroyContext = {\n id,\n config: step.config,\n env: step.env ?? {},\n logger,\n };\n\n try {\n await Promise.race([\n destroy(context),\n new Promise<void>((_, reject) =>\n setTimeout(\n () => reject(new Error(`${label} '${id}' destroy timed out`)),\n STEP_TIMEOUT,\n ),\n ),\n ]);\n } catch (err) {\n logger.error(`${label} '${id}' destroy failed: ${err}`);\n }\n });\n\n await Promise.allSettled(promises);\n}\n","import type { Collector, WalkerOS, Elb, Ingest } from '@walkeros/core';\nimport {\n createIngest,\n emitStep,\n FatalError,\n getGrantedConsent,\n processEventMapping,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEvent } from './handle';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { buildBaseState } from './observerEmit';\nimport { runTransformerChain } from './transformer';\n\nfunction filterDestinations(\n destinations: Collector.Destinations,\n include?: string[],\n exclude?: string[],\n): Collector.Destinations {\n let filtered = destinations;\n if (include) {\n filtered = Object.fromEntries(\n Object.entries(filtered).filter(([id]) => include.includes(id)),\n );\n }\n if (exclude) {\n filtered = Object.fromEntries(\n Object.entries(filtered).filter(([id]) => !exclude.includes(id)),\n );\n }\n return filtered;\n}\n\n/**\n * Creates the push function for the collector.\n * Handles source mapping, event creation, and routing to destinations.\n *\n * @param collector - The walkerOS collector instance\n * @param prepareEvent - Function to enrich partial events\n * @returns The push function\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Collector.PushFn {\n const innerPush = useHooks(\n async (\n event: WalkerOS.DeepPartialEvent,\n options: Collector.PushOptions = {},\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n const pushStart = Date.now();\n const {\n id,\n ingest,\n respond: initialRespond,\n mapping,\n preChain,\n include,\n exclude,\n } = options;\n let respond = initialRespond;\n let partialEvent = event;\n\n // Build filtered destination set if include/exclude specified\n const filteredDests =\n include || exclude\n ? filterDestinations(collector.destinations, include, exclude)\n : undefined;\n\n // Create mutable Ingest — accumulates context through the pipeline\n const pipelineIngest: Ingest =\n (ingest as Ingest | undefined) ?? createIngest(id || 'unknown');\n\n // Apply source mapping if provided in options\n if (mapping) {\n const processed = await processEventMapping(\n partialEvent,\n mapping,\n collector,\n );\n\n // Check ignore flag\n if (processed.ignore) {\n return createPushResult({ ok: true });\n }\n\n // Check consent requirements\n if (mapping.consent) {\n const grantedConsent = getGrantedConsent(\n mapping.consent,\n collector.consent,\n processed.event.consent as WalkerOS.Consent | undefined,\n );\n\n if (!grantedConsent) {\n return createPushResult({ ok: true });\n }\n }\n\n partialEvent = processed.event;\n }\n\n // Run pre-collector transformer chain if provided in options\n if (\n preChain?.length &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const chainResult = await runTransformerChain(\n collector,\n collector.transformers,\n preChain,\n partialEvent,\n pipelineIngest,\n respond,\n id ? `source.${id}.next` : undefined,\n );\n\n // Chain was stopped - event dropped\n if (chainResult.event === null) {\n return createPushResult({ ok: true });\n }\n\n // Pipeline-halt signal from a pre-collector `cache.stop: true`\n // HIT. The event is intentionally NOT forwarded to destinations;\n // duplicates are suppressed at the source.next boundary per the\n // documented \"downstream transformers and destinations are\n // skipped\" semantic in transformers/cache.mdx.\n if (chainResult.stopped) {\n if (chainResult.respond) respond = chainResult.respond;\n return createPushResult({ ok: true });\n }\n\n // Update respond if the chain produced a wrapped one\n if (chainResult.respond) respond = chainResult.respond;\n\n // Handle fan-out: array means multiple events from a single input\n if (Array.isArray(chainResult.event)) {\n // Process each forked event through the rest of the pipeline\n const forkResults = await Promise.all(\n chainResult.event.map(async (forkEvent) => {\n const enriched = prepareEvent(forkEvent);\n const full = createEvent(collector, enriched);\n return pushToDestinations(\n collector,\n full,\n {\n id,\n ingest: pipelineIngest,\n respond,\n },\n filteredDests,\n );\n }),\n );\n\n // Update source status\n if (id) {\n if (!collector.status.sources[id]) {\n collector.status.sources[id] = {\n count: 0,\n duration: 0,\n };\n }\n const sourceStatus = collector.status.sources[id];\n sourceStatus.count += chainResult.event.length;\n sourceStatus.lastAt = Date.now();\n sourceStatus.duration += Date.now() - pushStart;\n }\n\n return forkResults[0] ?? createPushResult({ ok: true });\n }\n\n partialEvent = chainResult.event;\n }\n\n // Prepare event (add timing, source info)\n const enrichedEvent = prepareEvent(partialEvent);\n\n // Create full event\n const fullEvent = createEvent(collector, enrichedEvent);\n\n // Push to destinations with id and ingest\n const result = await pushToDestinations(\n collector,\n fullEvent,\n {\n id,\n ingest: pipelineIngest,\n respond,\n },\n filteredDests,\n );\n\n // Update source status\n if (id) {\n if (!collector.status.sources[id]) {\n collector.status.sources[id] = {\n count: 0,\n duration: 0,\n };\n }\n const sourceStatus = collector.status.sources[id];\n sourceStatus.count++;\n sourceStatus.lastAt = Date.now();\n sourceStatus.duration += Date.now() - pushStart;\n }\n\n return result;\n },\n (err: unknown) => {\n if (err instanceof FatalError) throw err;\n collector.status.failed++;\n collector.logger.error('push failed', {\n event,\n ingest: options.ingest,\n error: err,\n });\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n collector.logger,\n );\n\n const wrapped: Collector.PushFn = async (event, options) => {\n const eventId = typeof event.id === 'string' ? event.id : '';\n const started = Date.now();\n emitStep(\n collector,\n buildBaseState(collector, {\n stepId: 'collector.push',\n stepType: 'collector',\n phase: 'in',\n eventId,\n now: started,\n }),\n );\n\n try {\n const result = await innerPush(event, options);\n const finished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: 'collector.push',\n stepType: 'collector',\n phase: 'out',\n eventId,\n now: finished,\n });\n outState.durationMs = finished - started;\n outState.outEvent = result;\n emitStep(collector, outState);\n return result;\n } catch (err) {\n const finished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: 'collector.push',\n stepType: 'collector',\n phase: 'error',\n eventId,\n now: finished,\n });\n errState.durationMs = finished - started;\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n };\n\n return wrapped;\n}\n","import type { Collector, Elb } from '@walkeros/core';\nimport type { HandleCommandFn } from './types/collector';\nimport { FatalError, useHooks, tryCatchAsync } from '@walkeros/core';\nimport { createPushResult } from './destination';\n\n/**\n * Creates the command function for the collector.\n * Handles walker commands (config, consent, destination, etc.)\n *\n * @param collector - The walkerOS collector instance\n * @param handleCommand - Command handler function\n * @returns The command function\n */\nexport function createCommand<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n): Collector.CommandFn {\n return useHooks(\n async (\n command: string,\n data?: unknown,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n return await handleCommand(collector, command, data, options);\n },\n (err: unknown) => {\n if (err instanceof FatalError) throw err;\n collector.status.failed++;\n collector.logger.error('command failed', {\n command,\n data,\n error: err,\n });\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Command',\n collector.hooks,\n collector.logger,\n );\n}\n","import type { Cache, Collector, Store } from '@walkeros/core';\nimport { emitStep, useHooks } from '@walkeros/core';\nimport { createCacheStore } from './cache-store';\nimport { buildBaseState } from './observerEmit';\nimport { wrapStoreWithCache } from './store-cache-wrapper';\n\n/**\n * Narrowed view of a `Store.InitStore` entry that also carries the optional\n * `cache` configuration emitted by the bundler. The runtime `Store.InitStores`\n * map is loosely typed at the core level so it can carry pass-through fields\n * (`cache`, `variables`, etc.) without coupling the core `Store.InitStore`\n * shape to flow-level concerns. Phase 2 reads `cache` through this local view.\n */\ntype InitStoreWithCache = Store.InitStore & {\n cache?: Cache.Cache<Cache.StoreCacheRule>;\n};\n\n/**\n * Hook wrapping and observer emission for a single store instance.\n * Mutates `instance` in place.\n *\n * Called once per store, AFTER any cache wrapping in phase 2. Wrapping the\n * outer (wrapper) instance means observers see the consumer-facing\n * boundary: they fire on every `wrapped.get` regardless of cache HIT/MISS,\n * and only once per `wrapped.set` (not also for the wrapper's internal\n * write into `cacheStore`). If the store has no cache wrapper, the bare\n * backing is wrapped instead, preserving observability.\n *\n * Two responsibilities per op:\n * 1. Inner `useHooks(..., 'StoreGet', ...)` wrap keeps the generic\n * user-declared hook contract working (`preStoreGet`, `postStoreSet`,\n * etc.).\n * 2. Outer self-emit wrap pushes `FlowState` (`stepType: 'store'`) into\n * `collector.observers` directly, so per-store telemetry no longer\n * needs a separate hook bag.\n */\nfunction applyStoreHooks(\n collector: Collector.Instance,\n instance: Store.Instance,\n storeId: string,\n): void {\n const stepIdFor = `store.${storeId}`;\n\n const innerGet = useHooks(\n instance.get,\n 'StoreGet',\n collector.hooks,\n collector.logger,\n );\n const innerSet = useHooks(\n instance.set,\n 'StoreSet',\n collector.hooks,\n collector.logger,\n );\n const innerDelete = useHooks(\n instance.delete,\n 'StoreDelete',\n collector.hooks,\n collector.logger,\n );\n\n instance.get = async (key: string): Promise<unknown> => {\n const started = Date.now();\n const inState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'in',\n eventId: '',\n now: started,\n });\n inState.meta = { op: 'get', key };\n emitStep(collector, inState);\n\n try {\n const result = await innerGet(key);\n const finished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'out',\n eventId: '',\n now: finished,\n });\n outState.durationMs = finished - started;\n outState.meta = { op: 'get', key };\n emitStep(collector, outState);\n return result;\n } catch (err) {\n const finished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'error',\n eventId: '',\n now: finished,\n });\n errState.durationMs = finished - started;\n errState.meta = { op: 'get', key };\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n };\n\n instance.set = async (\n key: string,\n value: unknown,\n ttl?: number,\n ): Promise<void> => {\n const started = Date.now();\n const inState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'in',\n eventId: '',\n now: started,\n });\n // Store values can be secrets or PII: emit only the op + key, never the\n // raw value, on any phase (in/out/error). Observers see what happened,\n // not what was written.\n inState.meta = { op: 'set', key };\n emitStep(collector, inState);\n\n try {\n await innerSet(key, value, ttl);\n const finished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'out',\n eventId: '',\n now: finished,\n });\n outState.durationMs = finished - started;\n outState.meta = { op: 'set', key };\n emitStep(collector, outState);\n } catch (err) {\n const finished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'error',\n eventId: '',\n now: finished,\n });\n errState.durationMs = finished - started;\n errState.meta = { op: 'set', key };\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n };\n\n instance.delete = async (key: string): Promise<void> => {\n const started = Date.now();\n const inState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'in',\n eventId: '',\n now: started,\n });\n inState.meta = { op: 'delete', key };\n emitStep(collector, inState);\n\n try {\n await innerDelete(key);\n const finished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'out',\n eventId: '',\n now: finished,\n });\n outState.durationMs = finished - started;\n outState.meta = { op: 'delete', key };\n emitStep(collector, outState);\n } catch (err) {\n const finished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'error',\n eventId: '',\n now: finished,\n });\n errState.durationMs = finished - started;\n errState.meta = { op: 'delete', key };\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n };\n}\n\n/**\n * Walks the `cache.store` graph in topological order (terminals first) and\n * reports each store id together with its cache config. Detects cycles via\n * three-color DFS (WHITE → GRAY → BLACK) and rejects references to unknown\n * store ids. Throws on the first problem with a message naming the path.\n *\n * The returned order is suitable for wrapping: when a wrapper is built for\n * store X, its `cache.store` target (if any) has already been wrapped.\n */\nfunction topoOrderForCacheWrap(\n defs: Record<string, InitStoreWithCache>,\n): string[] {\n type Color = 'WHITE' | 'GRAY' | 'BLACK';\n const color: Record<string, Color> = {};\n for (const id of Object.keys(defs)) color[id] = 'WHITE';\n\n const order: string[] = [];\n const stack: string[] = [];\n\n function visit(id: string): void {\n const c = color[id];\n if (c === 'BLACK') return;\n if (c === 'GRAY') {\n const cycleStart = stack.indexOf(id);\n const cyclePath = stack\n .slice(cycleStart === -1 ? 0 : cycleStart)\n .concat(id)\n .join(' -> ');\n throw new Error(`Cycle in cache.store chain: ${cyclePath}`);\n }\n\n color[id] = 'GRAY';\n stack.push(id);\n\n const target = defs[id].cache?.store;\n if (target !== undefined) {\n if (!(target in defs)) {\n throw new Error(\n `Store \"${id}\" cache.store references \"${target}\", which is not declared in flow.stores`,\n );\n }\n visit(target);\n }\n\n stack.pop();\n color[id] = 'BLACK';\n order.push(id);\n }\n\n for (const id of Object.keys(defs)) {\n if (color[id] === 'WHITE') visit(id);\n }\n\n return order;\n}\n\n/**\n * Initialize store instances from configuration.\n *\n * Three-phase init:\n * Phase 1, instantiate: call `code(context)` for every declared store.\n * Order is not significant in this phase. Hooks are NOT installed yet —\n * they wrap the outer boundary in phase 3.\n * Phase 2, topologically wrap: walk the `cache.store` graph, detect cycles\n * and unknown targets, then visit terminals first so any cache wrapper\n * installed in Task 7+ can rely on its backing being already wrapped.\n * Phase 3, install hooks: wrap the final instance (wrapper if cache was\n * applied, otherwise the bare backing) so hooks fire at the consumer\n * boundary and observe cache HIT/MISS behavior.\n *\n * Phase 2 must run before `resolveStoreReferences` in `collector.ts` so that\n * env-reference replacement uses the wrapped instance (referential identity\n * matters for the resolver).\n */\nexport async function initStores(\n collector: Collector.Instance,\n initStores: Store.InitStores = {},\n): Promise<Store.Stores> {\n const result: Store.Stores = {};\n\n // Phase 1: instantiate every store. Hooks are deferred to phase 3 so they\n // can wrap the outer (cache-wrapped) instance and observe HIT/MISS at the\n // consumer-facing boundary.\n for (const [storeId, storeDef] of Object.entries(initStores)) {\n const { code, config = {}, env = {} } = storeDef;\n\n const storeLogger = collector.logger.scope('store').scope(storeId);\n\n const context = {\n collector,\n logger: storeLogger,\n id: storeId,\n config,\n env,\n };\n\n const instance = await code(context);\n result[storeId] = instance;\n }\n\n // Phase 2: validate the cache.store graph and wrap in topological order.\n // Cycle and missing-target errors propagate out of `topoOrderForCacheWrap`.\n // Read-through wrapping is delegated to `wrapStoreWithCache`. The cache\n // layer is either a user-declared store (resolved against the in-progress\n // `result` map) or the default `__cache`, which is created lazily here so\n // it ends up assigned to `collector.stores` together with the rest.\n const defsWithCache = initStores as Record<string, InitStoreWithCache>;\n const order = topoOrderForCacheWrap(defsWithCache);\n for (const storeId of order) {\n const cacheConfig = defsWithCache[storeId].cache;\n if (!cacheConfig) continue;\n\n let cacheStore: Store.Instance;\n let cacheStoreId: string;\n if (cacheConfig.store !== undefined) {\n // Missing-target validation already ran in `topoOrderForCacheWrap`, so\n // this lookup is guaranteed to hit.\n cacheStore = result[cacheConfig.store];\n cacheStoreId = cacheConfig.store;\n } else {\n if (!result.__cache) {\n result.__cache = createCacheStore();\n }\n cacheStore = result.__cache;\n cacheStoreId = '__cache';\n }\n\n // Schema rejects `namespace: \"\"` for store caches, so the only way the\n // wrapper sees an absent namespace is when the user omitted it entirely.\n // In that case default to the host store id so multiple wrapped stores\n // sharing `__cache` cannot collide on raw keys.\n const resolvedNamespace = cacheConfig.namespace ?? storeId;\n\n // One startup log line per wrapped store. Operators inspecting the cache\n // layer see prefixed keys (e.g. `api:K`); surfacing the resolved namespace\n // and cache-store id here keeps that defaulting from feeling like hidden\n // magic. Scope mirrors the wrapper's own scope (Task 8) so all\n // cache-related output groups under `store-cache:<id>`.\n collector.logger\n .scope('store-cache')\n .scope(storeId)\n .info(\n `store \"${storeId}\" caches with namespace \"${resolvedNamespace}:\" via ${cacheStoreId}`,\n );\n\n result[storeId] = wrapStoreWithCache(result[storeId], {\n storeId,\n cacheConfig,\n cacheStore,\n namespace: resolvedNamespace,\n logger: collector.logger.scope('store-cache').scope(storeId),\n collector,\n });\n }\n\n // Phase 3: install hooks on the final instance for every user-declared\n // store. Wrapping the OUTER instance (wrapper if a cache was applied,\n // bare backing otherwise) means the hook fires at the consumer-facing\n // boundary and observes cache HIT/MISS. The auto-created default\n // `__cache` is skipped — it has no consumer-facing contract; users never\n // call `__cache.get` directly. Skipping it also prevents the wrapper's\n // internal writes into the default cache from double-firing\n // `preStoreSet` against the consumer-facing boundary.\n for (const [storeId, instance] of Object.entries(result)) {\n if (storeId === '__cache') continue;\n applyStoreHooks(collector, instance, storeId);\n }\n\n return result;\n}\n\n/**\n * Resolve store references in component env values.\n *\n * The bundler resolves `$store.gcs` to a direct JS reference to the raw\n * store definition object (`stores.gcs = { code, config }`). After stores\n * are initialized, this function walks transformer/destination/source env\n * objects and replaces any raw store definition reference with the\n * corresponding initialized Store.Instance.\n *\n * IMPORTANT: Uses referential identity (`===`) to match env values against\n * raw store definitions. This works because the bundler generates code where\n * env values are direct references to the same objects in the `stores` map.\n * Programmatic configs must use the same object reference — copies won't match.\n *\n * Only resolves top-level env keys. Nested store references are not supported.\n */\nexport function resolveStoreReferences(\n rawStores: Store.InitStores,\n initializedStores: Store.Stores,\n initConfig: Collector.InitConfig,\n): void {\n // Build a lookup: raw store def → initialized instance (O(1) per env value)\n const lookup = new Map<object, Store.Instance>();\n for (const [storeId, rawDef] of Object.entries(rawStores)) {\n if (initializedStores[storeId])\n lookup.set(rawDef, initializedStores[storeId]);\n }\n if (lookup.size === 0) return;\n\n function resolveEnv(env: Record<string, unknown> | undefined) {\n if (!env) return;\n for (const [key, value] of Object.entries(env)) {\n if (typeof value === 'object' && value !== null) {\n const instance = lookup.get(value);\n if (instance) env[key] = instance;\n }\n }\n }\n\n // Walk all component types that may have env values\n for (const defs of [\n initConfig.transformers,\n initConfig.destinations,\n initConfig.sources,\n ]) {\n if (!defs) continue;\n for (const def of Object.values(defs)) {\n resolveEnv((def as { env?: Record<string, unknown> }).env);\n }\n }\n}\n","import type { Store } from '@walkeros/core';\n\n/**\n * Options for the built-in collector cache store (`__cache`).\n *\n * The default cache is an entry-capped LRU with active TTL sweep. Byte-size\n * accounting is opt-in: when `maxSize` is `undefined`, no byte budget is\n * enforced.\n */\nexport interface CacheStoreOptions {\n /** Hard cap on entries. Defaults to 10000. */\n maxEntries?: number;\n /**\n * Optional byte budget for the cache. When set, byte-sized eviction is\n * enabled in addition to entry-count eviction. Defaults to `undefined`\n * (no byte budget).\n */\n maxSize?: number;\n /**\n * Active sweep interval (ms) for purging expired entries even when they\n * are never read. Defaults to 60_000 (60 seconds). Pass 0 to disable.\n */\n sweepIntervalMs?: number;\n /**\n * Fraction of `maxEntries` to keep after a batched eviction pass. Defaults\n * to 0.8. The cache trims to `maxEntries * lowWaterMark` in one pass on\n * overflow.\n */\n lowWaterMark?: number;\n}\n\n/**\n * Operational counters exposed by the cache store. All counters are\n * monotonic for the lifetime of the cache instance.\n */\nexport interface CacheStoreCounters {\n /** Successful `get` calls that returned a live cached value. */\n hits: number;\n /** `get` calls that found no entry (cold) or only an expired one. */\n misses: number;\n /** `set` calls that created a new key (first-time population). */\n populates: number;\n /** All `set` calls (populates + overwrites). */\n writes: number;\n /** All `delete` calls that removed an existing key. */\n deletes: number;\n /** Entries removed because the cache hit `maxEntries`. */\n evictions_entries: number;\n /** Entries removed because their TTL expired (sweep or lazy). */\n evictions_ttl: number;\n}\n\ninterface CacheEntry {\n value: unknown;\n expires?: number;\n}\n\n/**\n * The upgraded `__cache` store. Backward-compatible with the existing\n * `Store.Instance` shape — callers see `get(key)`, `set(key, value, ttl?)`,\n * `delete(key)`. Adds an observability surface via `counters` and an active\n * TTL sweep that runs on a timer.\n *\n * Eviction model:\n * - Map iteration order is insertion order; oldest insertion is the FIFO head.\n * - `get` reorders the entry to most-recently-used (delete + re-insert).\n * - On insert overflow (size > maxEntries), evict in one pass down to\n * `lowWaterMark * maxEntries` (default 80%).\n *\n * Active TTL sweep: every `sweepIntervalMs` ms, walk the map and drop any\n * entries past `expires`. The interval is cleared in `destroy()`.\n */\nexport type CacheStore = Store.Instance & {\n readonly counters: CacheStoreCounters;\n destroy: () => void;\n};\n\nconst DEFAULT_MAX_ENTRIES = 10000;\nconst DEFAULT_SWEEP_INTERVAL_MS = 60_000;\nconst DEFAULT_LOW_WATER_MARK = 0.8;\n\nexport function createCacheStore(options: CacheStoreOptions = {}): CacheStore {\n const maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;\n const lowWaterMark = options.lowWaterMark ?? DEFAULT_LOW_WATER_MARK;\n const sweepIntervalMs = options.sweepIntervalMs ?? DEFAULT_SWEEP_INTERVAL_MS;\n const targetSize = Math.floor(maxEntries * lowWaterMark);\n\n const entries = new Map<string, CacheEntry>();\n\n const counters: CacheStoreCounters = {\n hits: 0,\n misses: 0,\n populates: 0,\n writes: 0,\n deletes: 0,\n evictions_entries: 0,\n evictions_ttl: 0,\n };\n\n function evictOverflow(): void {\n if (entries.size <= maxEntries) return;\n // Trim in one pass down to targetSize using insertion-order iteration\n // (oldest first). LRU is preserved because `get` re-inserts on access.\n const toRemove = entries.size - targetSize;\n let removed = 0;\n for (const key of entries.keys()) {\n if (removed >= toRemove) break;\n entries.delete(key);\n removed++;\n }\n counters.evictions_entries += removed;\n }\n\n function sweep(): void {\n const now = Date.now();\n let removed = 0;\n for (const [key, entry] of entries) {\n if (entry.expires !== undefined && entry.expires <= now) {\n entries.delete(key);\n removed++;\n }\n }\n counters.evictions_ttl += removed;\n }\n\n let sweepTimer: ReturnType<typeof setInterval> | undefined;\n if (sweepIntervalMs > 0) {\n sweepTimer = setInterval(sweep, sweepIntervalMs);\n // Don't keep the Node.js event loop alive solely for the cache sweep.\n if (\n sweepTimer &&\n typeof (sweepTimer as { unref?: () => void }).unref === 'function'\n ) {\n (sweepTimer as { unref: () => void }).unref();\n }\n }\n\n const store: CacheStore = {\n type: 'memory',\n config: {},\n\n get(key: string): unknown {\n const entry = entries.get(key);\n if (!entry) {\n counters.misses++;\n return undefined;\n }\n\n if (entry.expires !== undefined && entry.expires <= Date.now()) {\n entries.delete(key);\n counters.evictions_ttl++;\n counters.misses++;\n return undefined;\n }\n\n // LRU: move to most-recently-used position.\n entries.delete(key);\n entries.set(key, entry);\n counters.hits++;\n return entry.value;\n },\n\n set(key: string, value: unknown, ttl?: number): void {\n const isNew = !entries.has(key);\n // Always delete first so re-insert puts the entry at the\n // most-recently-used position regardless of overwrite or new.\n if (!isNew) entries.delete(key);\n\n entries.set(key, {\n value,\n expires: ttl !== undefined ? Date.now() + ttl : undefined,\n });\n\n counters.writes++;\n if (isNew) counters.populates++;\n\n if (entries.size > maxEntries) evictOverflow();\n },\n\n delete(key: string): void {\n if (entries.delete(key)) counters.deletes++;\n },\n\n get counters() {\n // Return a snapshot so external callers can't mutate internal state.\n return { ...counters };\n },\n\n destroy(): void {\n if (sweepTimer !== undefined) {\n clearInterval(sweepTimer);\n sweepTimer = undefined;\n }\n entries.clear();\n },\n };\n\n return store;\n}\n","import type { Cache, Collector, Logger, Store } from '@walkeros/core';\nimport { compileMatcher, emitStep } from '@walkeros/core';\nimport { buildBaseState } from './observerEmit';\n\n/**\n * Options passed to `wrapStoreWithCache`. Pre-resolved by `initStores` phase\n * 2 so the wrapper itself stays small and side-effect free at construction.\n *\n * - `cacheStore` is the store layer where cached values live. Defaults to\n * the collector's `__cache` instance, but may be any other initialized\n * store (e.g. a fs-backed cache for cross-process sharing).\n * - `namespace` is the prefix prepended to every key written to the cache\n * layer. Defaults to `storeId` when the user did not override\n * `cache.namespace`.\n * - `logger` is the collector's scoped logger, used for the best-effort\n * warnings emitted when a cache-side write or delete fails. Optional only\n * to keep test setups lightweight — production call sites pass\n * `collector.logger`.\n */\nexport interface WrappedStoreOptions {\n storeId: string;\n cacheConfig: Cache.Cache<Cache.StoreCacheRule>;\n cacheStore: Store.Instance;\n namespace: string;\n logger?: Logger.Instance;\n /**\n * Optional collector reference for cache-level observability. When\n * provided, the wrapper emits a `FlowState` (`stepType: 'store'`,\n * `meta.op: 'cache'`) on every wrapped `get`, carrying the resolved\n * cache status (`'hit'` or `'miss'`) and the key. Observers attached\n * to `collector.observers` see HIT/MISS without coupling to wrapper\n * internals. Optional only to keep unit-test setups lightweight;\n * production call sites pass it.\n */\n collector?: Collector.Instance;\n}\n\ninterface CompiledStoreCacheRule {\n match: (context: Record<string, unknown>) => boolean;\n ttl: number;\n}\n\n/**\n * Per-wrapped-store observability counters. The `evictions_*` counters live on\n * the underlying cache store (`createCacheStore` returns its own counters\n * surface for the global `__cache`), so they are deliberately absent here.\n *\n * Semantics:\n * - `hits` — `cacheStore.get` returned a defined value.\n * - `misses` — cache returned undefined AND no in-flight Promise was joined\n * (this caller is the one driving the backing fetch).\n * - `populates` — the wrapper wrote into the cache after a backing MISS that\n * returned a defined value AND matched a rule.\n * - `writes` — every call to `wrapper.set`, regardless of cache outcome.\n * - `deletes` — every call to `wrapper.delete`.\n * - `inflight_dedups` — a get found an in-flight Promise on the same key and\n * joined it instead of starting a new backing call.\n */\nexport interface WrappedStoreCounters {\n hits: number;\n misses: number;\n populates: number;\n writes: number;\n deletes: number;\n inflight_dedups: number;\n}\n\n/**\n * Public-facing extension of `Store.Instance` with the per-wrapper counter\n * surface. Consumers that need observability (operator UIs, debug endpoints)\n * cast to this type via `as WrappedStoreInstance`; everything else continues\n * to see the canonical `Store.Instance` shape and stays decoupled from the\n * wrapper's internals.\n */\nexport interface WrappedStoreInstance extends Store.Instance {\n /**\n * Snapshot accessor: returns a fresh copy of the counter map on every\n * access. Mutating the returned object never affects internal state, so\n * callers can serialize, diff, or send the snapshot freely. The returned\n * object always carries every counter key, zero-initialized.\n */\n readonly counters: WrappedStoreCounters;\n}\n\n/**\n * Wrap a backing `Store.Instance` with a read-through cache layer.\n *\n * Read semantics:\n * 1. Probe the cache at `namespace:key`. Any non-undefined value is a HIT.\n * 2. On MISS, delegate to `backing.get(key)`.\n * 3. If the backing returned a defined value AND a rule matches the\n * `{ key, value }` context, populate the cache with `rule.ttl * 1000` ms.\n * Negative caching (caching `undefined`) is intentionally not supported.\n *\n * Write semantics (`set` / `delete`) follow the \"cache is advisory\" policy\n * documented in `docs/plans/2026-05-13-store-cache-design.md` (Write path and\n * error policy):\n * - Backing first. If `backing.set`/`backing.delete` throws, the wrapper\n * throws and the cache layer is never touched. The backing is the source\n * of truth and its failures must surface to the caller.\n * - Cache best-effort. After a successful backing write, attempt the cache\n * write. A throwing cache layer is logged via `logger.warn` and swallowed\n * so the wrapper still resolves successfully — the next read will MISS\n * and re-populate. Failed cache deletes leave a stale entry that serves\n * until TTL; the warning lets operators react.\n */\nexport function wrapStoreWithCache(\n backing: Store.Instance,\n opts: WrappedStoreOptions,\n): WrappedStoreInstance {\n const { cacheConfig, cacheStore, namespace, logger, storeId, collector } =\n opts;\n\n // Cache observability. Each wrapped `get` resolves to a HIT or MISS;\n // the wrapper emits a `FlowState` on the collector so observers can\n // record cache metadata without coupling to wrapper internals. When\n // `collector` is absent (unit-test path), reporting is skipped.\n const reportCacheStatus = (key: string, status: 'hit' | 'miss'): void => {\n if (!collector) return;\n const state = buildBaseState(collector, {\n stepId: `store.${storeId}`,\n stepType: 'store',\n phase: 'in',\n eventId: '',\n now: Date.now(),\n });\n state.meta = {\n op: 'cache',\n cached: status === 'hit',\n status,\n key,\n };\n emitStep(collector, state);\n };\n\n // Closure-scoped counters. Mutated directly at each path; the public\n // `counters` accessor on the returned instance returns a fresh shallow copy\n // so external consumers cannot mutate internal state.\n const counters: WrappedStoreCounters = {\n hits: 0,\n misses: 0,\n populates: 0,\n writes: 0,\n deletes: 0,\n inflight_dedups: 0,\n };\n\n // Pre-compile each rule's matcher once at wrap time. Rules without a `match`\n // clause are treated as always-matching, mirroring the EventCacheRule\n // helpers in `packages/core/src/cache.ts`.\n const compiledRules: CompiledStoreCacheRule[] = cacheConfig.rules.map(\n (rule) => ({\n match: rule.match ? compileMatcher(rule.match) : () => true,\n ttl: rule.ttl,\n }),\n );\n\n const prefixed = (key: string): string => `${namespace}:${key}`;\n\n function findMatchingRule(\n key: string,\n value: unknown,\n ): CompiledStoreCacheRule | undefined {\n // Store-cache context shape is `{ key, value? }` — no `ingest`. The value\n // is omitted when the caller has not yet read from the backing (e.g.\n // future write-path callers).\n const ctx: Record<string, unknown> =\n value === undefined ? { key } : { key, value };\n return compiledRules.find((r) => r.match(ctx));\n }\n\n // Closure-scoped in-flight registry: N concurrent gets on the same cold key\n // share one backing call. Keyed by the namespaced cache key so distinct\n // backing keys never collide. The entry is removed in `finally` so a\n // settled (resolved or rejected) Promise never lingers — a subsequent get\n // either hits the now-populated cache or retries the backing.\n const inFlight = new Map<string, Promise<unknown>>();\n\n return {\n type: backing.type,\n config: backing.config,\n setup: backing.setup,\n\n // Snapshot accessor. Returning a fresh shallow copy on every read keeps\n // the internal counter object un-aliased: consumers that store, diff, or\n // serialize the snapshot cannot inadvertently mutate state.\n get counters(): WrappedStoreCounters {\n return { ...counters };\n },\n\n async get(key: string): Promise<unknown> {\n const ns = prefixed(key);\n const cached = await cacheStore.get(ns);\n if (cached !== undefined) {\n counters.hits++;\n reportCacheStatus(key, 'hit');\n return cached;\n }\n\n // Single-flight: if another caller is already fetching this key, join\n // their Promise rather than starting a second backing call.\n const existing = inFlight.get(ns);\n if (existing) {\n counters.inflight_dedups++;\n reportCacheStatus(key, 'hit');\n return existing;\n }\n\n // This caller drives the backing fetch — count the MISS once here so\n // joined callers above are not double-counted as misses too.\n counters.misses++;\n reportCacheStatus(key, 'miss');\n\n const promise = (async () => {\n try {\n const value = await backing.get(key);\n if (value === undefined) return undefined;\n\n const rule = findMatchingRule(key, value);\n if (rule) {\n // Best-effort cache populate. Mirrors the Task 8 write-path\n // policy: backing has already returned, so a throwing cache layer\n // must not surface as an unhandled rejection on the shared\n // Promise that other concurrent callers are awaiting.\n try {\n // `cache.ttl` is documented in seconds; the underlying cache\n // store accepts ms. Multiply once at the boundary to keep the\n // rest of the pipeline consistent with EventCache semantics.\n await cacheStore.set(ns, value, rule.ttl * 1000);\n // Count the populate only after the cache write resolves so a\n // failed populate (logged below) does not inflate the counter.\n counters.populates++;\n } catch (error) {\n warnCacheFailure('set', key, error);\n }\n }\n return value;\n } finally {\n // Always release the slot — on resolve so the next read hits the\n // now-populated cache, on reject so a transient backing failure\n // doesn't freeze the key forever behind a dead Promise.\n inFlight.delete(ns);\n }\n })();\n inFlight.set(ns, promise);\n return promise;\n },\n\n async set(key: string, value: unknown, ttl?: number): Promise<void> {\n // Count every set the moment the wrapper is entered, before any IO.\n // The counter reflects intent (how many writes the wrapper has been\n // asked to perform), independent of backing or cache success.\n counters.writes++;\n\n // Backing first. A throw here propagates: backing is the source of\n // truth, callers must see real write failures.\n await backing.set(key, value, ttl);\n\n const rule = findMatchingRule(key, value);\n if (!rule) return;\n\n // Best-effort cache populate. Wrap only the cache-side call: backing\n // errors above have already propagated, so this try/catch is scoped to\n // the advisory layer.\n try {\n await cacheStore.set(prefixed(key), value, rule.ttl * 1000);\n } catch (error) {\n warnCacheFailure('set', key, error);\n }\n },\n\n async delete(key: string): Promise<void> {\n // Mirrors `writes`: count intent at entry, before backing or cache IO.\n counters.deletes++;\n\n // Backing first; same propagation rules as `set`.\n await backing.delete(key);\n\n try {\n await cacheStore.delete(prefixed(key));\n } catch (error) {\n warnCacheFailure('delete', key, error);\n }\n },\n };\n\n function warnCacheFailure(\n op: 'set' | 'delete',\n key: string,\n error: unknown,\n ): void {\n const message = `store-cache(${storeId}): cache ${op} failed for \"${key}\"; backing succeeded, continuing`;\n if (logger) {\n logger.warn(message, { error });\n } else {\n // Defensive fallback so unit tests that do not thread a logger still\n // surface the failure rather than swallowing it silently. Production\n // call sites in `store.ts` always pass `collector.logger`.\n // eslint-disable-next-line no-console\n console.warn(message, error);\n }\n }\n}\n","import type { Collector, Source, WalkerOS, Elb } from '@walkeros/core';\nimport { createPushResult } from './destination';\n\n/**\n * Creates the default ELB source.\n * Routes between collector.push and collector.command based on input.\n * Provides backward-compatible flexible argument interface.\n *\n * @param collector - The walkerOS collector instance\n * @returns ELB source instance\n */\nexport function createElbSource(\n collector: Collector.Instance,\n): Source.Instance {\n return {\n type: 'elb',\n config: {},\n\n // The push function is the elb() interface users interact with\n push: async (\n eventOrCommand?: unknown,\n data?: unknown,\n context?: unknown,\n nested?: WalkerOS.Entities,\n custom?: WalkerOS.Properties,\n ): Promise<Elb.PushResult> => {\n // Detect walker commands\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n const command = eventOrCommand.replace('walker ', '');\n return collector.command(command, data);\n }\n\n // Build event object\n let event: WalkerOS.DeepPartialEvent;\n\n if (typeof eventOrCommand === 'string') {\n // Convert string to object: elb('page view', { title: 'Home' })\n event = { name: eventOrCommand };\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = data as WalkerOS.Properties;\n }\n } else if (eventOrCommand && typeof eventOrCommand === 'object') {\n // Use object directly: elb({ name: 'page view', data: {...} })\n event = eventOrCommand as WalkerOS.DeepPartialEvent;\n // Merge additional data if provided\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = {\n ...(event.data || {}),\n ...(data as WalkerOS.Properties),\n };\n }\n } else {\n // Invalid input\n return createPushResult({ ok: false });\n }\n\n // Add optional properties if provided\n if (context && typeof context === 'object') {\n event.context = context as WalkerOS.OrderedProperties;\n }\n if (nested && Array.isArray(nested)) {\n event.nested = nested;\n }\n if (custom && typeof custom === 'object') {\n event.custom = custom as WalkerOS.Properties;\n }\n\n // Call collector.push with event object\n return collector.push(event);\n },\n };\n}\n","import type { Collector, Elb } from '@walkeros/core';\nimport type { StartFlow } from './types';\nimport { collector } from './collector';\nimport { createElbSource } from './elb';\nimport { initSources } from './source';\n\nexport async function startFlow<ElbPush extends Elb.Fn = Elb.Fn>(\n initConfig?: Collector.InitConfig,\n): Promise<StartFlow<ElbPush>> {\n initConfig = initConfig || {};\n const instance = await collector(initConfig);\n\n // Create and register ELB source first\n const elbSource = createElbSource(instance);\n instance.sources.elb = elbSource;\n\n // Now initialize other sources with ELB source available\n await initSources(instance, initConfig.sources || {});\n\n const { consent, user, globals, custom } = initConfig;\n\n if (consent) await instance.command('consent', consent);\n if (user) await instance.command('user', user);\n if (globals) Object.assign(instance.globals, globals);\n if (custom) Object.assign(instance.custom, custom);\n\n if (instance.config.run) await instance.command('run');\n\n // Determine the primary elb:\n // 1. Use explicitly marked primary source\n // 2. Use first non-elb source if any exist\n // 3. Fallback to ELB source\n let primaryElb: Elb.Fn = elbSource.push as Elb.Fn;\n\n const sources = Object.values(instance.sources).filter(\n (source) => source.type !== 'elb',\n );\n\n // First, check for explicitly marked primary source\n const markedPrimary = sources.find(\n (source) => (source.config as { primary?: boolean }).primary,\n );\n\n if (markedPrimary) {\n primaryElb = markedPrimary.push as Elb.Fn;\n } else if (sources.length > 0) {\n // Use first source as default\n primaryElb = sources[0].push as Elb.Fn;\n }\n\n return {\n collector: instance,\n elb: primaryElb as ElbPush,\n };\n}\n","import type { Simulation } from '@walkeros/core';\n\ninterface WrapResult {\n /** Env with tracked paths wrapped by recording functions */\n wrappedEnv: Record<string, unknown>;\n /** Mutable array — calls are pushed here during step execution */\n calls: Simulation.Call[];\n}\n\nfunction deepClone(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') return obj;\n if (Array.isArray(obj)) return obj.map(deepClone);\n const clone: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj as Record<string, unknown>)) {\n clone[key] = typeof value === 'function' ? value : deepClone(value);\n }\n return clone;\n}\n\n/**\n * Wrap tracked paths in a destination env with recording wrappers.\n *\n * The env object must include a `simulation: string[]` declaring which\n * dot-paths to intercept. Returns a cloned env (without `simulation`)\n * where those paths record every call into the `calls` array.\n */\nexport function wrapEnv(\n env: Record<string, unknown> & { simulation: string[] },\n): WrapResult {\n const calls: Simulation.Call[] = [];\n const { simulation, ...rest } = env;\n\n // Deep clone the env to avoid mutating the original (preserves functions)\n const wrappedEnv = deepClone(rest) as Record<string, unknown>;\n\n for (const rawPath of simulation) {\n // Strip optional \"call:\" prefix\n const path = rawPath.startsWith('call:') ? rawPath.slice(5) : rawPath;\n const segments = path.split('.');\n\n // Navigate to the parent\n let target: Record<string, unknown> = wrappedEnv;\n for (let i = 0; i < segments.length - 1; i++) {\n if (target[segments[i]] == null) break;\n target = target[segments[i]] as Record<string, unknown>;\n }\n\n const leaf = segments[segments.length - 1];\n if (target == null || !(leaf in target)) continue;\n\n const original = target[leaf];\n\n if (typeof original === 'function') {\n target[leaf] = function (this: unknown, ...args: unknown[]) {\n calls.push({ fn: path, args, ts: Date.now() });\n return original.apply(this, args);\n };\n }\n }\n\n return { wrappedEnv, calls };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;;;ACGO,IAAM,WAAwD;AAAA,EACnE,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,KAAK;AAAA,EACL,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,KAAK;AAAA,EACL,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,QAAQ;AACV;AAEA,IAAM,eAA+C;AAAA,EACnD,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS;AACX;AAEA,IAAM,QAAQ;AAAA,EACZ,SAAS;AACX;AAEO,IAAM,QAAQ;AAAA,EACnB;AAAA,EACA;AACF;;;ACtCA,kBAAuB;AAMhB,SAAS,eACdA,YACA,MAC8B;AAC9B,QAAM,SAA2B,CAAC;AAClC,SAAO,QAAQ,IAAI,EAAE,QAAQ,CAAC,CAAC,M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,QAAM,aAAa,UAAU,IAAI;AAEjC,aAAW,WAAW,YAAY;AAEhC,UAAM,OAAO,QAAQ,WAAW,OAAO,IAAI,QAAQ,MAAM,CAAC,IAAI;AAC9D,UAAM,WAAW,KAAK,MAAM,GAAG;AAG/B,QAAI,SAAkC;AACtC,aAAS,IAAI,GAAG,IAAI,SAAS,SAAS,GAAG,KAAK;AAC5C,UAAI,OAAO,SAAS,CAAC,CAAC,KAAK,KAAM;AACjC,eAAS,OAAO,SAAS,CAAC,CAAC;AAAA,IAC7B;AAEA,UAAM,OAAO,SAAS,SAAS,SAAS,CAAC;AACzC,QAAI,UAAU,QAAQ,EAAE,QAAQ,QAAS;AAEzC,UAAM,WAAW,OAAO,IAAI;AAE5B,QAAI,OAAO,aAAa,YAAY;AAClC,aAAO,IAAI,IAAI,YAA4B,MAAiB;AAC1D,cAAM,KAAK,EAAE,IAAI,MAAM,MAAM,IAAI,KAAK,IAAI,EAAE,CAAC;AAC7C,eAAO,SAAS,MAAM,MAAM,IAAI;AAAA,MAClC;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,YAAY,MAAM;AAC7B;","names":["collector","import_core","import_core","import_core","collector","import_core","import_core","collector","require","import_core","import_core","collector","collector","initTransformers","collector","collector","on","option","collector","event","isInitialized","batchState","destIdResolved","destStatus","import_core","collector","collector","import_core","collector","import_core","collector","import_core","import_core","collector","collector","initStores","collector","collector","clone"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/types/code.ts","../src/constants.ts","../src/consent.ts","../src/collector.ts","../src/destination.ts","../src/observerEmit.ts","../src/on.ts","../src/pending.ts","../src/source.ts","../src/transformer.ts","../src/cache.ts","../src/buffers.ts","../src/handle.ts","../src/shutdown.ts","../src/push.ts","../src/command.ts","../src/store.ts","../src/cache-store.ts","../src/store-cache-wrapper.ts","../src/elb.ts","../src/flow.ts","../src/wrapEnv.ts"],"sourcesContent":["export * from './types';\n\nexport * from './constants';\n\nexport * from './consent';\nexport * from './flow';\nexport * from './push';\nexport * from './destination';\nexport * from './handle';\nexport * from './on';\nexport * from './source';\nexport {\n runTransformerChain,\n transformerPush,\n transformerInit,\n walkChain,\n extractTransformerNextMap,\n} from './transformer';\nexport { wrapEnv } from './wrapEnv';\nexport { getCacheStore } from './cache';\n","import type { Destination, Mapping, On, WalkerOS } from '@walkeros/core';\n\nexport interface Settings {\n scripts?: string[];\n init?: string;\n on?: string;\n push?: string;\n pushBatch?: string;\n}\n\nexport interface CodeMapping extends Mapping.Rule<CodeMapping> {\n push?: string;\n pushBatch?: string;\n}\n\nexport type Types = Destination.Types<Settings, CodeMapping>;\nexport type Config = Destination.Config<Types>;\nexport type Context = Destination.Context<Types>;\nexport type PushContext = Destination.PushContext<Types>;\nexport type PushBatchContext = Destination.PushBatchContext<Types>;\n\nexport type InitFn = (context: Context) => void;\nexport type OnFn = (type: On.Types, context: Context) => void;\nexport type PushFn = (event: WalkerOS.Event, context: PushContext) => void;\nexport type PushBatchFn = (\n batch: Destination.Batch<CodeMapping>,\n context: PushBatchContext,\n) => void;\n","import type { Collector } from '@walkeros/core';\nimport type { CommandTypes, StorageType } from './types/collector';\n\nexport const Commands: Record<CommandTypes, Collector.CommandType> = {\n Action: 'action',\n Actions: 'actions',\n Config: 'config',\n Consent: 'consent',\n Context: 'context',\n Custom: 'custom',\n Destination: 'destination',\n Elb: 'elb',\n Globals: 'globals',\n Hook: 'hook',\n Init: 'init',\n Link: 'link',\n On: 'on',\n Prefix: 'data-elb',\n Ready: 'ready',\n Run: 'run',\n Session: 'session',\n Shutdown: 'shutdown',\n User: 'user',\n Walker: 'walker',\n} as const;\n\nconst UtilsStorage: { [key: string]: StorageType } = {\n Cookie: 'cookie',\n Local: 'local',\n Session: 'session',\n} as const;\n\nconst Utils = {\n Storage: UtilsStorage,\n};\n\nexport const Const = {\n Commands,\n Utils,\n};\n\nexport default Const;\n","import type { Collector, WalkerOS } from '@walkeros/core';\nimport { assign } from '@walkeros/core';\n\n/**\n * Processes consent data: coerces to boolean, updates collector state.\n * Does NOT notify or process queues — caller handles that.\n */\nexport function processConsent(\n collector: Collector.Instance,\n data: WalkerOS.Consent,\n): { update: WalkerOS.Consent } {\n const update: WalkerOS.Consent = {};\n Object.entries(data).forEach(([name, granted]) => {\n update[name] = !!granted;\n });\n\n collector.consent = assign(collector.consent, update);\n\n return { update };\n}\n","import type { Collector, Logger, WalkerOS } from '@walkeros/core';\nimport { assign, createLogger } from '@walkeros/core';\nimport { commonHandleCommand } from './handle';\nimport { initDestinations } from './destination';\nimport { initTransformers } from './transformer';\nimport { createPush } from './push';\nimport { createCommand } from './command';\nimport { initSources } from './source';\nimport { initStores, resolveStoreReferences } from './store';\nimport { createCacheStore } from './cache-store';\n\n// Replaced at build time by tsup's `define` (see packages/config/tsup).\ndeclare const __VERSION__: string;\n\nexport async function collector(\n initConfig: Collector.InitConfig,\n): Promise<Collector.Instance> {\n const defaultConfig: Collector.Config = {\n globalsStatic: {},\n sessionStatic: {},\n run: true,\n queueMax: 1_000,\n };\n\n const config: Collector.Config = assign(defaultConfig, initConfig, {\n merge: false,\n extend: false,\n });\n\n // Create logger with config from initConfig\n const loggerConfig: Logger.Config = {\n level: initConfig.logger?.level,\n handler: initConfig.logger?.handler,\n };\n const logger = createLogger(loggerConfig);\n\n // Enhanced globals with static globals from config\n const finalGlobals = { ...config.globalsStatic, ...initConfig.globals };\n\n const collector: Collector.Instance = {\n allowed: false,\n config,\n consent: initConfig.consent || {},\n custom: initConfig.custom || {},\n destinations: {},\n transformers: {},\n stores: {},\n globals: finalGlobals,\n hooks: initConfig.hooks || {},\n observers: new Set(),\n logger,\n on: {},\n queue: [],\n round: 0,\n session: undefined,\n status: {\n startedAt: Date.now(),\n in: 0,\n out: 0,\n failed: 0,\n sources: {},\n destinations: {},\n dropped: {},\n },\n timing: Date.now(),\n user: initConfig.user || {},\n sources: {},\n pending: { destinations: {} },\n push: undefined as unknown as Collector.PushFn, // Placeholder, will be set below\n command: undefined as unknown as Collector.CommandFn, // Placeholder, will be set below\n };\n\n // Set the push and command functions with the collector reference\n collector.push = createPush(\n collector,\n (event: WalkerOS.DeepPartialEvent): WalkerOS.PartialEvent =>\n ({\n timing: Math.round((Date.now() - collector.timing) / 10) / 100,\n source: { type: 'collector', schema: '4', version: __VERSION__ },\n ...event,\n }) as WalkerOS.PartialEvent,\n );\n\n collector.command = createCommand(collector, commonHandleCommand);\n\n // Initialize stores (first - other components may depend on them)\n const rawStores = initConfig.stores || {};\n collector.stores = await initStores(collector, rawStores);\n\n // Resolve store references in component env values.\n // The bundler emits `$store.gcs` as a direct reference to `stores.gcs`\n // (the raw {code, config} definition). After initialization, replace\n // these raw references with the actual Store.Instance objects.\n resolveStoreReferences(rawStores, collector.stores, initConfig);\n\n // Create default cache store for steps that use cache without explicit store.\n // Uses LRU + entry cap + batched eviction + active TTL sweep. See\n // `cache-store.ts` for the full semantics.\n if (!collector.stores.__cache) {\n collector.stores.__cache = createCacheStore();\n }\n\n // Initialize destinations after collector is fully created\n // Sources are initialized in startFlow after ELB source is created\n collector.destinations = await initDestinations(\n collector,\n initConfig.destinations || {},\n );\n\n // Initialize transformers\n collector.transformers = await initTransformers(\n collector,\n initConfig.transformers || {},\n );\n\n return collector;\n}\n","import type {\n Cache,\n Collector,\n WalkerOS,\n Elb,\n Destination,\n Transformer,\n Ingest,\n} from '@walkeros/core';\nimport {\n assign,\n buildCacheContext,\n clone,\n compileCache,\n checkCache,\n storeCache,\n createIngest,\n debounce,\n emitStep,\n getId,\n getGrantedConsent,\n getNextSteps,\n isDefined,\n isFunction,\n isObject,\n processEventMapping,\n stepId,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { buildBaseState } from './observerEmit';\nimport { callDestinationOn } from './on';\nimport {\n runTransformerChain,\n walkChain,\n extractTransformerNextMap,\n extractChainProperty,\n} from './transformer';\nimport { getCacheStore } from './cache';\nimport { pushBounded, resetOverflowFlag, warnOverflowOnce } from './buffers';\n\nconst DEFAULT_QUEUE_MAX = 1_000;\nconst DEFAULT_DLQ_MAX = 100;\n/** Default upper-bound on entries per batch. Caps unbounded growth under sustained load. */\nconst DEFAULT_BATCH_SIZE = 1_000;\n/** Default upper-bound on batch age in ms. Forces flush even if debounce keeps resetting. */\nconst DEFAULT_BATCH_AGE = 30_000;\n\n/**\n * Sentinel returned by {@link destinationPush} when an event was enqueued\n * into a batch (not delivered synchronously). The aggregation pass in\n * {@link pushToDestinations} reads this to skip the per-event `count`\n * increment; counters are bumped by the flush callback instead, after\n * `pushBatch` resolves. Per PROD-004 plan Q9: increment on successful\n * flush per entry, not on enqueue.\n */\nconst BATCHED_RESULT: { batched: true } = Object.freeze({ batched: true });\n\nfunction isBatchedResult(value: unknown): boolean {\n return value === BATCHED_RESULT;\n}\n\n/**\n * Normalize a batch config value to the canonical `{ wait?, size?, age? }`\n * shape. A bare number is treated as `wait` (legacy form). `undefined`\n * normalizes to an empty object so callers can chain `??` lookups.\n */\nfunction normalizeBatchOptions(\n value: number | Destination.BatchOptions | undefined,\n): { wait?: number; size?: number; age?: number } {\n if (value === undefined) return {};\n if (typeof value === 'number') return { wait: value };\n return { wait: value.wait, size: value.size, age: value.age };\n}\n\n/**\n * Ensure a per-destination status entry exists and return it.\n * Mirrors the shape used elsewhere in this file.\n */\nfunction ensureDestStatus(\n collector: Collector.Instance,\n destId: string,\n): Collector.DestinationStatus {\n if (!collector.status.destinations[destId]) {\n collector.status.destinations[destId] = {\n count: 0,\n failed: 0,\n duration: 0,\n queuePushSize: 0,\n dlqSize: 0,\n };\n }\n return collector.status.destinations[destId];\n}\n\n/**\n * Bump a drop counter under `status.dropped[stepId][buffer]`. Lazily\n * creates the per-step entry; returns the new counter value so callers\n * can pass it straight into the warn-once log payload.\n */\nfunction bumpDropped(\n status: Collector.Status,\n id: string,\n buffer: 'queue' | 'dlq',\n n: number,\n): number {\n if (!status.dropped[id]) status.dropped[id] = {};\n const entry = status.dropped[id];\n entry[buffer] = (entry[buffer] ?? 0) + n;\n return entry[buffer]!;\n}\n\n/**\n * Resolves transformer chain for a destination.\n *\n * `getNextSteps` returns the immediate next-step ids for the given Route in\n * the supplied context. `walkChain` then follows static `.next` links from\n * each entry to produce the full ordered chain. The WeakMap inside\n * `getNextSteps` caches the compiled form, so we don't re-compile per event.\n *\n * post-collector destination.before disallows `many` (enforced at the schema\n * layer via `RouteWithoutManySchema`), so we never see more than one id here\n * unless a user passes an explicit string[] chain — in which case we want to\n * treat it as the explicit chain (no further walking).\n *\n * `transformerNextMap` is computed once per `pushToDestinations` call (it depends\n * only on `collector.transformers`) and passed in to avoid rebuilding it for\n * every destination's before and next chain resolution.\n */\nfunction resolveDestinationChain(\n before: Transformer.Route | undefined,\n transformerNextMap: ReturnType<typeof extractTransformerNextMap>,\n ingest?: Ingest,\n): string[] {\n if (!before) return [];\n // Static string[] chains pass through unchanged — they are explicit and\n // suppress `.next` walking. Static single-string starts are walked.\n if (\n Array.isArray(before) &&\n before.every((entry) => typeof entry === 'string')\n ) {\n return walkChain(before, transformerNextMap);\n }\n if (typeof before === 'string') {\n return walkChain(before, transformerNextMap);\n }\n // Conditional shape — resolve per-event, walk single-id result.\n const ids = getNextSteps(before, buildCacheContext(ingest));\n if (ids.length === 0) return [];\n if (ids.length === 1) return walkChain(ids[0], transformerNextMap);\n // Multiple ids from a conditional shape: treat as explicit chain.\n // (destination.before disallows `many`; this path is reached only if a\n // RouteConfig.next resolves to a string[], which is then the user's\n // declared chain.)\n return walkChain(ids, transformerNextMap);\n}\n\n/**\n * Adds a new destination to the collector.\n *\n * @param collector - The walkerOS collector instance.\n * @param data - The destination's init data.\n * @returns The result of the push operation.\n */\nexport async function addDestination(\n collector: Collector.Instance,\n data: Destination.Init,\n): Promise<Elb.PushResult> {\n const { code, config: dataConfig = {}, env = {}, before, next, cache } = data;\n\n // Validate that code has a push method\n if (!isFunction(code.push)) {\n return createPushResult({\n ok: false,\n failed: {\n invalid: {\n type: 'invalid',\n error: 'Destination code must have a push method',\n },\n },\n });\n }\n\n const baseConfig = dataConfig || { init: false };\n // Merge before, next, and cache into config if provided at root level\n let config = before ? { ...baseConfig, before } : { ...baseConfig };\n if (next) config = { ...config, next };\n if (cache) config = { ...config, cache };\n\n const destination: Destination.Instance = {\n ...code,\n config,\n env: mergeEnvironments(code.env, env),\n };\n\n let id = destination.config.id; // Use given id\n if (!id) {\n // Generate a new id if none was given (lowercase alpha only for readability)\n do {\n id = getId(5, 'abcdefghijklmnopqrstuvwxyz');\n } while (collector.destinations[id]);\n }\n\n // Add the destination\n collector.destinations[id] = destination;\n\n // Process previous events if not disabled\n if (destination.config.queue !== false)\n destination.queuePush = [...collector.queue];\n\n return pushToDestinations(collector, undefined, {}, { [id]: destination });\n}\n\n/**\n * Pushes an event to all or a subset of destinations.\n *\n * @param collector - The walkerOS collector instance.\n * @param event - The event to push.\n * @param meta - Optional metadata with id and ingest.\n * @param destinations - The destinations to push to.\n * @returns The result of the push operation.\n */\nexport async function pushToDestinations(\n collector: Collector.Instance,\n event?: WalkerOS.Event,\n meta: {\n id?: string;\n ingest?: Ingest;\n respond?: import('@walkeros/core').RespondFn;\n } = {},\n destinations?: Collector.Destinations,\n): Promise<Elb.PushResult> {\n const { allowed, consent, globals, user } = collector;\n\n // Check if collector is allowed to push\n if (!allowed) return createPushResult({ ok: false });\n\n // Add event to the collector queue (bounded; FIFO drop-oldest on overflow)\n if (event) {\n const queueMax = collector.config.queueMax;\n if (queueMax === undefined) {\n throw new Error(\n 'Collector.Config.queueMax is undefined; defaults must be seeded by collector()',\n );\n }\n const result = pushBounded(collector.queue, event, { max: queueMax });\n if (result.dropped > 0) {\n const droppedCount = bumpDropped(\n collector.status,\n stepId('collector'),\n 'queue',\n result.dropped,\n );\n warnOverflowOnce(\n collector.queue,\n collector.logger,\n 'collector.queue overflow; oldest events dropped',\n {\n buffer: 'queue',\n cap: queueMax,\n droppedCount,\n },\n );\n } else if (collector.queue.length < queueMax) {\n resetOverflowFlag(collector.queue);\n }\n collector.status.in++;\n }\n\n // Use given destinations or use internal destinations\n if (!destinations) destinations = collector.destinations;\n\n // Precompute the transformer next map once per push (shared across all\n // destinations in this batch, used for both before and next chain resolution).\n // Guarded because tests and partially-initialized collectors may pass\n // `transformers` as undefined.\n const transformerNextMap = collector.transformers\n ? extractTransformerNextMap(collector.transformers)\n : {};\n\n const results = await Promise.all(\n // Process all destinations in parallel\n Object.entries(destinations || {}).map(async ([id, destination]) => {\n // Disabled destinations are completely skipped — no queuing, no init, no processing\n if (destination.config.disabled) {\n return { id, destination, skipped: true };\n }\n\n // Queued events: refresh consent (full replace — stale consent must not persist).\n // User/globals merge happens for all events below in allowedEvents.map.\n let currentQueue = (destination.queuePush || []).map((event) => ({\n ...event,\n consent,\n }));\n destination.queuePush = [];\n\n // Current event: added as-is (consent is already fresh from createEvent).\n if (event) currentQueue.push(clone(event));\n\n // Clone ingest for this destination (prevents cross-destination races in Promise.all)\n const destIngest: Ingest = meta.ingest\n ? {\n ...meta.ingest,\n _meta: { ...meta.ingest._meta, path: [...meta.ingest._meta.path] },\n }\n : createIngest('unknown');\n\n // If no events and no queued on events, skip this destination\n if (!currentQueue.length && !destination.queueOn?.length) {\n return { id, destination, skipped: true };\n }\n\n // If only on events queued (no push events), still init to flush queueOn.\n // Direct try/catch + logger.error here is intentional. Previously this\n // used tryCatchAsync(destinationInit) without an onError callback, which\n // silently returned undefined when init threw, hiding real failures on\n // the queueOn-only path. Mirrors the same pattern used below at the main\n // init call site so failures are never silent on either branch.\n if (!currentQueue.length && destination.queueOn?.length) {\n let isInitialized = false;\n try {\n isInitialized = await destinationInit(collector, destination, id);\n } catch (err) {\n collector.status.failed++;\n const destType = destination.type || 'unknown';\n collector.logger.scope(destType).error('destination init failed', {\n error: err instanceof Error ? err.message : String(err),\n });\n }\n return { id, destination, skipped: !isInitialized };\n }\n\n const allowedEvents: WalkerOS.Events = [];\n const skippedEvents = currentQueue.filter((queuedEvent) => {\n const grantedConsent = getGrantedConsent(\n destination.config.consent, // Required\n consent, // Current collector state\n queuedEvent.consent, // Individual event state\n );\n\n if (grantedConsent) {\n queuedEvent.consent = grantedConsent; // Save granted consent states only\n\n allowedEvents.push(queuedEvent); // Add to allowed queue\n return false; // Remove from destination queue\n }\n\n // Emit a skip state for the consent-denied event so observers can\n // see the gate decision per-event.\n const skipState = buildBaseState(collector, {\n stepId: stepId('destination', id),\n stepType: 'destination',\n phase: 'skip',\n eventId: typeof queuedEvent.id === 'string' ? queuedEvent.id : '',\n now: Date.now(),\n });\n skipState.skipReason = 'consent';\n if (consent) skipState.consent = { ...consent };\n if (destination.config.consent) {\n skipState.meta = { required: { ...destination.config.consent } };\n }\n emitStep(collector, skipState);\n\n return true; // Keep denied events in the queue\n });\n\n // Add skipped (consent-denied) events back to the queue.\n // Bounded; FIFO drop-oldest on overflow.\n if (skippedEvents.length > 0) {\n const queuePush = destination.queuePush;\n const destId = destination.config.id || id;\n const bound = {\n max: destination.config.queueMax ?? DEFAULT_QUEUE_MAX,\n };\n let totalDropped = 0;\n for (const skipped of skippedEvents) {\n const r = pushBounded(queuePush, skipped, bound);\n totalDropped += r.dropped;\n }\n if (totalDropped > 0) {\n // Ensure status entry exists for early-overflow paths.\n ensureDestStatus(collector, destId);\n const droppedCount = bumpDropped(\n collector.status,\n stepId('destination', destId),\n 'queue',\n totalDropped,\n );\n warnOverflowOnce(\n queuePush,\n collector.logger.scope(destination.type || 'unknown'),\n 'destination.queuePush overflow; oldest events dropped',\n {\n buffer: 'queuePush',\n destination: destId,\n cap: bound.max,\n droppedCount,\n },\n );\n } else if (queuePush.length < bound.max) {\n resetOverflowFlag(queuePush);\n }\n }\n\n // Execution shall not pass if no events are allowed\n if (!allowedEvents.length) {\n return { id, destination, queue: currentQueue }; // Don't push if not allowed\n }\n\n // Initialize the destination if needed.\n // Direct try/catch + logger.error here is intentional. Previously this\n // used tryCatchAsync(destinationInit) without an onError callback, which\n // silently returned undefined when init threw, hiding real failures. The\n // destination itself may also log a more specific error before throwing;\n // this is the boundary safety net so failures are never silent.\n let isInitialized = false;\n try {\n isInitialized = await destinationInit(collector, destination, id);\n } catch (err) {\n collector.status.failed++;\n const destType = destination.type || 'unknown';\n collector.logger.scope(destType).error('destination init failed', {\n error: err instanceof Error ? err.message : String(err),\n });\n }\n\n if (!isInitialized) return { id, destination, queue: currentQueue };\n\n // Process the destinations event queue\n let error: unknown;\n let response: unknown;\n if (!destination.dlq) destination.dlq = [];\n\n // Resolve the before chain once per destination batch (the per-event\n // resolution inside getNextSteps is WeakMap-cached, so this is cheap).\n const before = destination.config.before;\n const postChain = resolveDestinationChain(\n before,\n transformerNextMap,\n destIngest,\n );\n\n // Capture the next chain config; resolution happens per-event below.\n const nextConfig = destination.config.next;\n\n // Compile destination cache once per batch (not per-event).\n // Destination caches operate on events (HIT/MISS keyed by event fields),\n // so the rule shape is always EventCacheRule, not StoreCacheRule.\n const destCacheConfig = destination.config?.cache as\n | Cache.Cache<Cache.EventCacheRule>\n | undefined;\n const compiledDCache = destCacheConfig\n ? compileCache(destCacheConfig)\n : undefined;\n const dCacheStore = compiledDCache\n ? getCacheStore(compiledDCache, collector)\n : undefined;\n\n // Process allowed events and store failed ones in the dead letter queue (DLQ)\n let totalDuration = 0;\n // Count of events enqueued into a batch in this pass; the aggregation\n // below uses this to skip the synchronous `count++` for batched events\n // (counters move to the flush callback per PROD-004 plan Q9).\n let batchedCount = 0;\n await Promise.all(\n allowedEvents.map(async (event) => {\n // Merge collector state into event (collector as base, event overrides)\n event.globals = assign(globals, event.globals);\n event.user = assign(user, event.user);\n\n // Full cache check: before the before chain (skips everything on HIT)\n let cacheMiss: { key: string; ttl: number } | undefined;\n if (compiledDCache?.stop && dCacheStore) {\n const cacheContext = buildCacheContext(destIngest, event);\n const cacheResult = await checkCache(\n compiledDCache,\n dCacheStore,\n cacheContext,\n );\n if (cacheResult?.status === 'HIT') {\n return event; // Skip before chain + push\n }\n if (cacheResult?.status === 'MISS') {\n cacheMiss = { key: cacheResult.key, ttl: cacheResult.rule.ttl };\n }\n }\n\n // Run post-collector transformer chain if configured for this destination\n let processedEvent: WalkerOS.Event | null = event;\n let destRespond = meta.respond;\n if (\n postChain.length > 0 &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const chainResult = await runTransformerChain(\n collector,\n collector.transformers,\n postChain,\n event,\n destIngest,\n meta.respond,\n `destination.${id}.before`,\n );\n\n if (chainResult.event === null) {\n // Chain stopped - skip this event for this destination\n return event;\n }\n\n // Update respond if the chain produced a wrapped one\n if (chainResult.respond) destRespond = chainResult.respond;\n\n // Use the processed event (cast back to full Event type)\n // Before chains use first result if fan-out occurred\n processedEvent = (\n Array.isArray(chainResult.event)\n ? chainResult.event[0]\n : chainResult.event\n ) as WalkerOS.Event;\n }\n\n // Step-level cache check: after before chain, skip only push on HIT\n if (compiledDCache && !compiledDCache.stop && dCacheStore) {\n const cacheContext = buildCacheContext(destIngest, processedEvent);\n const cacheResult = await checkCache(\n compiledDCache,\n dCacheStore,\n cacheContext,\n );\n if (cacheResult?.status === 'HIT') {\n return event; // Skip push — deduplicated\n }\n if (cacheResult?.status === 'MISS') {\n cacheMiss = { key: cacheResult.key, ttl: cacheResult.rule.ttl };\n }\n }\n\n const pushStart = Date.now();\n let pushFailed = false;\n const result = await tryCatchAsync(destinationPush, (err) => {\n // Log the error with destination scope\n const destType = destination.type || 'unknown';\n collector.logger.scope(destType).error('Push failed', {\n error: err,\n event: processedEvent!.name,\n });\n error = err; // oh no\n pushFailed = true;\n\n // Add failed event to destinations DLQ (bounded; FIFO drop-oldest)\n const dlq = destination.dlq!;\n const destId = destination.config.id || id;\n const dlqBound = {\n max: destination.config.dlqMax ?? DEFAULT_DLQ_MAX,\n };\n const dlqResult = pushBounded(\n dlq,\n [processedEvent!, err],\n dlqBound,\n );\n if (dlqResult.dropped > 0) {\n ensureDestStatus(collector, destId);\n const droppedCount = bumpDropped(\n collector.status,\n stepId('destination', destId),\n 'dlq',\n dlqResult.dropped,\n );\n warnOverflowOnce(\n dlq,\n collector.logger.scope(destination.type || 'unknown'),\n 'destination.dlq overflow; oldest entries dropped',\n {\n buffer: 'dlq',\n destination: destId,\n cap: dlqBound.max,\n droppedCount,\n },\n );\n } else if (dlq.length < dlqBound.max) {\n resetOverflowFlag(dlq);\n }\n\n return undefined;\n })(\n collector,\n destination,\n id,\n processedEvent!,\n destIngest,\n destRespond,\n );\n totalDuration += Date.now() - pushStart;\n\n // Destination cache MISS: store the push result after attempt\n if (\n cacheMiss &&\n dCacheStore &&\n destination.config.mock === undefined\n ) {\n storeCache(\n dCacheStore,\n cacheMiss.key,\n result ?? true,\n cacheMiss.ttl,\n );\n }\n\n // Capture the last response (for single event pushes).\n // Batched-enqueue sentinel is NOT a real response; don't surface it.\n if (result !== undefined && !isBatchedResult(result)) {\n response = result;\n }\n if (isBatchedResult(result)) batchedCount++;\n\n // Run destination.next chain after successful push\n if (!pushFailed && nextConfig) {\n // Write push response to ingest for destination.next transformers\n if (result !== undefined) {\n destIngest._response = result;\n }\n\n const nextChain = resolveDestinationChain(\n nextConfig,\n transformerNextMap,\n destIngest,\n );\n\n if (\n nextChain.length > 0 &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const nextResult = await runTransformerChain(\n collector,\n collector.transformers,\n nextChain,\n processedEvent!,\n destIngest,\n destRespond,\n `destination.${id}.next`,\n );\n if (nextResult.respond) destRespond = nextResult.respond;\n }\n }\n\n return event;\n }),\n );\n\n return {\n id,\n destination,\n error,\n response,\n totalDuration,\n batchedCount,\n allowedCount: allowedEvents.length,\n };\n }),\n );\n\n // Build result objects\n const done: Record<string, Destination.Ref> = {};\n const queued: Record<string, Destination.Ref> = {};\n const failed: Record<string, Destination.Ref> = {};\n\n for (const result of results) {\n if (result.skipped) continue;\n\n const destination = result.destination;\n const ref: Destination.Ref = {\n type: destination.type || 'unknown',\n data: result.response, // Capture push() return value\n };\n\n // Ensure destination status entry exists\n ensureDestStatus(collector, result.id);\n const destStatus = collector.status.destinations[result.id];\n const now = Date.now();\n\n // Refresh point-in-time buffer sizes after the destination's push pass.\n destStatus.queuePushSize = destination.queuePush?.length ?? 0;\n destStatus.dlqSize = destination.dlq?.length ?? 0;\n\n if (result.error) {\n ref.error = result.error;\n failed[result.id] = ref;\n destStatus.failed++;\n destStatus.lastAt = now;\n destStatus.duration += result.totalDuration || 0;\n collector.status.failed++;\n } else if (result.queue && result.queue.length) {\n // Events already re-queued at destination.queuePush via skippedEvents push\n queued[result.id] = ref;\n } else {\n // If every allowed event was enqueued into a batch, success counters\n // belong to the flush callback (PROD-004 plan Q9): don't increment\n // here and don't mark `done`. The flush bumps `count` and `out` when\n // pushBatch resolves. If only some events were batched, count the\n // synchronously-delivered ones.\n const batchedCount = result.batchedCount ?? 0;\n const allowedCount = result.allowedCount ?? 0;\n const syncDelivered = Math.max(0, allowedCount - batchedCount);\n if (syncDelivered > 0 || allowedCount === 0) {\n done[result.id] = ref;\n // For non-batched destinations preserve the historical semantics\n // (one bump per pushToDestinations call, regardless of allowed\n // events count, since the original code only bumped once).\n destStatus.count++;\n destStatus.lastAt = now;\n destStatus.duration += result.totalDuration || 0;\n collector.status.out++;\n }\n }\n }\n\n return createPushResult({\n event,\n ...(Object.keys(done).length && { done }),\n ...(Object.keys(queued).length && { queued }),\n ...(Object.keys(failed).length && { failed }),\n });\n}\n\n/**\n * Initializes a destination.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to initialize.\n * @param destId - The destination ID.\n * @returns Whether the destination was initialized successfully.\n */\nexport async function destinationInit<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n destId: string,\n): Promise<boolean> {\n // Check if the destination was initialized properly or try to do so\n if (destination.init && !destination.config.init) {\n // Create scoped logger for this destination: [type:id] or [unknown:id]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context: Destination.Context = {\n collector,\n logger: destLogger,\n id: destId,\n config: destination.config,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n destLogger.debug('init');\n\n const initStarted = Date.now();\n emitStep(\n collector,\n buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'init',\n eventId: '',\n now: initStarted,\n }),\n );\n\n let configResult;\n try {\n configResult = await useHooks(\n destination.init,\n 'DestinationInit',\n collector.hooks,\n collector.logger,\n )(context);\n } catch (err) {\n const initErrFinished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'error',\n eventId: '',\n now: initErrFinished,\n });\n errState.durationMs = initErrFinished - initStarted;\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n\n // Actively check for errors (when false)\n if (configResult === false) return configResult; // don't push if init is false\n\n // Update the destination config if it was returned\n destination.config = {\n ...(configResult || destination.config),\n init: true, // Remember that the destination was initialized\n };\n\n // Flush queued on() events now that destination is initialized\n if (destination.queueOn?.length) {\n const queueOn = destination.queueOn;\n destination.queueOn = [];\n\n for (const { type, data } of queueOn) {\n callDestinationOn(collector, destination, destId, type, data);\n }\n }\n\n destLogger.debug('init done');\n }\n\n return true; // Destination is ready to push\n}\n\n/**\n * Pushes an event to a single destination.\n * Handles mapping, batching, and consent checks.\n *\n * @template Destination\n * @param collector - The walkerOS collector instance.\n * @param destination - The destination to push to.\n * @param destId - The destination ID.\n * @param event - The event to push.\n * @param ingest - Mutable ingest context flowing through the pipeline.\n * @returns Whether the event was pushed successfully.\n */\nexport async function destinationPush<Destination extends Destination.Instance>(\n collector: Collector.Instance,\n destination: Destination,\n destId: string,\n event: WalkerOS.Event,\n ingest?: Ingest,\n respond?: import('@walkeros/core').RespondFn,\n): Promise<unknown> {\n const { config } = destination;\n\n const processed = await processEventMapping(event, config, collector);\n\n if (processed.ignore) return false;\n\n // Create scoped logger for this destination: [type] or [unknown]\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType);\n\n const context: Destination.PushContext = {\n collector,\n logger: destLogger,\n id: destId,\n config,\n data: processed.data,\n rule: processed.mapping,\n ingest: ingest!,\n env: {\n ...mergeEnvironments(destination.env, config.env),\n ...(respond ? { respond } : {}),\n },\n };\n\n // Mock interception — replaces the actual destination.push() call\n if (config.mock !== undefined) {\n destLogger.debug('mock', { event: processed.event.name });\n return config.mock;\n }\n\n const eventMapping = processed.mapping;\n const mappingKey = processed.mappingKey || '* *';\n\n if (\n eventMapping?.batch &&\n destination.pushBatch &&\n config.mock === undefined\n ) {\n // Initialize batch registry on destination (not on shared mapping config)\n destination.batches = destination.batches || {};\n\n // Get or create batch state for this mapping key\n if (!destination.batches[mappingKey]) {\n const batched: Destination.Batch<unknown> = {\n key: mappingKey,\n entries: [],\n events: [],\n data: [],\n };\n\n // Resolve scheduling options: mapping-level overrides destination-level.\n // Mapping rule `batch` (number form = wait; object = wait/size/age).\n // Destination config `batch` (number = wait; object = wait/size/age).\n const ruleOpts = normalizeBatchOptions(eventMapping.batch);\n const destOpts = normalizeBatchOptions(config.batch);\n const wait =\n ruleOpts.wait ??\n destOpts.wait ??\n // No wait at either layer means \"rely on size/age only\"; pick a\n // long debounce so wait is effectively never the trigger.\n DEFAULT_BATCH_AGE;\n const size = ruleOpts.size ?? destOpts.size ?? DEFAULT_BATCH_SIZE;\n const age = ruleOpts.age ?? destOpts.age ?? DEFAULT_BATCH_AGE;\n\n // Capture references the flush closure needs. ingest, respond, and\n // per-event eventMapping are read from `entries`, NOT from this scope,\n // so the closure does NOT leak the first event's context.\n const baseEnv = mergeEnvironments(destination.env, config.env);\n\n const flushBatch = async (): Promise<void> => {\n const batchState = destination.batches![mappingKey];\n const currentBatched = batchState.batched;\n if (currentBatched.entries.length === 0) return;\n\n const snapshot: Destination.Batch<unknown> = {\n key: currentBatched.key,\n entries: currentBatched.entries,\n events: currentBatched.events,\n data: currentBatched.data,\n };\n currentBatched.entries = [];\n currentBatched.events = [];\n currentBatched.data = [];\n\n const rep = snapshot.entries[0];\n const batchContext: Destination.PushBatchContext = {\n collector,\n logger: destLogger,\n id: destId,\n config,\n data: undefined,\n rule: rep.rule,\n ingest: rep.ingest!,\n env: {\n ...baseEnv,\n ...(rep.respond ? { respond: rep.respond } : {}),\n },\n };\n\n destLogger.debug('push batch', { events: snapshot.entries.length });\n\n const destIdResolved = destination.config.id || destId;\n const destStatus = ensureDestStatus(collector, destIdResolved);\n\n const flushStarted = Date.now();\n const flushState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'flush',\n eventId: '',\n now: flushStarted,\n });\n flushState.batch = { size: snapshot.entries.length, index: 0 };\n emitStep(collector, flushState);\n\n let succeeded = true;\n await tryCatchAsync(\n useHooks(\n destination.pushBatch!,\n 'DestinationPushBatch',\n collector.hooks,\n collector.logger,\n ),\n (err) => {\n succeeded = false;\n const errFinished = Date.now();\n const batchErrState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'error',\n eventId: '',\n now: errFinished,\n });\n batchErrState.durationMs = errFinished - flushStarted;\n batchErrState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n batchErrState.batch = {\n size: snapshot.entries.length,\n index: 0,\n };\n emitStep(collector, batchErrState);\n // Defect 2 fix: route the entire batch to DLQ on failure.\n const dlq = (destination.dlq = destination.dlq || []);\n const dlqBound = {\n max: destination.config.dlqMax ?? DEFAULT_DLQ_MAX,\n };\n let totalDropped = 0;\n for (const entry of snapshot.entries) {\n const r = pushBounded(dlq, [entry.event, err], dlqBound);\n totalDropped += r.dropped;\n }\n if (totalDropped > 0) {\n const droppedCount = bumpDropped(\n collector.status,\n stepId('destination', destIdResolved),\n 'dlq',\n totalDropped,\n );\n warnOverflowOnce(\n dlq,\n destLogger,\n 'destination.dlq overflow; oldest entries dropped',\n {\n buffer: 'dlq',\n destination: destIdResolved,\n cap: dlqBound.max,\n droppedCount,\n },\n );\n } else if (dlq.length < dlqBound.max) {\n resetOverflowFlag(dlq);\n }\n destStatus.failed += snapshot.entries.length;\n destStatus.dlqSize = dlq.length;\n collector.status.failed += snapshot.entries.length;\n destLogger.error('Push batch failed', {\n error: err instanceof Error ? err.message : String(err),\n entries: snapshot.entries.length,\n });\n return undefined;\n },\n )(snapshot, batchContext);\n\n destLogger.debug('push batch done');\n\n // Decrement in-flight regardless of outcome.\n destStatus.inFlightBatch = Math.max(\n 0,\n (destStatus.inFlightBatch ?? 0) - snapshot.entries.length,\n );\n\n if (succeeded) {\n destStatus.count += snapshot.entries.length;\n destStatus.lastAt = Date.now();\n collector.status.out += snapshot.entries.length;\n }\n };\n\n const scheduler = debounce(flushBatch, {\n wait,\n size,\n age,\n });\n\n destination.batches[mappingKey] = {\n batched,\n batchFn: () => {\n void scheduler();\n },\n flush: async () => {\n await scheduler.flush();\n },\n };\n }\n\n // Add per-event entry into the batch.\n const batchState = destination.batches[mappingKey];\n batchState.batched.entries.push({\n event: processed.event,\n ingest,\n respond,\n rule: eventMapping,\n data: processed.data,\n });\n batchState.batched.events.push(processed.event);\n if (isDefined(processed.data)) batchState.batched.data.push(processed.data);\n\n // In-flight bookkeeping for operational visibility.\n const destIdResolved = destination.config.id || destId;\n const destStatus = ensureDestStatus(collector, destIdResolved);\n destStatus.inFlightBatch = (destStatus.inFlightBatch ?? 0) + 1;\n\n // Trigger debounced batch (also handles size/age caps internally).\n batchState.batchFn();\n\n // Signal \"enqueued to batch, not delivered\" so the aggregation pass\n // in pushToDestinations skips the synchronous `count` increment.\n return BATCHED_RESULT;\n } else {\n destLogger.debug('push', { event: processed.event.name });\n\n // Emit a per-event observer pair around the destination.push call so\n // observers see the work this destination did for this event.\n const eventIdValue =\n typeof processed.event.id === 'string' ? processed.event.id : '';\n const pushStarted = Date.now();\n const inState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'in',\n eventId: eventIdValue,\n now: pushStarted,\n });\n if (processed.mappingKey) inState.mappingKey = processed.mappingKey;\n if (processed.event.consent) {\n inState.consent = { ...processed.event.consent };\n }\n emitStep(collector, inState);\n\n try {\n // It's time to go to the destination's side now\n const response = await useHooks(\n destination.push,\n 'DestinationPush',\n collector.hooks,\n collector.logger,\n )(processed.event, context);\n\n const pushFinished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'out',\n eventId: eventIdValue,\n now: pushFinished,\n });\n outState.durationMs = pushFinished - pushStarted;\n outState.outEvent = response;\n if (processed.mappingKey) outState.mappingKey = processed.mappingKey;\n emitStep(collector, outState);\n\n destLogger.debug('push done');\n\n return response;\n } catch (err) {\n const pushFinished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepId('destination', destId),\n stepType: 'destination',\n phase: 'error',\n eventId: eventIdValue,\n now: pushFinished,\n });\n errState.durationMs = pushFinished - pushStarted;\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n if (processed.mappingKey) errState.mappingKey = processed.mappingKey;\n emitStep(collector, errState);\n throw err;\n }\n }\n}\n\n/**\n * Creates a standardized result object for push operations.\n *\n * @param partialResult - A partial result to merge with the default result.\n * @returns The push result.\n */\nexport function createPushResult(\n partialResult?: Partial<Elb.PushResult>,\n): Elb.PushResult {\n return {\n ok: !partialResult?.failed,\n ...partialResult,\n };\n}\n\n/**\n * Register a single destination from its init definition.\n * Merges code config, user config, and chain config.\n * Used by initDestinations and activatePending.\n */\nexport function registerDestination(\n def: Destination.Init,\n): Destination.Instance {\n const { code, config = {}, env = {}, cache } = def;\n const { config: configWithBefore } = extractChainProperty(def, 'before');\n const { config: configWithChains } = extractChainProperty(\n { ...def, config: configWithBefore },\n 'next',\n );\n const mergedConfig = { ...code.config, ...config, ...configWithChains };\n // Merge definition-level cache into config for runtime access\n if (cache) mergedConfig.cache = cache;\n const mergedEnv = mergeEnvironments(code.env, env);\n return { ...code, config: mergedConfig, env: mergedEnv };\n}\n\n/**\n * Initializes a map of destinations using ONLY the unified code/config/env pattern.\n * Does NOT call destination.init() - that happens later during push with proper consent checks.\n *\n * @param destinations - The destinations to initialize.\n * @param collector - The collector instance for destination init context.\n * @returns The initialized destinations.\n */\nexport async function initDestinations(\n collector: Collector.Instance,\n destinations: Destination.InitDestinations = {},\n): Promise<Collector.Destinations> {\n const result: Collector.Destinations = {};\n\n for (const [id, def] of Object.entries(destinations)) {\n if (def.config?.require?.length) {\n collector.pending.destinations[id] = def;\n continue;\n }\n result[id] = registerDestination(def);\n }\n\n return result;\n}\n\n/**\n * Merges destination environment with config environment\n * Config env takes precedence over destination env for overrides\n */\nexport function mergeEnvironments(\n destinationEnv?: Destination.Env,\n configEnv?: Destination.Env,\n): Destination.Env {\n // If neither environment exists, return empty object\n if (!destinationEnv && !configEnv) return {};\n\n // If only one exists, return it\n if (!configEnv) return destinationEnv!;\n if (!destinationEnv) return configEnv;\n\n // Both exist - merge objects with configEnv taking precedence\n if (isObject(destinationEnv) && isObject(configEnv)) {\n return { ...destinationEnv, ...configEnv };\n }\n\n // If they're not both objects, config env overrides destination env\n return configEnv;\n}\n","import type { Collector, FlowState } from '@walkeros/core';\nimport { emitStep } from '@walkeros/core';\n\nexport interface BuildBaseStateArgs {\n stepId: string;\n stepType: FlowState['stepType'];\n phase: FlowState['phase'];\n eventId: string;\n now: number;\n}\n\n/**\n * Build a `FlowState` carrying the six always-populated fields. Callers\n * fill in additional fields (consent, batch, error, meta, inEvent,\n * outEvent, mappingKey, durationMs) as relevant for the step site.\n *\n * `flowId` defaults to a literal `'default'` until flow-id wiring is\n * threaded through the collector instance. Treat as a forward-compatible\n * placeholder, not a final shape.\n */\nexport function buildBaseState(\n collector: Collector.Instance,\n args: BuildBaseStateArgs,\n): FlowState {\n const startedAt = collector.status.startedAt;\n return {\n flowId: 'default',\n stepId: args.stepId,\n stepType: args.stepType,\n phase: args.phase,\n eventId: args.eventId,\n timestamp: new Date(args.now).toISOString(),\n elapsedMs: args.now - startedAt,\n };\n}\n\n/**\n * Convenience wrapper: build the base state and fan out to observers in\n * one call. Returns no value; callers that need to add trailing fields\n * before observers see them should call `buildBaseState` + `emitStep`\n * directly instead.\n */\nexport function emit(\n collector: Collector.Instance,\n args: BuildBaseStateArgs,\n): void {\n emitStep(collector, buildBaseState(collector, args));\n}\n","import type { Collector, On, WalkerOS, Destination } from '@walkeros/core';\nimport { isArray, FatalError } from '@walkeros/core';\nimport { Const } from './constants';\nimport { tryCatch, tryCatchAsync } from '@walkeros/core';\nimport { mergeEnvironments } from './destination';\nimport { activatePending } from './pending';\nimport { flushSourceQueueOn, isSourceStarted } from './source';\n\ntype OnCallbackKind =\n | 'destination'\n | 'generic'\n | 'source'\n | 'consent'\n | 'ready'\n | 'run'\n | 'session';\n\n/**\n * Log a thrown error from a user-supplied `on` callback.\n *\n * Category B (user code): visibility via the scoped 'on' logger only.\n * `status.failed` is reserved for pipeline failures and stays untouched\n * here so it remains a clean health signal.\n *\n * Rethrows `FatalError` to let runtime supervisors fail fast on explicit\n * abort signals. Both `tryCatch` and `tryCatchAsync` propagate throws\n * raised inside onError, so this rethrow surfaces at the caller.\n */\nfunction logOnCallbackError(\n collector: Collector.Instance,\n kind: OnCallbackKind,\n error: unknown,\n extra?: Record<string, unknown>,\n): void {\n if (error instanceof FatalError) throw error;\n collector.logger.scope('on').error('on callback failed', {\n kind,\n ...extra,\n error,\n });\n}\n\n/**\n * Build the unified On.Context passed to every subscription callback.\n * Mirrors the Mapping.Context posture: collector + scoped logger only.\n */\nfunction buildOnContext(\n collector: Collector.Instance,\n type: On.Types,\n): On.Context {\n return {\n collector,\n logger: collector.logger.scope('on').scope(String(type)),\n };\n}\n\n/**\n * Registers a callback for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to listen for.\n * @param option The callback function or an array of callback functions.\n */\nexport async function on(\n collector: Collector.Instance,\n type: On.Types,\n option: WalkerOS.SingleOrArray<On.Subscription>,\n) {\n const on = collector.on;\n const onType: Array<On.Subscription> = on[type] || [];\n const options = isArray(option) ? option : [option];\n\n options.forEach((option) => {\n onType.push(option);\n });\n\n // Update collector on state\n (on[type] as typeof onType) = onType;\n\n // Execute the on function directly\n fireCallbacks(collector, type, options);\n}\n\n/**\n * Calls a destination's on() handler with proper context.\n * Used by both onApply() for immediate calls and destinationInit() for flushing queued events.\n */\nexport function callDestinationOn(\n collector: Collector.Instance,\n destination: Destination.Instance,\n destId: string,\n type: On.Types,\n data: unknown,\n) {\n if (!destination.on) return;\n\n const destType = destination.type || 'unknown';\n const destLogger = collector.logger.scope(destType).scope('on').scope(type);\n\n const context: Destination.Context = {\n collector,\n logger: destLogger,\n id: destId,\n config: destination.config,\n data: data as Destination.Data,\n env: mergeEnvironments(destination.env, destination.config.env),\n };\n\n tryCatch(destination.on, (err) =>\n logOnCallbackError(collector, 'destination', err, { destId, type }),\n )(type, context);\n}\n\n/**\n * Fire a set of registered `on` callbacks against current collector state.\n *\n * Used by both `on()` (when registering a new callback, to fire it against\n * current state) and `onApply()` (when dispatching a state-change command to\n * every registered callback of that type). Separating this from `onApply`\n * ensures `on()` does NOT trigger `onApply`'s source/destination broadcast,\n * which would cause infinite recursion if a source's `on` handler registers\n * another callback of the same type.\n */\nfunction fireCallbacks(\n collector: Collector.Instance,\n type: On.Types,\n options: Array<On.Subscription>,\n config?: unknown,\n): void {\n // Calculate context data once for all sources and destinations\n let contextData: unknown;\n\n switch (type) {\n case Const.Commands.Consent:\n contextData = config || collector.consent;\n break;\n case Const.Commands.Session:\n contextData = collector.session;\n break;\n case Const.Commands.User:\n contextData = config || collector.user;\n break;\n case Const.Commands.Custom:\n contextData = config || collector.custom;\n break;\n case Const.Commands.Globals:\n contextData = config || collector.globals;\n break;\n case Const.Commands.Config:\n contextData = config || collector.config;\n break;\n case Const.Commands.Ready:\n case Const.Commands.Run:\n default:\n contextData = undefined;\n break;\n }\n\n if (!options.length) return;\n\n switch (type) {\n case Const.Commands.Consent:\n onConsent(\n collector,\n options as Array<On.ConsentRule>,\n config as WalkerOS.Consent,\n );\n break;\n case Const.Commands.Ready:\n onReady(collector, options as Array<On.ReadyFn>);\n break;\n case Const.Commands.Run:\n onRun(collector, options as Array<On.RunFn>);\n break;\n case Const.Commands.Session:\n onSession(collector, options as Array<On.SessionFn>);\n break;\n default: {\n // Generic handler for user, custom, globals, config, and arbitrary events\n const ctx = buildOnContext(collector, type);\n options.forEach((func) => {\n if (typeof func === 'function') {\n tryCatch(func as On.GenericFn, (err) =>\n logOnCallbackError(collector, 'generic', err, { type }),\n )(contextData, ctx);\n }\n });\n break;\n }\n }\n}\n\n/**\n * Applies all registered callbacks for a specific event type.\n *\n * @param collector The walkerOS collector instance.\n * @param type The type of the event to apply the callbacks for.\n * @param options The options for the callbacks.\n * @param config The consent configuration.\n */\nexport async function onApply(\n collector: Collector.Instance,\n type: On.Types,\n options?: Array<On.Subscription>,\n config?: unknown,\n): Promise<boolean> {\n // Use the optionally provided options\n let onConfig = options || [];\n\n if (!options) {\n // Get the collector on events\n onConfig = collector.on[type] || [];\n }\n\n // Calculate context data once for source/destination broadcast\n let contextData: unknown;\n\n switch (type) {\n case Const.Commands.Consent:\n contextData = config || collector.consent;\n break;\n case Const.Commands.Session:\n contextData = collector.session;\n break;\n case Const.Commands.User:\n contextData = config || collector.user;\n break;\n case Const.Commands.Custom:\n contextData = config || collector.custom;\n break;\n case Const.Commands.Globals:\n contextData = config || collector.globals;\n break;\n case Const.Commands.Config:\n contextData = config || collector.config;\n break;\n case Const.Commands.Ready:\n case Const.Commands.Run:\n default:\n contextData = undefined;\n break;\n }\n\n let vetoed = false;\n // Per-source require decrement + gated on() delivery.\n // Sources are not \"started\" until config.init === true AND config.require is empty.\n // Unstarted sources have their on() events queued in instance.queueOn\n // and replayed once they start.\n for (const [sourceId, source] of Object.entries(collector.sources)) {\n if (source.config.require?.length) {\n const idx = source.config.require.indexOf(type);\n if (idx !== -1) source.config.require.splice(idx, 1);\n }\n\n if (!source.on) continue;\n\n if (isSourceStarted(source)) {\n const result = await tryCatchAsync(source.on, (err) =>\n logOnCallbackError(collector, 'source', err, { sourceId, type }),\n )(type, contextData);\n if (result === false) vetoed = true;\n } else {\n source.queueOn = source.queueOn || [];\n source.queueOn.push({ type, data: contextData });\n }\n }\n\n Object.entries(collector.destinations).forEach(([destId, destination]) => {\n if (destination.on) {\n // Queue if destination not yet initialized\n if (!destination.config.init) {\n destination.queueOn = destination.queueOn || [];\n destination.queueOn.push({ type, data: contextData });\n return;\n }\n callDestinationOn(collector, destination, destId, type, contextData);\n }\n });\n\n // Sources whose require was just emptied AND init has run: flush their\n // queueOn now (the require-completing event was queued in the gated\n // branch above, so flushing here delivers it without losing ordering).\n for (const [sourceId, source] of Object.entries(collector.sources)) {\n if (isSourceStarted(source) && source.queueOn?.length) {\n await flushSourceQueueOn(collector, source, sourceId);\n }\n }\n\n // Activate pending destinations whose require conditions are met.\n // (Pending sources are gone — their require is tracked in source.config.require\n // and gated via queueOn above.)\n if (Object.keys(collector.pending.destinations).length > 0) {\n await activatePending(collector, type);\n }\n\n fireCallbacks(collector, type, onConfig, config);\n\n return !vetoed;\n}\n\nfunction onConsent(\n collector: Collector.Instance,\n onConfig: Array<On.ConsentRule>,\n currentConsent?: WalkerOS.Consent,\n): void {\n const consentState = currentConsent || collector.consent;\n const ctx = buildOnContext(collector, Const.Commands.Consent);\n\n onConfig.forEach((rule) => {\n // Execute every handler whose consent key is present in the current state.\n Object.keys(consentState)\n .filter((key) => key in rule)\n .forEach((key) => {\n tryCatch(rule[key], (err) =>\n logOnCallbackError(collector, 'consent', err, { key }),\n )(consentState, ctx);\n });\n });\n}\n\nfunction onReady(\n collector: Collector.Instance,\n onConfig: Array<On.ReadyFn>,\n): void {\n if (!collector.allowed) return;\n const ctx = buildOnContext(collector, Const.Commands.Ready);\n onConfig.forEach((func) => {\n tryCatch(func, (err) => logOnCallbackError(collector, 'ready', err))(\n undefined,\n ctx,\n );\n });\n}\n\nfunction onRun(collector: Collector.Instance, onConfig: Array<On.RunFn>): void {\n if (!collector.allowed) return;\n const ctx = buildOnContext(collector, Const.Commands.Run);\n onConfig.forEach((func) => {\n tryCatch(func, (err) => logOnCallbackError(collector, 'run', err))(\n undefined,\n ctx,\n );\n });\n}\n\nfunction onSession(\n collector: Collector.Instance,\n onConfig: Array<On.SessionFn>,\n): void {\n if (!collector.session) return;\n const ctx = buildOnContext(collector, Const.Commands.Session);\n onConfig.forEach((func) => {\n tryCatch(func, (err) => logOnCallbackError(collector, 'session', err))(\n collector.session,\n ctx,\n );\n });\n}\n","import type { Collector } from '@walkeros/core';\nimport { registerDestination } from './destination';\n\n/**\n * Activate pending destinations whose require conditions are met.\n * Called from onApply after each non-vetoed event.\n *\n * Mutates require arrays in place — removes the fulfilled event type.\n * When require is empty, registers and moves to active map.\n *\n * Re-entrancy safe: delete-before-init ensures nested calls see clean state.\n *\n * Sources are no longer pending — their lifecycle is tracked per-instance\n * via `Source.Config.init` and `Source.Instance.queueOn`. See on.ts.\n */\nexport async function activatePending(\n collector: Collector.Instance,\n type: string,\n): Promise<void> {\n for (const [id, def] of Object.entries(collector.pending.destinations)) {\n if (!collector.pending.destinations[id] || collector.destinations[id])\n continue;\n\n const require = def.config?.require;\n if (!require) continue;\n\n const idx = require.indexOf(type);\n if (idx === -1) continue;\n require.splice(idx, 1);\n\n if (require.length > 0) continue;\n\n delete collector.pending.destinations[id];\n const instance = registerDestination(def);\n if (instance.config.queue !== false) {\n instance.queuePush = [...collector.queue];\n }\n collector.destinations[id] = instance;\n }\n}\n","import type {\n Cache,\n Collector,\n Elb,\n Ingest,\n Source,\n WalkerOS,\n} from '@walkeros/core';\nimport type { RespondFn, RespondOptions } from '@walkeros/core';\nimport {\n createIngest,\n FatalError,\n getMappingValue,\n tryCatchAsync,\n getNextSteps,\n compileCache,\n checkCache,\n storeCache,\n applyUpdate,\n buildCacheContext,\n} from '@walkeros/core';\nimport {\n walkChain,\n extractTransformerNextMap,\n runTransformerChain,\n cloneIngest,\n} from './transformer';\n\n/**\n * A Route is \"static\" when it's a transformer-ID string or an array of\n * transformer-ID strings. Static routes can be resolved once at init and\n * walked synchronously; conditional shapes (RouteConfig, mixed arrays)\n * depend on per-event context and resolve via getNextSteps at dispatch.\n */\nfunction isStaticRoute(\n route: import('@walkeros/core').Transformer.Route | undefined,\n): route is string | string[] {\n if (typeof route === 'string') return true;\n if (\n Array.isArray(route) &&\n route.every((entry) => typeof entry === 'string')\n ) {\n return true;\n }\n return false;\n}\nimport { getCacheStore } from './cache';\n\n/**\n * Flush a source's queueOn buffer. Called when the source becomes \"started\"\n * (config.init === true AND config.require is empty/absent). Idempotent:\n * the buffer is cleared before iteration, so re-entry from within an `on`\n * handler does not re-fire the same items.\n *\n * A throw inside `source.on` is treated as a pipeline failure: log via the\n * scoped 'source' logger and increment `status.failed`. The flush itself\n * is walkerOS-orchestrated startup; the throw represents the source's\n * inability to consume a buffered state-change event.\n */\nexport async function flushSourceQueueOn(\n collector: Collector.Instance,\n source: Source.Instance,\n sourceId?: string,\n): Promise<void> {\n if (!source.on || !source.queueOn?.length) return;\n const queue = source.queueOn;\n source.queueOn = [];\n const id = sourceId || source.config?.id || 'unknown';\n for (const { type, data } of queue) {\n await tryCatchAsync(source.on, (err: unknown): undefined => {\n if (err instanceof FatalError) throw err;\n collector.status.failed++;\n collector.logger.scope('source').error('source on flush failed', {\n sourceId: id,\n type,\n error: err,\n });\n return undefined;\n })(type, data);\n }\n}\n\n/**\n * A source is \"started\" — eligible to receive on() events directly — when\n * its init has run and any require gate is satisfied.\n */\nexport function isSourceStarted(source: Source.Instance): boolean {\n return Boolean(source.config.init) && !source.config.require?.length;\n}\n\n/**\n * Initialize a single source. Extracted from the initSources loop body\n * so it can be reused by the pending-source activator.\n */\nexport async function initSource(\n collector: Collector.Instance,\n sourceId: string,\n sourceDefinition: Source.InitSource,\n): Promise<Source.Instance | undefined> {\n const {\n code,\n config = {},\n env = {},\n primary,\n next,\n before,\n cache,\n } = sourceDefinition;\n\n // Compile source cache config (if configured).\n // Source caches operate on events (request-scoped HIT/MISS keyed by event\n // fields), so the rule shape is always EventCacheRule, not StoreCacheRule.\n const sourceCacheConfig = cache as\n | Cache.Cache<Cache.EventCacheRule>\n | undefined;\n const compiledSourceCache = sourceCacheConfig\n ? compileCache({\n ...sourceCacheConfig,\n stop: sourceCacheConfig.stop ?? true,\n })\n : undefined;\n\n // Resolve transformer chain for this source.\n // Static (string / string[]) chains pre-walk at init (optimization).\n // Conditional shapes (case / gate) require per-request context — see wrappedPush.\n const staticPreChain = isStaticRoute(next)\n ? walkChain(next, extractTransformerNextMap(collector.transformers))\n : undefined;\n\n // Resolve before chain for this source (consent-exempt, pre-source preprocessing).\n const staticBeforeChain = isStaticRoute(before)\n ? walkChain(before, extractTransformerNextMap(collector.transformers))\n : undefined;\n\n // Terminal push: where the source pipeline ends. Defaults to\n // `collector.push`. Tests (and rare advanced consumers) may override by\n // passing `push` in the source's `env`; in that case the override\n // replaces the collector and receives the raw event with no pipeline\n // options. Per-scope ingest/respond is invisible to overriders by\n // design: overriders are responsible for their own pipeline shape.\n const userTerminalPush = (env as { push?: Collector.PushFn }).push;\n const terminalPush: Collector.PushFn = userTerminalPush ?? collector.push;\n const hasUserTerminalPush = Boolean(userTerminalPush);\n\n /**\n * Execute the source pipeline for a single push call. Operates ONLY on\n * the per-call `scope` parameter — never reads source-factory closure\n * variables for ingest/respond. The scope is the unit of cross-request\n * isolation.\n *\n * The function may mutate `scope.respond` (cache MISS wraps it to\n * intercept the cached value before forwarding). That mutation is\n * scope-local: a concurrent call with its own scope is unaffected.\n */\n const executePush = async (\n rawEvent: WalkerOS.DeepPartialEvent,\n options: Collector.PushOptions,\n scope: { ingest: Ingest; respond: RespondFn | undefined },\n ): Promise<Elb.PushResult> => {\n let pendingRespond: Promise<void> | undefined;\n\n // Resolve before chain (static or conditional).\n // Single-id results walk static `.next` links; multi-id results are\n // explicit chains (fan-out from `many` is handled by the engine).\n const beforeChain =\n staticBeforeChain ??\n (before !== undefined\n ? (() => {\n const ids = getNextSteps(before, buildCacheContext(scope.ingest));\n if (ids.length === 0) return [];\n const start = ids.length === 1 ? ids[0] : ids;\n return walkChain(\n start,\n extractTransformerNextMap(collector.transformers),\n );\n })()\n : []);\n\n // The before chain may fan out (return an array of events). The cache\n // check and destination push must run once per event so fan-out is\n // preserved end-to-end. Cache logic is request-scoped (keyed by the\n // scope's ingest), so it lives outside the loop. The actual pipeline\n // (preChain + collector.push) runs inside the loop, once per event.\n let events: WalkerOS.DeepPartialEvent[] = [rawEvent];\n\n // Run source.before chain (consent-exempt, pre-source preprocessing)\n if (\n beforeChain.length > 0 &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const beforeResult = await runTransformerChain(\n collector,\n collector.transformers,\n beforeChain,\n rawEvent,\n scope.ingest,\n scope.respond,\n `source.${sourceId}.before`,\n );\n if (beforeResult.event === null) {\n return { ok: true } as Elb.PushResult;\n }\n // Pipeline-halt signal from a `cache.stop: true` HIT inside the\n // source.before chain. Do NOT invoke collector.push — drop the event\n // before it enters the collector pipeline.\n if (beforeResult.stopped) {\n if (beforeResult.respond) scope.respond = beforeResult.respond;\n return { ok: true } as Elb.PushResult;\n }\n if (beforeResult.respond) scope.respond = beforeResult.respond;\n events = Array.isArray(beforeResult.event)\n ? beforeResult.event\n : [beforeResult.event];\n }\n\n // Source cache check (full=true by default for sources)\n if (compiledSourceCache) {\n const cacheStore = getCacheStore(compiledSourceCache, collector);\n if (cacheStore) {\n const cacheContext = buildCacheContext(scope.ingest);\n const cacheResult = await checkCache(\n compiledSourceCache,\n cacheStore,\n cacheContext,\n // no per-step prefix — cache keys honor user-provided namespace only\n );\n\n if (cacheResult) {\n if (cacheResult.status === 'HIT' && cacheResult.value !== undefined) {\n if (compiledSourceCache.stop) {\n // stop=true (default): respond with cached value, skip pipeline\n let respondValue: unknown = cacheResult.value;\n if (cacheResult.rule.update) {\n respondValue = await applyUpdate(\n respondValue,\n cacheResult.rule.update as Record<string, unknown>,\n { ...cacheContext, cache: { status: 'HIT' } },\n collector,\n );\n }\n scope.respond?.(respondValue as Record<string, unknown>);\n return { ok: true } as Elb.PushResult;\n }\n // stop=false: cached value unused — HIT signals \"seen before\", pipeline continues\n }\n\n if (\n cacheResult.status === 'MISS' &&\n compiledSourceCache.stop &&\n scope.respond\n ) {\n // stop=true MISS: wrap respond to intercept and cache the value.\n // Store original in cache, then apply update rules with MISS\n // status before responding (mirrors HIT path which applies\n // with HIT status).\n //\n // When `update` is configured the update step is async, so\n // the wrapper captures its promise in `pendingRespond`.\n // `executePush` awaits that promise before returning, so any\n // source fallback that runs after `await env.push(...)` (e.g.\n // the express source's transparent-GIF default) sees\n // `createRespond`'s first-call-wins flag already set and\n // correctly no-ops. Without this, the fallback would win\n // the race and the real response would be lost.\n const unwrappedRespond = scope.respond;\n const missUpdate = cacheResult.rule.update;\n const missContext = { ...cacheContext, cache: { status: 'MISS' } };\n const missKey = cacheResult.key;\n const missTtl = cacheResult.rule.ttl;\n\n const missRespond: RespondFn = (respondOptions) => {\n storeCache(cacheStore, missKey, respondOptions, missTtl);\n\n if (!missUpdate) {\n unwrappedRespond(respondOptions);\n return;\n }\n\n pendingRespond = (async () => {\n const updated = await applyUpdate(\n respondOptions,\n missUpdate as Record<string, unknown>,\n missContext,\n collector,\n );\n unwrappedRespond(updated as RespondOptions);\n })();\n };\n\n scope.respond = missRespond;\n }\n\n // stop=false MISS: store sentinel so subsequent requests get a HIT\n if (cacheResult.status === 'MISS' && !compiledSourceCache.stop) {\n storeCache(cacheStore, cacheResult.key, true, cacheResult.rule.ttl);\n }\n }\n }\n }\n\n // Resolve chain: static (pre-computed) or conditional (per-event).\n // Three dispatch shapes from `getNextSteps`:\n // - [] → no route matched; passthrough to collector with no\n // pre-chain.\n // - ['x'] → walk static `.next` links from x and run as a single\n // sequential subchain inside `collector.push`.\n // - ['a','b',…] → `many` fan-out. Each id is an INDEPENDENT terminal\n // subchain dispatched via its own `collector.push` call\n // with a per-branch cloned ingest and `respond` cleared\n // (no-respond-across-many doctrine). Error isolation\n // per branch via tryCatchAsync.\n //\n // Note: a plain `next: ['a','b','c']` is `isStaticRoute` → pre-walked\n // by `staticPreChain` as the legacy explicit sequential chain. Only\n // `{ many: [...] }` reaches the multi-id branch here.\n type Dispatch =\n | { kind: 'single'; preChain: string[] }\n | { kind: 'many'; branches: string[][] };\n\n const dispatch: Dispatch = staticPreChain\n ? { kind: 'single', preChain: staticPreChain }\n : next !== undefined\n ? (() => {\n const ids = getNextSteps(next, buildCacheContext(scope.ingest));\n if (ids.length === 0)\n return { kind: 'single', preChain: [] } as Dispatch;\n if (ids.length === 1)\n return {\n kind: 'single',\n preChain: walkChain(\n ids[0],\n extractTransformerNextMap(collector.transformers),\n ),\n } as Dispatch;\n return {\n kind: 'many',\n branches: ids.map((id) =>\n walkChain(\n id,\n extractTransformerNextMap(collector.transformers),\n ),\n ),\n } as Dispatch;\n })()\n : ({ kind: 'single', preChain: [] } as Dispatch);\n\n // Push each event independently through the post-before pipeline.\n // For non-fan-out (single event) this is a one-iteration loop and\n // behaves exactly like the previous implementation.\n let pushResult: Elb.PushResult = { ok: true } as Elb.PushResult;\n for (const event of events) {\n if (dispatch.kind === 'many') {\n // `many` fan-out: each branch is an independent terminal flow.\n // Per-branch ingest clone, no respond propagation, error isolation\n // via tryCatchAsync. Branch results are awaited and discarded;\n // scope.respond is NOT updated from any branch.\n await Promise.all(\n dispatch.branches.map((branchChain, idx) =>\n tryCatchAsync(\n async () =>\n hasUserTerminalPush\n ? terminalPush(event)\n : terminalPush(event, {\n ...options,\n id: sourceId,\n ingest: cloneIngest(scope.ingest, `${sourceId}.${idx}`),\n respond: undefined,\n mapping: config,\n preChain: branchChain,\n }),\n (err) => {\n collector.logger\n .scope('source:many')\n .error(`many branch ${idx} failed`, { error: err });\n return { ok: true } as Elb.PushResult;\n },\n )(),\n ),\n );\n // `many` is fan-out, not enrichment — surface a generic OK.\n pushResult = { ok: true } as Elb.PushResult;\n } else if (hasUserTerminalPush) {\n // User override: bypass the pipeline, deliver raw events. This\n // preserves the `env.push: mockPush` test spy pattern.\n pushResult = await terminalPush(event);\n } else {\n pushResult = await terminalPush(event, {\n ...options,\n id: sourceId,\n ingest: scope.ingest,\n respond: scope.respond,\n mapping: config,\n preChain: dispatch.preChain,\n });\n }\n }\n\n // Wait for any deferred MISS update work to land on the source's\n // respond sender before returning control to the source. This\n // ensures source-level fallbacks (e.g. transparent GIFs) run after\n // the real response has been committed via first-call-wins.\n if (pendingRespond) await pendingRespond;\n\n return pushResult;\n };\n\n /**\n * Build a fresh per-scope `Ingest` from raw scope input by applying\n * `config.ingest` mapping if present. Always produces a typed Ingest\n * with valid `_meta`. Pure: returns a new object, never reads or\n * writes source-factory state.\n */\n const extractIngest = async (rawScope: unknown): Promise<Ingest> => {\n const fresh = createIngest(sourceId);\n if (!config.ingest || rawScope === undefined) return fresh;\n const extracted = await getMappingValue(rawScope, config.ingest, {\n collector,\n });\n return {\n ...fresh,\n ...(extracted as Record<string, unknown>),\n _meta: fresh._meta, // protect _meta from being overwritten\n };\n };\n\n // Factory-default push: each call gets a fresh Ingest and no respond.\n // Sources with a single logical scope (browser, dataLayer) call this\n // directly via `env.push`. Server sources handling concurrent requests\n // call `context.withScope(...)` instead, which threads a per-scope\n // ingest/respond into the same pipeline.\n const wrappedPush: Collector.PushFn = async (\n rawEvent: WalkerOS.DeepPartialEvent,\n options: Collector.PushOptions = {},\n ) => {\n const scope = {\n ingest: createIngest(sourceId),\n respond: undefined as RespondFn | undefined,\n };\n return executePush(rawEvent, options, scope);\n };\n\n // Create initial logger scoped to sourceId (type will be added after init)\n const initialLogger = collector.logger.scope('source').scope(sourceId);\n\n // Build cleanEnv. User-supplied env can override every field; we\n // immediately overwrite `push` with the source-pipeline `wrappedPush`.\n // Any user-supplied `env.push` was captured above as `terminalPush`\n // (the pipeline's terminus, not the source's outward-facing push).\n const cleanEnv: Source.Env = {\n command: collector.command,\n sources: collector.sources,\n elb: collector.sources.elb.push,\n logger: initialLogger,\n ...env,\n push: wrappedPush,\n };\n\n /**\n * Bind ingest and respond to a single scope of work. Each invocation\n * builds a fresh `Ingest`, captures the given `respond`, and runs the\n * caller's `body` with a per-scope env whose `push` carries both. The\n * scope is the unit of cross-call isolation — concurrent withScope\n * invocations never share ingest or respond.\n */\n const withScope: Source.Context['withScope'] = async (\n rawScope,\n respond,\n body,\n ) => {\n const scope: { ingest: Ingest; respond: RespondFn | undefined } = {\n ingest: await extractIngest(rawScope),\n respond,\n };\n const scopePush: Collector.PushFn = (rawEvent, options = {}) =>\n executePush(rawEvent, options, scope);\n const scopeEnv: Source.ScopeEnv = {\n ...cleanEnv,\n push: scopePush,\n ingest: scope.ingest,\n respond: scope.respond,\n };\n return body(scopeEnv);\n };\n\n const sourceContext: Source.Context = {\n collector,\n logger: initialLogger,\n id: sourceId,\n config,\n env: cleanEnv,\n withScope,\n };\n\n const sourceInstance = await tryCatchAsync(\n code,\n (err: unknown): undefined => {\n if (err instanceof FatalError) throw err;\n collector.status.failed++;\n collector.logger.scope('source').error('source factory failed', {\n sourceId,\n error: err,\n });\n return undefined;\n },\n )(sourceContext);\n if (!sourceInstance) return undefined;\n\n const sourceType = sourceInstance.type || 'unknown';\n const sourceLogger = collector.logger.scope(sourceType).scope(sourceId);\n cleanEnv.logger = sourceLogger;\n\n if (primary) {\n sourceInstance.config = { ...sourceInstance.config, primary };\n }\n\n return sourceInstance;\n}\n\n/**\n * Initialize sources. Sources with `require` are deferred to collector.pending.\n */\nexport async function initSources(\n collector: Collector.Instance,\n sources: Source.InitSources = {},\n): Promise<Collector.Sources> {\n const result: Collector.Sources = {};\n\n // Pass 1: register every source via its factory.\n for (const [sourceId, sourceDefinition] of Object.entries(sources)) {\n const sourceInstance = await initSource(\n collector,\n sourceId,\n sourceDefinition,\n );\n if (!sourceInstance) continue;\n // Propagate orchestration fields from the user's source definition into\n // the registered instance config. The factory does not know about\n // `require` — it's an InitSource-level concern that the collector owns.\n // Clone the array so per-source decrement (in onApply) doesn't mutate\n // the caller's config.\n const userRequire = sourceDefinition.config?.require;\n sourceInstance.config = {\n ...sourceInstance.config,\n init: false,\n ...(userRequire ? { require: [...userRequire] } : {}),\n };\n result[sourceId] = sourceInstance;\n }\n\n // Merge into collector.sources BEFORE pass 2 so that any onApply\n // broadcast triggered during init can find every source.\n Object.assign(collector.sources, result);\n\n // Pass 2: init each source. Side effects allowed here.\n for (const sourceId of Object.keys(result)) {\n const instance = collector.sources[sourceId];\n let initFailed = false;\n if (instance.init) {\n await tryCatchAsync(instance.init.bind(instance), (err: unknown) => {\n if (err instanceof FatalError) throw err;\n initFailed = true;\n collector.status.failed++;\n collector.logger.scope('source').error('source init failed', {\n sourceId,\n error: err,\n });\n })();\n }\n // Control-flow fix: a throw inside `init()` previously left the source\n // marked `config.init = true` despite never having completed setup.\n // Operators reading `source.config.init` would see a healthy source\n // that was actually broken. Skip the rest of the loop on failure so\n // the source stays in `config.init = false` and is visibly stuck.\n if (initFailed) continue;\n instance.config.init = true;\n if (isSourceStarted(instance)) {\n await flushSourceQueueOn(collector, instance, sourceId);\n }\n }\n\n return result;\n}\n","/**\n * @module transformer\n *\n * Transformer Chain Utilities\n * ==========================\n *\n * This module provides the unified implementation for transformer chains in walkerOS.\n * Chains are used at two points in the data flow:\n *\n * 1. Pre-collector chains (source.next):\n * Source → [Transformer Chain] → Collector\n * Events are processed before the collector sees them.\n *\n * 2. Post-collector chains (destination.before):\n * Collector → [Transformer Chain] → Destination\n * Events are processed before reaching specific destinations.\n *\n * Key Functions:\n * - extractTransformerNextMap(): Extracts next links from transformer instances\n * - extractChainProperty(): Unified extraction of chain properties from definitions\n * - walkChain(): Resolves chain IDs from starting point\n * - runTransformerChain(): Executes a chain of transformers on an event\n *\n * Chain Resolution:\n * - String start: Walk transformer.next links until chain ends\n * - Array start: Use array directly (explicit chain, ignores transformer.next)\n *\n * Chain Termination:\n * - Transformer returns false → chain stops, event is dropped\n * - Transformer throws error → chain stops, event is dropped\n * - Transformer returns void → continue with unchanged event\n * - Transformer returns event → continue with modified event\n */\nimport type {\n Cache,\n Collector,\n Transformer,\n WalkerOS,\n Ingest,\n} from '@walkeros/core';\nimport {\n createIngest,\n emitStep,\n FatalError,\n isObject,\n stepId,\n tryCatchAsync,\n useHooks,\n getNextSteps,\n compileCache,\n checkCache,\n storeCache,\n buildCacheContext,\n validateStepEntry,\n processEventMapping,\n} from '@walkeros/core';\nimport { buildBaseState } from './observerEmit';\nimport { getCacheStore } from './cache';\n\n/**\n * Extracts transformer next configuration for chain walking.\n * Maps transformer instances to their config.next values.\n *\n * This is the single source of truth for extracting chain links.\n * Used by both source.ts (pre-collector chains) and destination.ts (post-collector chains).\n *\n * @param transformers - Map of transformer instances\n * @returns Map of transformer IDs to their next configuration\n */\nexport function extractTransformerNextMap(\n transformers: Transformer.Transformers,\n): Record<string, { next?: string | string[] }> {\n const result: Record<string, { next?: string | string[] }> = {};\n for (const [id, transformer] of Object.entries(transformers)) {\n const next = transformer.config?.next;\n // Static shapes are recorded for synchronous chain walking.\n // Conditional shapes (RouteConfig, mixed arrays) resolve per-event via\n // getNextSteps at dispatch time; they get an empty entry here so the\n // chain walker stops at this hop rather than following a stale link.\n if (typeof next === 'string') {\n result[id] = { next };\n } else if (\n Array.isArray(next) &&\n next.every((entry) => typeof entry === 'string')\n ) {\n result[id] = { next: next as string[] };\n } else {\n result[id] = {};\n }\n }\n return result;\n}\n\n/**\n * Extracts chain property from definition and merges into config.\n * Provides unified handling for source.next, destination.before, and transformer.next.\n *\n * @param definition - Component definition with optional chain property\n * @param propertyName - Name of chain property ('next' or 'before')\n * @returns Object with merged config and extracted chain value\n */\nexport function extractChainProperty<\n T extends { config?: Record<string, unknown>; [key: string]: unknown },\n>(\n definition: T,\n propertyName: 'next' | 'before',\n): {\n config: Record<string, unknown>;\n chainValue: string | string[] | undefined;\n} {\n const config = (definition.config || {}) as Record<string, unknown>;\n const chainValue = definition[propertyName] as string | string[] | undefined;\n\n if (chainValue !== undefined) {\n return {\n config: { ...config, [propertyName]: chainValue },\n chainValue,\n };\n }\n\n return { config, chainValue: undefined };\n}\n\n/**\n * Walks a transformer chain starting from a given transformer ID.\n * Returns ordered array of transformer IDs in the chain.\n *\n * Used for on-demand chain resolution:\n * - Called from destination.ts with destination.config.before\n * - Called from source.ts with source.config.next\n *\n * @param startId - First transformer in chain, or explicit array of transformer IDs\n * @param transformers - Available transformer configs with optional `next` field\n * @returns Ordered array of transformer IDs to execute\n *\n * @example\n * // Single transformer\n * walkChain('redact', { redact: {} }) // ['redact']\n *\n * @example\n * // Chain via next\n * walkChain('a', { a: { next: 'b' }, b: { next: 'c' }, c: {} }) // ['a', 'b', 'c']\n *\n * @example\n * // Explicit array\n * walkChain(['x', 'y'], {}) // ['x', 'y']\n */\nexport function walkChain(\n startId: string | string[] | undefined,\n transformers: Record<string, { next?: string | string[] }> = {},\n): string[] {\n if (!startId) return [];\n\n // If array provided, use it directly (explicit chain)\n if (Array.isArray(startId)) {\n return startId;\n }\n\n // Walk the chain via transformer.next links\n const chain: string[] = [];\n const visited = new Set<string>();\n let current: string | undefined = startId;\n\n while (current && transformers[current]) {\n if (visited.has(current)) {\n // Circular reference detected - stop walking\n break;\n }\n visited.add(current);\n chain.push(current);\n\n const next: string | string[] | undefined = transformers[current].next;\n\n // If transformer has array next, append it and stop walking\n if (Array.isArray(next)) {\n chain.push(...next);\n break;\n }\n\n current = next;\n }\n\n return chain;\n}\n\n/**\n * Initializes transformer instances from configuration.\n * Does NOT call transformer.init() - that happens lazily before first push.\n *\n * @param collector - The collector instance\n * @param initTransformers - Transformer initialization configurations\n * @returns Initialized transformer instances\n */\nexport async function initTransformers(\n collector: Collector.Instance,\n initTransformers: Transformer.InitTransformers = {},\n): Promise<Transformer.Transformers> {\n const result: Transformer.Transformers = {};\n\n for (const [transformerId, transformerDef] of Object.entries(\n initTransformers,\n )) {\n const { code, env = {} } = transformerDef;\n\n // Validate the entry via the shared predicate. A code-less entry must\n // declare at least one operative field (package, before, next, cache,\n // mapping). Unknown keys and code+package conflicts are also rejected.\n const validation = validateStepEntry(\n transformerDef as Record<string, unknown>,\n 'Transformer',\n );\n if (!validation.ok) {\n collector.logger.warn(\n `Transformer ${transformerId} invalid (${validation.code}): ${validation.reason}. Skipping.`,\n );\n continue;\n }\n\n // Use unified chain property extractor for both before and next\n const { config: configWithBefore } = extractChainProperty(\n transformerDef,\n 'before',\n );\n const { config: configWithChain } = extractChainProperty(\n { ...transformerDef, config: configWithBefore },\n 'next',\n );\n\n // Merge definition-level env into config so it's available during push.\n // transformerPush reads transformer.config.env to build the push context.\n const configWithEnv =\n Object.keys(env).length > 0\n ? { ...configWithChain, env: env as Transformer.Env }\n : configWithChain;\n\n // Merge definition-level cache into config for runtime access\n const { cache } = transformerDef;\n const configWithCache = cache ? { ...configWithEnv, cache } : configWithEnv;\n\n // Build transformer context for init\n const transformerLogger = collector.logger\n .scope('transformer')\n .scope(transformerId);\n\n const context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n ingest: createIngest(transformerId),\n config: configWithCache,\n env: env as Transformer.Env,\n };\n\n // Synthesize a passthrough instance when `code` is absent.\n // This makes the entry a \"pass\" — a named, code-less hop. Two flavors:\n // 1. mapping-aware: when `mapping` is declared, the synthesized push\n // runs `processEventMapping` and forwards the transformed event\n // (or drops it when a rule has `ignore: true`).\n // 2. plain passthrough: when only `before` / `next` / `cache` are\n // declared, the push returns the event unchanged.\n const codeFn =\n code ??\n ((ctx: Transformer.Context) => {\n const stepMapping = transformerDef.mapping;\n if (stepMapping) {\n // Warn once per init if vendor-payload fields are present at the\n // transformer position. Only event-mutating fields apply here.\n // Note: `MappingConfig` has no top-level `silent` field — that\n // lives on `Rule` only, so the config-level check is `data` only.\n const meaninglessFields: string[] = [];\n if (stepMapping.data !== undefined) meaninglessFields.push('data');\n // Walk rules for per-rule data/silent\n if (stepMapping.mapping) {\n for (const [entity, actions] of Object.entries(\n stepMapping.mapping,\n )) {\n if (typeof actions !== 'object' || actions === null) continue;\n for (const [action, rule] of Object.entries(\n actions as Record<string, unknown>,\n )) {\n if (typeof rule !== 'object' || rule === null) continue;\n const r = rule as Record<string, unknown>;\n if (r.data !== undefined)\n meaninglessFields.push(`mapping[${entity}][${action}].data`);\n if (r.silent !== undefined)\n meaninglessFields.push(\n `mapping[${entity}][${action}].silent`,\n );\n }\n }\n }\n if (meaninglessFields.length > 0) {\n ctx.collector.logger.warn(\n `Transformer ${transformerId}: \\`${meaninglessFields.join(', ')}\\` ignored at transformer position (only event-mutating fields apply).`,\n );\n }\n\n return {\n type: 'pass',\n config: ctx.config,\n push: async (event: WalkerOS.DeepPartialEvent) => {\n const r = await processEventMapping(\n event,\n stepMapping,\n ctx.collector,\n );\n if (r.ignore) return false;\n return { event: r.event };\n },\n };\n }\n return {\n type: 'pass',\n config: ctx.config,\n push: (event: WalkerOS.DeepPartialEvent) => ({ event }),\n };\n });\n\n // Initialize the transformer instance with context\n const instance = await codeFn(context);\n\n // Bug 2 fix: propagate def-level before/next to instance.config when\n // not already set by the code function. The recursive chain walker\n // reads instance.config.before; for synthesized pass-throughs and\n // well-behaved user code that returns a fresh config object, the\n // def-level value needs to land on instance.config explicitly.\n // User-supplied code that sets its own config.before is preserved.\n if (\n transformerDef.before !== undefined &&\n instance.config?.before === undefined\n ) {\n instance.config = {\n ...(instance.config ?? {}),\n before: transformerDef.before,\n };\n }\n if (\n transformerDef.next !== undefined &&\n instance.config?.next === undefined\n ) {\n instance.config = {\n ...(instance.config ?? {}),\n next: transformerDef.next,\n };\n }\n\n result[transformerId] = instance;\n }\n\n return result;\n}\n\n/**\n * Initializes a transformer if it hasn't been initialized yet.\n * Called lazily before first push.\n *\n * @param collector - The collector instance\n * @param transformer - The transformer to initialize\n * @param transformerId - The transformer ID\n * @returns Whether initialization succeeded\n */\nexport async function transformerInit(\n collector: Collector.Instance,\n transformer: Transformer.Instance,\n transformerId: string,\n): Promise<boolean> {\n // Check if already initialized\n if (transformer.init && !transformer.config.init) {\n const transformerType = transformer.type || 'unknown';\n const transformerLogger = collector.logger.scope(\n `transformer:${transformerType}`,\n );\n\n const context: Transformer.Context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n ingest: createIngest(transformerId),\n config: transformer.config,\n env: mergeTransformerEnvironments(transformer.config.env),\n };\n\n transformerLogger.debug('init');\n\n const configResult = await useHooks(\n transformer.init,\n 'TransformerInit',\n collector.hooks,\n collector.logger,\n )(context);\n\n // Check for initialization failure\n if (configResult === false) return false;\n\n // Update config if returned, preserving env from definition\n transformer.config = {\n ...(configResult || transformer.config),\n env:\n ((configResult as Record<string, unknown>)?.env as Transformer.Env) ||\n transformer.config.env,\n init: true,\n };\n\n transformerLogger.debug('init done');\n }\n\n return true;\n}\n\n/**\n * Pushes an event through a single transformer.\n *\n * @param collector - The collector instance\n * @param transformer - The transformer to push to\n * @param transformerId - The transformer ID\n * @param event - The event to process\n * @param ingest - Mutable ingest context flowing through the pipeline\n * @returns The processed event, void for passthrough, or false to stop chain\n */\nexport async function transformerPush(\n collector: Collector.Instance,\n transformer: Transformer.Instance,\n transformerId: string,\n event: WalkerOS.DeepPartialEvent,\n ingest?: Ingest,\n respond?: import('@walkeros/core').RespondFn,\n): Promise<Transformer.Result | Transformer.Result[] | false | void> {\n const transformerType = transformer.type || 'unknown';\n const transformerLogger = collector.logger.scope(\n `transformer:${transformerType}`,\n );\n\n const context: Transformer.Context = {\n collector,\n logger: transformerLogger,\n id: transformerId,\n ingest: ingest!, // Mutable shared context\n config: transformer.config,\n env: {\n ...mergeTransformerEnvironments(transformer.config.env),\n ...(respond ? { respond } : {}),\n },\n };\n\n transformerLogger.debug('push', { event: (event as { name?: string }).name });\n\n const eventId = typeof event.id === 'string' ? event.id : '';\n const started = Date.now();\n const inState = buildBaseState(collector, {\n stepId: stepId('transformer', transformerId),\n stepType: 'transformer',\n phase: 'in',\n eventId,\n now: started,\n });\n emitStep(collector, inState);\n\n try {\n const result = await useHooks(\n transformer.push,\n 'TransformerPush',\n collector.hooks,\n collector.logger,\n )(event, context);\n\n const finished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: stepId('transformer', transformerId),\n stepType: 'transformer',\n phase: 'out',\n eventId,\n now: finished,\n });\n outState.durationMs = finished - started;\n outState.outEvent = result;\n emitStep(collector, outState);\n\n transformerLogger.debug('push done');\n\n return result;\n } catch (err) {\n const finished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepId('transformer', transformerId),\n stepType: 'transformer',\n phase: 'error',\n eventId,\n now: finished,\n });\n errState.durationMs = finished - started;\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n}\n\n/**\n * Clone an ingest for an independent branch (e.g. a `many` fan-out branch).\n *\n * Each branch needs its own `_meta.path` so cycle protection and the\n * MAX_PATH_LENGTH safety valve operate per-branch rather than colliding\n * across sibling forks. The top-level object and `_meta` are shallow-copied;\n * `_meta.path` is duplicated so appends in one branch do not leak into others.\n *\n * `branchId` is reserved for future per-branch labelling (Task 4.1) and is\n * not currently written into `_meta`; it is accepted now so callers don't\n * need to change their call sites when error-isolation lands.\n */\nexport function cloneIngest(\n ingest: Ingest | undefined,\n branchId: string,\n): Ingest {\n if (!ingest) return createIngest(branchId);\n return {\n ...ingest,\n _meta: { ...ingest._meta, path: [...ingest._meta.path] },\n };\n}\n\n/**\n * Runs an event through a chain of transformers.\n *\n * @param collector - The collector instance with transformers\n * @param transformers - Map of transformer instances\n * @param chain - Ordered array of transformer IDs to execute\n * @param event - The event to process\n * @param ingest - Mutable ingest context flowing through the pipeline\n * @returns The processed event or null if chain was stopped\n */\nexport async function runTransformerChain(\n collector: Collector.Instance,\n transformers: Transformer.Transformers,\n chain: string[],\n event: WalkerOS.DeepPartialEvent,\n ingest?: Ingest,\n respond?: import('@walkeros/core').RespondFn,\n chainContext?: string,\n): Promise<Transformer.ChainResult> {\n const MAX_PATH_LENGTH = 256;\n\n // Ensure an ingest exists so the per-branch path budget engages\n // regardless of caller. Production callers (source/push/destination)\n // always pass one; this guards direct test invocations and any future\n // entrypoint that omits it. Without an ingest, the safety valve below\n // can never trip — leaving cyclic `many` graphs unbounded.\n if (!ingest) {\n ingest = createIngest(chain[0] ?? 'chain');\n }\n\n if (chainContext && ingest._meta) {\n ingest._meta.chainPath = chainContext;\n }\n\n let processedEvent = event;\n let currentRespond = respond;\n\n for (const transformerName of chain) {\n const transformer = transformers[transformerName];\n if (!transformer) {\n collector.logger.warn(`Transformer not found: ${transformerName}`);\n continue;\n }\n\n // Safety valve: prevent unbounded path growth\n if (ingest && ingest._meta && ingest._meta.path.length > MAX_PATH_LENGTH) {\n collector.logger.error(`Max path length exceeded at ${transformerName}`);\n return { event: null, respond: currentRespond };\n }\n\n // Track step in _meta (runtime-managed)\n if (ingest && ingest._meta) {\n ingest._meta.hops++;\n ingest._meta.path.push(transformerName);\n }\n\n // Initialize transformer if needed. The wrap surfaces a thrown init\n // (misconfiguration, missing env, etc.) with full cause via the scoped\n // logger and counts it on `status.failed`. A non-throw `false` return\n // from transformerInit itself flows through the same early-return below\n // (handled by the destination's own log; counter remains untouched on\n // the deliberate-false path).\n const isInitialized = await tryCatchAsync(\n transformerInit,\n (err: unknown): boolean => {\n if (err instanceof FatalError) throw err;\n collector.status.failed++;\n collector.logger\n .scope(`transformer:${transformer.type || 'unknown'}`)\n .error('transformer init failed', {\n transformer: transformerName,\n error: err,\n });\n return false;\n },\n )(collector, transformer, transformerName);\n\n if (!isInitialized) {\n // Stop chain on init failure. Thrown cases were already logged with\n // full cause via the onError above; deliberate-false returns leave\n // the chain stop signal intact without extra noise.\n return { event: null, respond: currentRespond };\n }\n\n // Path-specific mock check (takes precedence)\n if (\n chainContext &&\n transformer.config?.chainMocks?.[chainContext] !== undefined\n ) {\n const chainMock = transformer.config.chainMocks[chainContext];\n collector.logger\n .scope(`transformer:${transformer.type || 'unknown'}`)\n .debug('chainMock', { chain: chainContext });\n processedEvent = chainMock as WalkerOS.DeepPartialEvent;\n continue;\n }\n\n // Global mock check\n if (transformer.config?.mock !== undefined) {\n collector.logger\n .scope(`transformer:${transformer.type || 'unknown'}`)\n .debug('mock');\n processedEvent = transformer.config.mock as WalkerOS.DeepPartialEvent;\n continue;\n }\n\n // Disabled check\n if (transformer.config?.disabled) {\n continue;\n }\n\n // Compile transformer cache once (reused for HIT check and MISS store).\n // Transformer caches operate on events (step-level HIT/MISS keyed by event\n // fields), so the rule shape is always EventCacheRule, not StoreCacheRule.\n const tCacheConfig = transformer.config?.cache as\n | Cache.Cache<Cache.EventCacheRule>\n | undefined;\n const compiledTCache = tCacheConfig\n ? compileCache(tCacheConfig)\n : undefined;\n const tCacheStore = compiledTCache\n ? getCacheStore(compiledTCache, collector)\n : undefined;\n\n // Check transformer cache (step-level: skip push, continue chain)\n let cacheMiss: { key: string; ttl: number } | undefined;\n if (compiledTCache && tCacheStore) {\n const cacheContext = buildCacheContext(ingest, processedEvent);\n const cacheResult = await checkCache(\n compiledTCache,\n tCacheStore,\n cacheContext,\n );\n\n if (cacheResult?.status === 'HIT' && cacheResult.value) {\n processedEvent = cacheResult.value as WalkerOS.DeepPartialEvent;\n if (compiledTCache.stop)\n // stop=true → stop chain AND halt pipeline at this position.\n // Caller branches on `stopped` to skip downstream stages\n // (collector.push, destinations); see push.ts and source.ts.\n return {\n event: processedEvent,\n respond: currentRespond,\n stopped: true,\n };\n continue; // stop=false → next transformer\n }\n\n if (cacheResult?.status === 'MISS') {\n cacheMiss = { key: cacheResult.key, ttl: cacheResult.rule.ttl };\n }\n }\n\n // Run transformer.before chain if configured.\n //\n // Dispatch uses `getNextSteps`:\n // - [] → no route matched; skip the before chain (passthrough).\n // - ['x'] → sequential continuation; walk static .next links from x\n // and run as a single subchain. Preserves cache.stop and\n // null/respond propagation from the nested chain.\n // - ['a','b',...] → `many` fan-out. Each branch is an independent\n // terminal subchain with a cloned ingest (per-branch\n // cycle protection). No merge: many is fan-out, not\n // enrichment, so parent processedEvent is unchanged.\n // Per-branch error isolation lands in Task 4.1;\n // respond suppression lands in Task 4.2.\n const transformerBefore = transformer.config.before;\n if (transformerBefore) {\n const beforeIds = getNextSteps(\n transformerBefore,\n buildCacheContext(ingest, processedEvent),\n );\n if (beforeIds.length === 1) {\n const beforeChainIds = walkChain(\n beforeIds[0],\n extractTransformerNextMap(transformers),\n );\n if (beforeChainIds.length > 0) {\n const beforeResult = await runTransformerChain(\n collector,\n transformers,\n beforeChainIds,\n processedEvent,\n ingest,\n currentRespond,\n chainContext,\n );\n if (beforeResult.event === null)\n return {\n event: null,\n respond: beforeResult.respond ?? currentRespond,\n }; // Before chain stopped\n // Propagate pipeline-halt from a nested `cache.stop: true` HIT in\n // the before chain. The outer caller (push.ts / source.ts) drops\n // the event before destinations see it.\n if (beforeResult.stopped) {\n return {\n event: Array.isArray(beforeResult.event)\n ? beforeResult.event[0]\n : beforeResult.event,\n respond: beforeResult.respond ?? currentRespond,\n stopped: true,\n };\n }\n if (beforeResult.respond) currentRespond = beforeResult.respond;\n // Before chains use first result if fan-out occurred\n processedEvent = Array.isArray(beforeResult.event)\n ? beforeResult.event[0]\n : beforeResult.event;\n }\n } else if (beforeIds.length > 1) {\n // many: independent terminal subchains. Each branch walks to its own\n // exit with a per-branch ingest clone. Per-branch error isolation\n // (Task 4.1): wrap each branch dispatch in `tryCatchAsync` so a\n // throw in one branch (init failure, unforeseen runtime error) does\n // not reject the surrounding `Promise.all` and starve siblings.\n // No-respond-across-many: respond ownership cannot be unambiguously\n // assigned when one inbound request fans out to N terminal flows.\n // Branch dispatch passes `undefined` instead of `currentRespond`, and\n // branch results are awaited and discarded — currentRespond is NOT\n // updated from any branch's wrapped respond.\n await Promise.all(\n beforeIds.map((id) =>\n tryCatchAsync(runTransformerChain, (err) => {\n collector.logger\n .scope('transformer:many')\n .error(`many branch ${id} failed`, { error: err });\n return { event: null, respond: undefined };\n })(\n collector,\n transformers,\n walkChain(id, extractTransformerNextMap(transformers)),\n processedEvent,\n cloneIngest(ingest, id),\n undefined,\n chainContext,\n ),\n ),\n );\n // No merge: many is fan-out, not enrichment. Parent processedEvent\n // unchanged.\n }\n }\n\n // Run the transformer\n const result = await tryCatchAsync(transformerPush, (err) => {\n collector.logger\n .scope(`transformer:${transformer.type || 'unknown'}`)\n .error('Push failed', { error: err });\n return false as const; // Stop chain on error\n })(\n collector,\n transformer,\n transformerName,\n processedEvent,\n ingest,\n currentRespond,\n );\n\n // Handle result\n if (result === false) {\n // Transformer explicitly stopped the chain\n return { event: null, respond: currentRespond };\n }\n\n // Handle Result array (fan-out) — MUST be before typeof === 'object'\n if (Array.isArray(result)) {\n const remainingChain = chain.slice(chain.indexOf(transformerName) + 1);\n\n const forkResults = await Promise.all(\n result.map(async (forkResult) => {\n const forkEvent = forkResult.event || processedEvent;\n // Clone ingest per fork to prevent cross-fork contamination\n const forkIngest = cloneIngest(ingest, 'unknown');\n\n if (forkResult.next) {\n // Fork has explicit routing. Dispatch uses `getNextSteps`:\n // - [] → no route matched; passthrough this fork's\n // event without entering any subchain (fork\n // has explicit routing, so we do NOT fall\n // through to remainingChain).\n // - ['x'] → walk static .next from x and run that as a\n // single subchain. Preserves the existing\n // \"fork has explicit routing terminates the\n // main chain at this branch\" semantic — the\n // subchain's ChainResult is this fork's\n // result.\n // - ['a','b',...] → `many` fan-out. Each id dispatches as its\n // own terminal subchain with a per-branch\n // cloned ingest. Returns an array of\n // ChainResults; the outer `.flat()` in the\n // aggregation loop folds them into the\n // surrounding flatEvents collection.\n const forkIds = getNextSteps(\n forkResult.next,\n buildCacheContext(forkIngest, forkEvent),\n );\n if (forkIds.length === 0) {\n return { event: forkEvent, respond: currentRespond };\n }\n if (forkIds.length === 1) {\n const branchedChain = walkChain(\n forkIds[0],\n extractTransformerNextMap(transformers),\n );\n if (branchedChain.length > 0) {\n return runTransformerChain(\n collector,\n transformers,\n branchedChain,\n forkEvent,\n forkIngest,\n currentRespond,\n chainContext,\n );\n }\n return { event: forkEvent, respond: currentRespond };\n }\n // Terminal fan-out. Each branch walks to its own exit with a\n // per-branch ingest clone. Per-branch error isolation\n // (Task 4.1): wrap each branch dispatch in `tryCatchAsync` so a\n // throw in one branch does not reject the surrounding\n // `Promise.all` and starve siblings.\n // No-respond-across-many: respond ownership cannot be unambiguously\n // assigned when one inbound request fans out to N terminal flows.\n // Branches are dispatched with `respond: undefined`, and the\n // ChainResults returned to the outer aggregation are stripped of\n // any branch-internal respond so the outer fork's combined result\n // never propagates a branch's wrapped respond back to the caller.\n const branchResults = await Promise.all(\n forkIds.map((id) =>\n tryCatchAsync(runTransformerChain, (err) => {\n collector.logger\n .scope('transformer:many')\n .error(`many branch ${id} failed`, { error: err });\n return { event: null, respond: undefined };\n })(\n collector,\n transformers,\n walkChain(id, extractTransformerNextMap(transformers)),\n forkEvent,\n cloneIngest(forkIngest, id),\n undefined,\n chainContext,\n ),\n ),\n );\n // Strip per-branch side-channels (respond, stopped) at the many\n // boundary. The outer aggregation only learns about events from\n // branch ChainResults; respond and stopped are branch-internal\n // concerns and must not leak back to the surrounding fork's\n // combined result.\n return branchResults.map(\n (br): Transformer.ChainResult => ({\n event: br.event,\n respond: undefined,\n }),\n );\n }\n\n // Fork continues through remaining chain\n if (remainingChain.length > 0) {\n return runTransformerChain(\n collector,\n transformers,\n remainingChain,\n forkEvent,\n forkIngest,\n currentRespond,\n chainContext,\n );\n }\n return { event: forkEvent, respond: currentRespond };\n }),\n );\n\n // Collect events from ChainResult objects and track last respond\n let lastForkRespond = currentRespond;\n const flatEvents: WalkerOS.DeepPartialEvent[] = [];\n for (const fr of forkResults.flat()) {\n if (fr === null) continue;\n if (fr && typeof fr === 'object' && 'event' in fr) {\n const cr = fr as Transformer.ChainResult;\n if (cr.respond) lastForkRespond = cr.respond;\n if (cr.event === null) continue;\n if (Array.isArray(cr.event)) flatEvents.push(...cr.event);\n else flatEvents.push(cr.event);\n } else {\n flatEvents.push(fr as WalkerOS.DeepPartialEvent);\n }\n }\n if (flatEvents.length === 0)\n return { event: null, respond: lastForkRespond };\n if (flatEvents.length === 1)\n return { event: flatEvents[0], respond: lastForkRespond };\n return { event: flatEvents, respond: lastForkRespond };\n }\n\n if (result && typeof result === 'object') {\n // Unified TransformerResult handling\n const { event: resultEvent, respond: resultRespond, next } = result;\n\n // Update respond if transformer provided a wrapper\n if (resultRespond) {\n currentRespond = resultRespond;\n }\n\n // Handle chain branching.\n //\n // Dispatch uses `getNextSteps`:\n // - [] → no route matched; passthrough (continue main chain\n // with resultEvent if provided).\n // - ['x'] → walk static .next from x and run that as a single\n // subchain. The branched subchain's ChainResult\n // becomes this transformer's final result; the main\n // chain terminates here (explicit routing wins).\n // - ['a','b',...] → `many` fan-out. Terminal: each branch dispatches\n // as its own subchain with a per-branch ingest\n // clone. Main chain terminates here. Per-branch\n // error isolation arrives in Task 4.1; respond\n // suppression in 4.2.\n if (next !== undefined) {\n const nextIds = getNextSteps(\n next,\n buildCacheContext(ingest, processedEvent),\n );\n if (nextIds.length === 0) {\n // No route matched → passthrough (continue chain)\n if (resultEvent) processedEvent = resultEvent;\n continue;\n }\n if (nextIds.length === 1) {\n const branchedChain = walkChain(\n nextIds[0],\n extractTransformerNextMap(transformers),\n );\n if (branchedChain.length > 0) {\n return runTransformerChain(\n collector,\n transformers,\n branchedChain,\n resultEvent || processedEvent,\n ingest,\n currentRespond,\n chainContext,\n );\n }\n // Branch target not found — drop event (fail-safe).\n collector.logger.warn(\n `Branch target not found: ${JSON.stringify(next)}`,\n );\n return { event: null, respond: currentRespond };\n }\n // many: terminal fan-out. Main chain terminates here. Per-branch\n // error isolation (Task 4.1): wrap each branch dispatch in\n // `tryCatchAsync` so a throw in one branch does not reject the\n // surrounding `Promise.all` and starve siblings.\n // No-respond-across-many: respond ownership cannot be unambiguously\n // assigned when one inbound request fans out to N terminal flows.\n // Branches are dispatched with `respond: undefined`, branch results\n // are awaited and discarded, and the outer return has\n // `respond: undefined` so the parent caller (source) sees no\n // wrapped respond.\n // No-stopped-across-many (Task 4.2 / regression-guarded by Task 4.3):\n // branch results — including any `stopped: true` from a nested\n // `cache.stop` HIT inside one branch — are discarded here. The outer\n // return omits `stopped`, so a cache.stop HIT in one branch does NOT\n // halt sibling branches. See the regression test\n // `transformer.test.ts > many: cache.stop in one branch does not\n // halt sibling branches`.\n await Promise.all(\n nextIds.map((id) =>\n tryCatchAsync(runTransformerChain, (err) => {\n collector.logger\n .scope('transformer:many')\n .error(`many branch ${id} failed`, { error: err });\n return { event: null, respond: undefined };\n })(\n collector,\n transformers,\n walkChain(id, extractTransformerNextMap(transformers)),\n resultEvent || processedEvent,\n cloneIngest(ingest, id),\n undefined,\n chainContext,\n ),\n ),\n );\n return { event: null, respond: undefined };\n }\n\n // Update event if provided\n if (resultEvent) {\n processedEvent = resultEvent;\n }\n }\n // If result is undefined (void), continue with current event unchanged\n\n // Cache MISS: store the processed event after push\n if (cacheMiss && tCacheStore) {\n storeCache(tCacheStore, cacheMiss.key, processedEvent, cacheMiss.ttl);\n }\n\n // If transformer didn't return { next } but has a conditional\n // config.next (one / gate / sequence / many), resolve it per-request\n // via `getNextSteps`. Static (string / string[]) chains are wired\n // statically via the next-map and pre-baked into `chain` by the\n // caller (or by `walkChain` when an explicit chain array is passed);\n // re-dispatching them here would override an explicit caller chain.\n //\n // Dispatch (conditional variants only):\n // - [] → no match; chain ends here (passthrough).\n // - ['x'] → continue main chain via static walk from x.\n // - ['a','b',...] → `many` fan-out. Terminal: each branch dispatches\n // as its own subchain with a per-branch ingest\n // clone. Main chain terminates here.\n const configNext = transformer.config.next;\n const isStaticConfigNext =\n typeof configNext === 'string' ||\n (Array.isArray(configNext) &&\n configNext.every((entry) => typeof entry === 'string'));\n const isConditionalConfigNext =\n configNext !== undefined && !isStaticConfigNext;\n if (\n (!result || (typeof result === 'object' && !result.next)) &&\n isConditionalConfigNext\n ) {\n const configNextIds = getNextSteps(\n transformer.config.next,\n buildCacheContext(ingest, processedEvent),\n );\n if (configNextIds.length === 1) {\n const continuationChain = walkChain(\n configNextIds[0],\n extractTransformerNextMap(transformers),\n );\n if (continuationChain.length > 0) {\n return runTransformerChain(\n collector,\n transformers,\n continuationChain,\n processedEvent,\n ingest,\n currentRespond,\n chainContext,\n );\n }\n // Target not found → chain ends here (passthrough)\n return { event: processedEvent, respond: currentRespond };\n }\n if (configNextIds.length > 1) {\n // many: terminal fan-out. Main chain terminates here. Per-branch\n // error isolation (Task 4.1): wrap each branch dispatch in\n // `tryCatchAsync` so a throw in one branch does not reject the\n // surrounding `Promise.all` and starve siblings.\n // No-respond-across-many: respond ownership cannot be unambiguously\n // assigned when one inbound request fans out to N terminal flows.\n // Branches are dispatched with `respond: undefined`, branch results\n // are awaited and discarded, and the outer return has\n // `respond: undefined` so the parent caller (source) sees no\n // wrapped respond.\n await Promise.all(\n configNextIds.map((id) =>\n tryCatchAsync(runTransformerChain, (err) => {\n collector.logger\n .scope('transformer:many')\n .error(`many branch ${id} failed`, { error: err });\n return { event: null, respond: undefined };\n })(\n collector,\n transformers,\n walkChain(id, extractTransformerNextMap(transformers)),\n processedEvent,\n cloneIngest(ingest, id),\n undefined,\n chainContext,\n ),\n ),\n );\n return { event: null, respond: undefined };\n }\n // configNextIds.length === 0: no match → chain ends here\n return { event: processedEvent, respond: currentRespond };\n }\n }\n\n return { event: processedEvent, respond: currentRespond };\n}\n\n/**\n * Merges transformer environments.\n */\nfunction mergeTransformerEnvironments(\n configEnv?: Transformer.Env,\n): Transformer.Env {\n if (!configEnv) return {};\n if (isObject(configEnv)) return configEnv;\n return {};\n}\n","import type { Collector, Store } from '@walkeros/core';\nimport type { CompiledCache } from '@walkeros/core';\n\n/**\n * Returns the store for a compiled cache config.\n * Uses the explicit store reference if provided, otherwise falls back to the\n * collector's default __cache store.\n */\nexport function getCacheStore(\n compiled: CompiledCache,\n collector: Collector.Instance,\n): Store.Instance | undefined {\n if (compiled.storeId && collector.stores[compiled.storeId]) {\n return collector.stores[compiled.storeId];\n }\n return collector.stores.__cache;\n}\n","import type { Logger } from '@walkeros/core';\n\n/**\n * Bounded-append helpers for collector internal buffers.\n *\n * Three collector buffers are size-bounded:\n * - `collector.queue` (replay buffer for late-registered destinations)\n * - `destination.queuePush` (consent-denied buffer, per destination)\n * - `destination.dlq` (failed-push dead-letter queue, per destination)\n *\n * All three share the same FIFO ring-buffer eviction semantics, so the\n * append logic lives in one place. `pushBounded` performs the size check,\n * evicts oldest entries (or refuses the new one for `dropNewest`), and\n * reports drops back to the caller via the typed result + optional callback.\n *\n * Caller responsibility: increment the appropriate status counter\n * under `status.dropped[stepId]` (see `stepId()` in @walkeros/core)\n * and emit the warn-once-on-transition log. The helper stays pure: no logger\n * coupling, no collector reference.\n */\n\nexport type BufferOverflowPolicy = 'dropOldest' | 'dropNewest';\n\nexport interface BufferBound {\n max: number;\n onOverflow?: BufferOverflowPolicy;\n}\n\nexport interface PushBoundedResult {\n /** Whether the new item was appended to the buffer. */\n appended: boolean;\n /** Number of items dropped on this call (0 in the happy path). */\n dropped: number;\n}\n\n/**\n * Append `item` to `buffer`, respecting `bound.max`. On overflow, evict\n * per `bound.onOverflow` (defaults to `'dropOldest'`).\n *\n * @param buffer - In-place mutated array.\n * @param item - Item to append.\n * @param bound - Cap + overflow policy.\n * @param onDrop - Optional callback receiving the dropped items (oldest\n * evictions on `dropOldest`, or the rejected new item on `dropNewest`).\n * Called once per overflow event with all dropped items batched.\n * @returns `{ appended, dropped }`.\n */\nexport function pushBounded<T>(\n buffer: T[],\n item: T,\n bound: BufferBound,\n onDrop?: (dropped: T[]) => void,\n): PushBoundedResult {\n if (!Number.isFinite(bound.max) || bound.max <= 0) {\n throw new Error(`pushBounded: max must be > 0 (got ${bound.max})`);\n }\n\n const policy: BufferOverflowPolicy = bound.onOverflow ?? 'dropOldest';\n\n if (policy === 'dropNewest') {\n if (buffer.length >= bound.max) {\n if (onDrop) onDrop([item]);\n return { appended: false, dropped: 1 };\n }\n buffer.push(item);\n return { appended: true, dropped: 0 };\n }\n\n // dropOldest\n const dropped: T[] = [];\n while (buffer.length >= bound.max) {\n // Length-guarded shift; never undefined here (max > 0, length > 0).\n dropped.push(buffer.shift()!);\n }\n buffer.push(item);\n if (dropped.length > 0 && onDrop) onDrop(dropped);\n return { appended: true, dropped: dropped.length };\n}\n\n/**\n * Per-buffer overflow log state. Used to emit a single warn when a buffer\n * crosses from below-cap to at-cap, suppressing further warns until the\n * buffer drains below cap and overflows again (per Q13).\n */\nconst overflowState = new WeakMap<object, boolean>();\n\n/**\n * Emit a warn-once log on the transition into overflow. Subsequent drops\n * within the same overflow window stay silent until the buffer drains\n * (the caller signals \"below-cap again\" by calling `resetOverflow`).\n *\n * The cumulative drop counter is still incremented on every drop by the\n * caller, so operators retain rate signal via `collector.status.dropped[stepId]`.\n */\nexport function warnOverflowOnce(\n buffer: object,\n logger: Logger.Instance,\n message: string,\n context: Record<string, unknown>,\n): void {\n if (overflowState.get(buffer)) return;\n overflowState.set(buffer, true);\n logger.warn(message, context);\n}\n\n/**\n * Reset the overflow flag when a buffer drains below cap, so the next\n * overflow transition will warn again.\n */\nexport function resetOverflowFlag(buffer: object): void {\n overflowState.delete(buffer);\n}\n","import type {\n Collector,\n WalkerOS,\n Destination,\n Elb,\n Hooks,\n On,\n} from '@walkeros/core';\nimport { Const } from './constants';\nimport {\n addDestination,\n pushToDestinations,\n createPushResult,\n} from './destination';\nimport { assign, getSpanId, isFunction, isString } from '@walkeros/core';\nimport { isObject } from '@walkeros/core';\nimport { processConsent } from './consent';\nimport { on, onApply } from './on';\nimport { destroyAllSteps } from './shutdown';\nimport type { RunState } from './types/collector';\n\n/**\n * Handles common commands.\n *\n * @param collector The walkerOS collector instance.\n * @param action The action to handle.\n * @param data The data to handle.\n * @returns A promise that resolves with the push result or undefined.\n */\nexport async function commonHandleCommand(\n collector: Collector.Instance,\n action: string,\n data?: unknown,\n): Promise<Elb.PushResult> {\n let result: Elb.PushResult | undefined;\n let onData: unknown;\n let shouldNotify = false;\n\n switch (action) {\n case Const.Commands.Config:\n if (isObject(data)) {\n assign(collector.config, data as Partial<Collector.Config>, {\n shallow: false,\n });\n onData = data;\n shouldNotify = true;\n }\n break;\n\n case Const.Commands.Consent:\n if (isObject(data)) {\n const { update } = processConsent(collector, data as WalkerOS.Consent);\n onData = update;\n shouldNotify = true;\n }\n break;\n\n case Const.Commands.Custom:\n if (isObject(data)) {\n collector.custom = assign(\n collector.custom,\n data as WalkerOS.Properties,\n );\n onData = data;\n shouldNotify = true;\n }\n break;\n\n case Const.Commands.Destination:\n if (\n isObject(data) &&\n 'code' in data &&\n isObject((data as Destination.Init).code)\n ) {\n result = await addDestination(collector, data as Destination.Init);\n }\n break;\n\n case Const.Commands.Globals:\n if (isObject(data)) {\n collector.globals = assign(\n collector.globals,\n data as WalkerOS.Properties,\n );\n onData = data;\n shouldNotify = true;\n }\n break;\n\n case Const.Commands.Hook:\n if (\n isObject(data) &&\n isString((data as { name?: unknown }).name) &&\n isFunction((data as { fn?: unknown }).fn)\n ) {\n const { name, fn } = data as {\n name: string;\n fn: WalkerOS.AnyFunction;\n };\n collector.hooks[name as keyof Hooks.Functions] = fn;\n onData = data;\n shouldNotify = true;\n }\n break;\n\n case Const.Commands.On:\n if (isObject(data) && isString((data as { type?: unknown }).type)) {\n const { type, rules } = data as {\n type: On.Types;\n rules: WalkerOS.SingleOrArray<On.Subscription>;\n };\n await on(collector, type, rules);\n }\n break;\n\n case Const.Commands.Ready:\n shouldNotify = true;\n break;\n\n case Const.Commands.Run:\n result = await runCollector(collector, data as RunState);\n shouldNotify = true;\n break;\n\n case Const.Commands.Session:\n shouldNotify = true;\n break;\n\n case Const.Commands.Shutdown:\n await destroyAllSteps(collector);\n break;\n\n case Const.Commands.User:\n if (isObject(data)) {\n assign(collector.user, data as WalkerOS.User, { shallow: false });\n onData = data;\n shouldNotify = true;\n }\n break;\n }\n\n // Single notification + flush point for all state-mutation commands\n if (shouldNotify) {\n await onApply(collector, action as On.Types, undefined, onData);\n result = await pushToDestinations(collector);\n }\n\n return result || createPushResult({ ok: true });\n}\n\n/**\n * Creates a full event from a partial event.\n *\n * @param collector The walkerOS collector instance.\n * @param partialEvent The partial event to transform.\n * @returns The full event.\n */\nexport function createEvent(\n collector: Collector.Instance,\n partialEvent: WalkerOS.PartialEvent,\n): WalkerOS.Event {\n if (!partialEvent.name) throw new Error('Event name is required');\n\n const [entityValue, actionValue] = partialEvent.name.split(' ');\n if (!entityValue || !actionValue) throw new Error('Event name is invalid');\n\n const {\n timestamp = Date.now(),\n name = `${entityValue} ${actionValue}`,\n data = {},\n context = {},\n globals = collector.globals,\n custom = {},\n user = collector.user,\n nested = [],\n consent = collector.consent,\n id = getSpanId(),\n trigger = '',\n entity = entityValue,\n action = actionValue,\n timing = 0,\n source = { type: 'collector', schema: '4' },\n } = partialEvent;\n\n return {\n name,\n data,\n context,\n globals,\n custom,\n user,\n nested,\n consent,\n id,\n trigger,\n entity,\n action,\n timestamp,\n timing,\n source,\n };\n}\n\n/**\n * Runs the collector by setting it to allowed state and processing queued events.\n *\n * @param collector The walkerOS collector instance.\n * @param state Optional state to merge with the collector (user, globals, consent, custom).\n * @returns A promise that resolves with the push result.\n */\nexport async function runCollector(\n collector: Collector.Instance,\n state?: RunState,\n): Promise<Elb.PushResult> {\n // Set the collector to allowed state\n collector.allowed = true;\n\n // Update timing for this run\n collector.timing = Date.now();\n\n // Update collector state if provided\n if (state) {\n // Update consent if provided\n if (state.consent) {\n collector.consent = assign(collector.consent, state.consent);\n }\n\n // Update user if provided\n if (state.user) {\n collector.user = assign(collector.user, state.user);\n }\n\n // Update globals if provided\n if (state.globals) {\n collector.globals = assign(\n collector.config.globalsStatic || {},\n state.globals,\n );\n }\n\n // Update custom if provided\n if (state.custom) {\n collector.custom = assign(collector.custom, state.custom);\n }\n }\n\n // Reset destination queues\n Object.values(collector.destinations).forEach((destination) => {\n destination.queuePush = [];\n });\n\n // Reset collector queue for this run\n collector.queue = [];\n\n // Increase round counter\n collector.round++;\n\n // Process any queued events now that the collector is allowed\n const result = await pushToDestinations(collector);\n\n return result;\n}\n","import type { Collector, Lifecycle, Logger } from '@walkeros/core';\n\nconst STEP_TIMEOUT = 5000;\n\n/**\n * Destroy all steps in pipeline order: sources → destinations → transformers.\n * Called by the collector's `shutdown` command handler.\n */\nexport async function destroyAllSteps(\n collector: Collector.Instance,\n): Promise<void> {\n const logger = collector.logger;\n\n // Phase 1: Sources (stop intake)\n await destroyStepGroup(collector.sources, 'source', logger);\n\n // Phase 2: Destinations (close connections)\n await destroyStepGroup(collector.destinations, 'destination', logger);\n\n // Phase 3: Transformers (release caches)\n await destroyStepGroup(collector.transformers, 'transformer', logger);\n\n // Phase 4: Stores (release storage — last, so transformers can flush during their destroy)\n await destroyStepGroup(collector.stores, 'store', logger);\n}\n\nasync function destroyStepGroup<\n T extends { config: unknown; env?: unknown; type?: string },\n>(\n steps: Record<string, T>,\n label: string,\n rootLogger: Logger.Instance,\n): Promise<void> {\n const promises = Object.entries(steps).map(async ([id, step]) => {\n // Access destroy via cast: its DestroyContext<C,E> generic is contravariant,\n // so concrete step types aren't assignable to a structural destroy signature.\n // Safe because we pass each step's own config/env back to its own destroy.\n const destroy = (\n step as {\n destroy?: (ctx: Lifecycle.DestroyContext) => void | Promise<void>;\n }\n ).destroy;\n if (!destroy) return;\n\n const stepType = step.type || 'unknown';\n const logger = rootLogger.scope(stepType);\n\n const context: Lifecycle.DestroyContext = {\n id,\n config: step.config,\n env: step.env ?? {},\n logger,\n };\n\n try {\n await Promise.race([\n destroy(context),\n new Promise<void>((_, reject) =>\n setTimeout(\n () => reject(new Error(`${label} '${id}' destroy timed out`)),\n STEP_TIMEOUT,\n ),\n ),\n ]);\n } catch (err) {\n logger.error(`${label} '${id}' destroy failed: ${err}`);\n }\n });\n\n await Promise.allSettled(promises);\n}\n","import type { Collector, WalkerOS, Elb, Ingest } from '@walkeros/core';\nimport {\n createIngest,\n emitStep,\n FatalError,\n getGrantedConsent,\n processEventMapping,\n tryCatchAsync,\n useHooks,\n} from '@walkeros/core';\nimport { createEvent } from './handle';\nimport { pushToDestinations, createPushResult } from './destination';\nimport { buildBaseState } from './observerEmit';\nimport { runTransformerChain } from './transformer';\n\nfunction filterDestinations(\n destinations: Collector.Destinations,\n include?: string[],\n exclude?: string[],\n): Collector.Destinations {\n let filtered = destinations;\n if (include) {\n filtered = Object.fromEntries(\n Object.entries(filtered).filter(([id]) => include.includes(id)),\n );\n }\n if (exclude) {\n filtered = Object.fromEntries(\n Object.entries(filtered).filter(([id]) => !exclude.includes(id)),\n );\n }\n return filtered;\n}\n\n/**\n * Creates the push function for the collector.\n * Handles source mapping, event creation, and routing to destinations.\n *\n * @param collector - The walkerOS collector instance\n * @param prepareEvent - Function to enrich partial events\n * @returns The push function\n */\nexport function createPush<T extends Collector.Instance>(\n collector: T,\n prepareEvent: (event: WalkerOS.DeepPartialEvent) => WalkerOS.PartialEvent,\n): Collector.PushFn {\n const innerPush = useHooks(\n async (\n event: WalkerOS.DeepPartialEvent,\n options: Collector.PushOptions = {},\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n const pushStart = Date.now();\n const {\n id,\n ingest,\n respond: initialRespond,\n mapping,\n preChain,\n include,\n exclude,\n } = options;\n let respond = initialRespond;\n let partialEvent = event;\n\n // Build filtered destination set if include/exclude specified\n const filteredDests =\n include || exclude\n ? filterDestinations(collector.destinations, include, exclude)\n : undefined;\n\n // Create mutable Ingest — accumulates context through the pipeline\n const pipelineIngest: Ingest =\n (ingest as Ingest | undefined) ?? createIngest(id || 'unknown');\n\n // Apply source mapping if provided in options\n if (mapping) {\n const processed = await processEventMapping(\n partialEvent,\n mapping,\n collector,\n );\n\n // Check ignore flag\n if (processed.ignore) {\n return createPushResult({ ok: true });\n }\n\n // Check consent requirements\n if (mapping.consent) {\n const grantedConsent = getGrantedConsent(\n mapping.consent,\n collector.consent,\n processed.event.consent as WalkerOS.Consent | undefined,\n );\n\n if (!grantedConsent) {\n return createPushResult({ ok: true });\n }\n }\n\n partialEvent = processed.event;\n }\n\n // Run pre-collector transformer chain if provided in options\n if (\n preChain?.length &&\n collector.transformers &&\n Object.keys(collector.transformers).length > 0\n ) {\n const chainResult = await runTransformerChain(\n collector,\n collector.transformers,\n preChain,\n partialEvent,\n pipelineIngest,\n respond,\n id ? `source.${id}.next` : undefined,\n );\n\n // Chain was stopped - event dropped\n if (chainResult.event === null) {\n return createPushResult({ ok: true });\n }\n\n // Pipeline-halt signal from a pre-collector `cache.stop: true`\n // HIT. The event is intentionally NOT forwarded to destinations;\n // duplicates are suppressed at the source.next boundary per the\n // documented \"downstream transformers and destinations are\n // skipped\" semantic in transformers/cache.mdx.\n if (chainResult.stopped) {\n if (chainResult.respond) respond = chainResult.respond;\n return createPushResult({ ok: true });\n }\n\n // Update respond if the chain produced a wrapped one\n if (chainResult.respond) respond = chainResult.respond;\n\n // Handle fan-out: array means multiple events from a single input\n if (Array.isArray(chainResult.event)) {\n // Process each forked event through the rest of the pipeline\n const forkResults = await Promise.all(\n chainResult.event.map(async (forkEvent) => {\n const enriched = prepareEvent(forkEvent);\n const full = createEvent(collector, enriched);\n return pushToDestinations(\n collector,\n full,\n {\n id,\n ingest: pipelineIngest,\n respond,\n },\n filteredDests,\n );\n }),\n );\n\n // Update source status\n if (id) {\n if (!collector.status.sources[id]) {\n collector.status.sources[id] = {\n count: 0,\n duration: 0,\n };\n }\n const sourceStatus = collector.status.sources[id];\n sourceStatus.count += chainResult.event.length;\n sourceStatus.lastAt = Date.now();\n sourceStatus.duration += Date.now() - pushStart;\n }\n\n return forkResults[0] ?? createPushResult({ ok: true });\n }\n\n partialEvent = chainResult.event;\n }\n\n // Prepare event (add timing, source info)\n const enrichedEvent = prepareEvent(partialEvent);\n\n // Create full event\n const fullEvent = createEvent(collector, enrichedEvent);\n\n // Push to destinations with id and ingest\n const result = await pushToDestinations(\n collector,\n fullEvent,\n {\n id,\n ingest: pipelineIngest,\n respond,\n },\n filteredDests,\n );\n\n // Update source status\n if (id) {\n if (!collector.status.sources[id]) {\n collector.status.sources[id] = {\n count: 0,\n duration: 0,\n };\n }\n const sourceStatus = collector.status.sources[id];\n sourceStatus.count++;\n sourceStatus.lastAt = Date.now();\n sourceStatus.duration += Date.now() - pushStart;\n }\n\n return result;\n },\n (err: unknown) => {\n if (err instanceof FatalError) throw err;\n collector.status.failed++;\n collector.logger.error('push failed', {\n event,\n ingest: options.ingest,\n error: err,\n });\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Push',\n collector.hooks,\n collector.logger,\n );\n\n const wrapped: Collector.PushFn = async (event, options) => {\n const eventId = typeof event.id === 'string' ? event.id : '';\n const started = Date.now();\n emitStep(\n collector,\n buildBaseState(collector, {\n stepId: 'collector.push',\n stepType: 'collector',\n phase: 'in',\n eventId,\n now: started,\n }),\n );\n\n try {\n const result = await innerPush(event, options);\n const finished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: 'collector.push',\n stepType: 'collector',\n phase: 'out',\n eventId,\n now: finished,\n });\n outState.durationMs = finished - started;\n outState.outEvent = result;\n emitStep(collector, outState);\n return result;\n } catch (err) {\n const finished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: 'collector.push',\n stepType: 'collector',\n phase: 'error',\n eventId,\n now: finished,\n });\n errState.durationMs = finished - started;\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n };\n\n return wrapped;\n}\n","import type { Collector, Elb } from '@walkeros/core';\nimport type { HandleCommandFn } from './types/collector';\nimport { FatalError, useHooks, tryCatchAsync } from '@walkeros/core';\nimport { createPushResult } from './destination';\n\n/**\n * Creates the command function for the collector.\n * Handles walker commands (config, consent, destination, etc.)\n *\n * @param collector - The walkerOS collector instance\n * @param handleCommand - Command handler function\n * @returns The command function\n */\nexport function createCommand<T extends Collector.Instance>(\n collector: T,\n handleCommand: HandleCommandFn<T>,\n): Collector.CommandFn {\n return useHooks(\n async (\n command: string,\n data?: unknown,\n options?: unknown,\n ): Promise<Elb.PushResult> => {\n return await tryCatchAsync(\n async (): Promise<Elb.PushResult> => {\n return await handleCommand(collector, command, data, options);\n },\n (err: unknown) => {\n if (err instanceof FatalError) throw err;\n collector.status.failed++;\n collector.logger.error('command failed', {\n command,\n data,\n error: err,\n });\n return createPushResult({ ok: false });\n },\n )();\n },\n 'Command',\n collector.hooks,\n collector.logger,\n );\n}\n","import type { Cache, Collector, Store } from '@walkeros/core';\nimport { emitStep, useHooks } from '@walkeros/core';\nimport { createCacheStore } from './cache-store';\nimport { buildBaseState } from './observerEmit';\nimport { wrapStoreWithCache } from './store-cache-wrapper';\n\n/**\n * Narrowed view of a `Store.InitStore` entry that also carries the optional\n * `cache` configuration emitted by the bundler. The runtime `Store.InitStores`\n * map is loosely typed at the core level so it can carry pass-through fields\n * (`cache`, `variables`, etc.) without coupling the core `Store.InitStore`\n * shape to flow-level concerns. Phase 2 reads `cache` through this local view.\n */\ntype InitStoreWithCache = Store.InitStore & {\n cache?: Cache.Cache<Cache.StoreCacheRule>;\n};\n\n/**\n * Hook wrapping and observer emission for a single store instance.\n * Mutates `instance` in place.\n *\n * Called once per store, AFTER any cache wrapping in phase 2. Wrapping the\n * outer (wrapper) instance means observers see the consumer-facing\n * boundary: they fire on every `wrapped.get` regardless of cache HIT/MISS,\n * and only once per `wrapped.set` (not also for the wrapper's internal\n * write into `cacheStore`). If the store has no cache wrapper, the bare\n * backing is wrapped instead, preserving observability.\n *\n * Two responsibilities per op:\n * 1. Inner `useHooks(..., 'StoreGet', ...)` wrap keeps the generic\n * user-declared hook contract working (`preStoreGet`, `postStoreSet`,\n * etc.).\n * 2. Outer self-emit wrap pushes `FlowState` (`stepType: 'store'`) into\n * `collector.observers` directly, so per-store telemetry no longer\n * needs a separate hook bag.\n */\nfunction applyStoreHooks(\n collector: Collector.Instance,\n instance: Store.Instance,\n storeId: string,\n): void {\n const stepIdFor = `store.${storeId}`;\n\n const innerGet = useHooks(\n instance.get,\n 'StoreGet',\n collector.hooks,\n collector.logger,\n );\n const innerSet = useHooks(\n instance.set,\n 'StoreSet',\n collector.hooks,\n collector.logger,\n );\n const innerDelete = useHooks(\n instance.delete,\n 'StoreDelete',\n collector.hooks,\n collector.logger,\n );\n\n instance.get = async (key: string): Promise<unknown> => {\n const started = Date.now();\n const inState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'in',\n eventId: '',\n now: started,\n });\n inState.meta = { op: 'get', key };\n emitStep(collector, inState);\n\n try {\n const result = await innerGet(key);\n const finished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'out',\n eventId: '',\n now: finished,\n });\n outState.durationMs = finished - started;\n outState.meta = { op: 'get', key };\n emitStep(collector, outState);\n return result;\n } catch (err) {\n const finished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'error',\n eventId: '',\n now: finished,\n });\n errState.durationMs = finished - started;\n errState.meta = { op: 'get', key };\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n };\n\n instance.set = async (\n key: string,\n value: unknown,\n ttl?: number,\n ): Promise<void> => {\n const started = Date.now();\n const inState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'in',\n eventId: '',\n now: started,\n });\n // Store values can be secrets or PII: emit only the op + key, never the\n // raw value, on any phase (in/out/error). Observers see what happened,\n // not what was written.\n inState.meta = { op: 'set', key };\n emitStep(collector, inState);\n\n try {\n await innerSet(key, value, ttl);\n const finished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'out',\n eventId: '',\n now: finished,\n });\n outState.durationMs = finished - started;\n outState.meta = { op: 'set', key };\n emitStep(collector, outState);\n } catch (err) {\n const finished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'error',\n eventId: '',\n now: finished,\n });\n errState.durationMs = finished - started;\n errState.meta = { op: 'set', key };\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n };\n\n instance.delete = async (key: string): Promise<void> => {\n const started = Date.now();\n const inState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'in',\n eventId: '',\n now: started,\n });\n inState.meta = { op: 'delete', key };\n emitStep(collector, inState);\n\n try {\n await innerDelete(key);\n const finished = Date.now();\n const outState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'out',\n eventId: '',\n now: finished,\n });\n outState.durationMs = finished - started;\n outState.meta = { op: 'delete', key };\n emitStep(collector, outState);\n } catch (err) {\n const finished = Date.now();\n const errState = buildBaseState(collector, {\n stepId: stepIdFor,\n stepType: 'store',\n phase: 'error',\n eventId: '',\n now: finished,\n });\n errState.durationMs = finished - started;\n errState.meta = { op: 'delete', key };\n errState.error =\n err instanceof Error\n ? { name: err.name, message: err.message }\n : { message: String(err) };\n emitStep(collector, errState);\n throw err;\n }\n };\n}\n\n/**\n * Walks the `cache.store` graph in topological order (terminals first) and\n * reports each store id together with its cache config. Detects cycles via\n * three-color DFS (WHITE → GRAY → BLACK) and rejects references to unknown\n * store ids. Throws on the first problem with a message naming the path.\n *\n * The returned order is suitable for wrapping: when a wrapper is built for\n * store X, its `cache.store` target (if any) has already been wrapped.\n */\nfunction topoOrderForCacheWrap(\n defs: Record<string, InitStoreWithCache>,\n): string[] {\n type Color = 'WHITE' | 'GRAY' | 'BLACK';\n const color: Record<string, Color> = {};\n for (const id of Object.keys(defs)) color[id] = 'WHITE';\n\n const order: string[] = [];\n const stack: string[] = [];\n\n function visit(id: string): void {\n const c = color[id];\n if (c === 'BLACK') return;\n if (c === 'GRAY') {\n const cycleStart = stack.indexOf(id);\n const cyclePath = stack\n .slice(cycleStart === -1 ? 0 : cycleStart)\n .concat(id)\n .join(' -> ');\n throw new Error(`Cycle in cache.store chain: ${cyclePath}`);\n }\n\n color[id] = 'GRAY';\n stack.push(id);\n\n const target = defs[id].cache?.store;\n if (target !== undefined) {\n if (!(target in defs)) {\n throw new Error(\n `Store \"${id}\" cache.store references \"${target}\", which is not declared in flow.stores`,\n );\n }\n visit(target);\n }\n\n stack.pop();\n color[id] = 'BLACK';\n order.push(id);\n }\n\n for (const id of Object.keys(defs)) {\n if (color[id] === 'WHITE') visit(id);\n }\n\n return order;\n}\n\n/**\n * Initialize store instances from configuration.\n *\n * Three-phase init:\n * Phase 1, instantiate: call `code(context)` for every declared store.\n * Order is not significant in this phase. Hooks are NOT installed yet —\n * they wrap the outer boundary in phase 3.\n * Phase 2, topologically wrap: walk the `cache.store` graph, detect cycles\n * and unknown targets, then visit terminals first so any cache wrapper\n * installed in Task 7+ can rely on its backing being already wrapped.\n * Phase 3, install hooks: wrap the final instance (wrapper if cache was\n * applied, otherwise the bare backing) so hooks fire at the consumer\n * boundary and observe cache HIT/MISS behavior.\n *\n * Phase 2 must run before `resolveStoreReferences` in `collector.ts` so that\n * env-reference replacement uses the wrapped instance (referential identity\n * matters for the resolver).\n */\nexport async function initStores(\n collector: Collector.Instance,\n initStores: Store.InitStores = {},\n): Promise<Store.Stores> {\n const result: Store.Stores = {};\n\n // Phase 1: instantiate every store. Hooks are deferred to phase 3 so they\n // can wrap the outer (cache-wrapped) instance and observe HIT/MISS at the\n // consumer-facing boundary.\n for (const [storeId, storeDef] of Object.entries(initStores)) {\n const { code, config = {}, env = {} } = storeDef;\n\n const storeLogger = collector.logger.scope('store').scope(storeId);\n\n const context = {\n collector,\n logger: storeLogger,\n id: storeId,\n config,\n env,\n };\n\n const instance = await code(context);\n result[storeId] = instance;\n }\n\n // Phase 2: validate the cache.store graph and wrap in topological order.\n // Cycle and missing-target errors propagate out of `topoOrderForCacheWrap`.\n // Read-through wrapping is delegated to `wrapStoreWithCache`. The cache\n // layer is either a user-declared store (resolved against the in-progress\n // `result` map) or the default `__cache`, which is created lazily here so\n // it ends up assigned to `collector.stores` together with the rest.\n const defsWithCache = initStores as Record<string, InitStoreWithCache>;\n const order = topoOrderForCacheWrap(defsWithCache);\n for (const storeId of order) {\n const cacheConfig = defsWithCache[storeId].cache;\n if (!cacheConfig) continue;\n\n let cacheStore: Store.Instance;\n let cacheStoreId: string;\n if (cacheConfig.store !== undefined) {\n // Missing-target validation already ran in `topoOrderForCacheWrap`, so\n // this lookup is guaranteed to hit.\n cacheStore = result[cacheConfig.store];\n cacheStoreId = cacheConfig.store;\n } else {\n if (!result.__cache) {\n result.__cache = createCacheStore();\n }\n cacheStore = result.__cache;\n cacheStoreId = '__cache';\n }\n\n // Schema rejects `namespace: \"\"` for store caches, so the only way the\n // wrapper sees an absent namespace is when the user omitted it entirely.\n // In that case default to the host store id so multiple wrapped stores\n // sharing `__cache` cannot collide on raw keys.\n const resolvedNamespace = cacheConfig.namespace ?? storeId;\n\n // One startup log line per wrapped store. Operators inspecting the cache\n // layer see prefixed keys (e.g. `api:K`); surfacing the resolved namespace\n // and cache-store id here keeps that defaulting from feeling like hidden\n // magic. Scope mirrors the wrapper's own scope (Task 8) so all\n // cache-related output groups under `store-cache:<id>`.\n collector.logger\n .scope('store-cache')\n .scope(storeId)\n .info(\n `store \"${storeId}\" caches with namespace \"${resolvedNamespace}:\" via ${cacheStoreId}`,\n );\n\n result[storeId] = wrapStoreWithCache(result[storeId], {\n storeId,\n cacheConfig,\n cacheStore,\n namespace: resolvedNamespace,\n logger: collector.logger.scope('store-cache').scope(storeId),\n collector,\n });\n }\n\n // Phase 3: install hooks on the final instance for every user-declared\n // store. Wrapping the OUTER instance (wrapper if a cache was applied,\n // bare backing otherwise) means the hook fires at the consumer-facing\n // boundary and observes cache HIT/MISS. The auto-created default\n // `__cache` is skipped — it has no consumer-facing contract; users never\n // call `__cache.get` directly. Skipping it also prevents the wrapper's\n // internal writes into the default cache from double-firing\n // `preStoreSet` against the consumer-facing boundary.\n for (const [storeId, instance] of Object.entries(result)) {\n if (storeId === '__cache') continue;\n applyStoreHooks(collector, instance, storeId);\n }\n\n return result;\n}\n\n/**\n * Resolve store references in component env values.\n *\n * The bundler resolves `$store.gcs` to a direct JS reference to the raw\n * store definition object (`stores.gcs = { code, config }`). After stores\n * are initialized, this function walks transformer/destination/source env\n * objects and replaces any raw store definition reference with the\n * corresponding initialized Store.Instance.\n *\n * IMPORTANT: Uses referential identity (`===`) to match env values against\n * raw store definitions. This works because the bundler generates code where\n * env values are direct references to the same objects in the `stores` map.\n * Programmatic configs must use the same object reference — copies won't match.\n *\n * Only resolves top-level env keys. Nested store references are not supported.\n */\nexport function resolveStoreReferences(\n rawStores: Store.InitStores,\n initializedStores: Store.Stores,\n initConfig: Collector.InitConfig,\n): void {\n // Build a lookup: raw store def → initialized instance (O(1) per env value)\n const lookup = new Map<object, Store.Instance>();\n for (const [storeId, rawDef] of Object.entries(rawStores)) {\n if (initializedStores[storeId])\n lookup.set(rawDef, initializedStores[storeId]);\n }\n if (lookup.size === 0) return;\n\n function resolveEnv(env: Record<string, unknown> | undefined) {\n if (!env) return;\n for (const [key, value] of Object.entries(env)) {\n if (typeof value === 'object' && value !== null) {\n const instance = lookup.get(value);\n if (instance) env[key] = instance;\n }\n }\n }\n\n // Walk all component types that may have env values\n for (const defs of [\n initConfig.transformers,\n initConfig.destinations,\n initConfig.sources,\n ]) {\n if (!defs) continue;\n for (const def of Object.values(defs)) {\n resolveEnv((def as { env?: Record<string, unknown> }).env);\n }\n }\n}\n","import type { Store } from '@walkeros/core';\n\n/**\n * Options for the built-in collector cache store (`__cache`).\n *\n * The default cache is an entry-capped LRU with active TTL sweep. Byte-size\n * accounting is opt-in: when `maxSize` is `undefined`, no byte budget is\n * enforced.\n */\nexport interface CacheStoreOptions {\n /** Hard cap on entries. Defaults to 10000. */\n maxEntries?: number;\n /**\n * Optional byte budget for the cache. When set, byte-sized eviction is\n * enabled in addition to entry-count eviction. Defaults to `undefined`\n * (no byte budget).\n */\n maxSize?: number;\n /**\n * Active sweep interval (ms) for purging expired entries even when they\n * are never read. Defaults to 60_000 (60 seconds). Pass 0 to disable.\n */\n sweepIntervalMs?: number;\n /**\n * Fraction of `maxEntries` to keep after a batched eviction pass. Defaults\n * to 0.8. The cache trims to `maxEntries * lowWaterMark` in one pass on\n * overflow.\n */\n lowWaterMark?: number;\n}\n\n/**\n * Operational counters exposed by the cache store. All counters are\n * monotonic for the lifetime of the cache instance.\n */\nexport interface CacheStoreCounters {\n /** Successful `get` calls that returned a live cached value. */\n hits: number;\n /** `get` calls that found no entry (cold) or only an expired one. */\n misses: number;\n /** `set` calls that created a new key (first-time population). */\n populates: number;\n /** All `set` calls (populates + overwrites). */\n writes: number;\n /** All `delete` calls that removed an existing key. */\n deletes: number;\n /** Entries removed because the cache hit `maxEntries`. */\n evictions_entries: number;\n /** Entries removed because their TTL expired (sweep or lazy). */\n evictions_ttl: number;\n}\n\ninterface CacheEntry {\n value: unknown;\n expires?: number;\n}\n\n/**\n * The upgraded `__cache` store. Backward-compatible with the existing\n * `Store.Instance` shape — callers see `get(key)`, `set(key, value, ttl?)`,\n * `delete(key)`. Adds an observability surface via `counters` and an active\n * TTL sweep that runs on a timer.\n *\n * Eviction model:\n * - Map iteration order is insertion order; oldest insertion is the FIFO head.\n * - `get` reorders the entry to most-recently-used (delete + re-insert).\n * - On insert overflow (size > maxEntries), evict in one pass down to\n * `lowWaterMark * maxEntries` (default 80%).\n *\n * Active TTL sweep: every `sweepIntervalMs` ms, walk the map and drop any\n * entries past `expires`. The interval is cleared in `destroy()`.\n */\nexport type CacheStore = Store.Instance & {\n readonly counters: CacheStoreCounters;\n destroy: () => void;\n};\n\nconst DEFAULT_MAX_ENTRIES = 10000;\nconst DEFAULT_SWEEP_INTERVAL_MS = 60_000;\nconst DEFAULT_LOW_WATER_MARK = 0.8;\n\nexport function createCacheStore(options: CacheStoreOptions = {}): CacheStore {\n const maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;\n const lowWaterMark = options.lowWaterMark ?? DEFAULT_LOW_WATER_MARK;\n const sweepIntervalMs = options.sweepIntervalMs ?? DEFAULT_SWEEP_INTERVAL_MS;\n const targetSize = Math.floor(maxEntries * lowWaterMark);\n\n const entries = new Map<string, CacheEntry>();\n\n const counters: CacheStoreCounters = {\n hits: 0,\n misses: 0,\n populates: 0,\n writes: 0,\n deletes: 0,\n evictions_entries: 0,\n evictions_ttl: 0,\n };\n\n function evictOverflow(): void {\n if (entries.size <= maxEntries) return;\n // Trim in one pass down to targetSize using insertion-order iteration\n // (oldest first). LRU is preserved because `get` re-inserts on access.\n const toRemove = entries.size - targetSize;\n let removed = 0;\n for (const key of entries.keys()) {\n if (removed >= toRemove) break;\n entries.delete(key);\n removed++;\n }\n counters.evictions_entries += removed;\n }\n\n function sweep(): void {\n const now = Date.now();\n let removed = 0;\n for (const [key, entry] of entries) {\n if (entry.expires !== undefined && entry.expires <= now) {\n entries.delete(key);\n removed++;\n }\n }\n counters.evictions_ttl += removed;\n }\n\n let sweepTimer: ReturnType<typeof setInterval> | undefined;\n if (sweepIntervalMs > 0) {\n sweepTimer = setInterval(sweep, sweepIntervalMs);\n // Don't keep the Node.js event loop alive solely for the cache sweep.\n if (\n sweepTimer &&\n typeof (sweepTimer as { unref?: () => void }).unref === 'function'\n ) {\n (sweepTimer as { unref: () => void }).unref();\n }\n }\n\n const store: CacheStore = {\n type: 'memory',\n config: {},\n\n get(key: string): unknown {\n const entry = entries.get(key);\n if (!entry) {\n counters.misses++;\n return undefined;\n }\n\n if (entry.expires !== undefined && entry.expires <= Date.now()) {\n entries.delete(key);\n counters.evictions_ttl++;\n counters.misses++;\n return undefined;\n }\n\n // LRU: move to most-recently-used position.\n entries.delete(key);\n entries.set(key, entry);\n counters.hits++;\n return entry.value;\n },\n\n set(key: string, value: unknown, ttl?: number): void {\n const isNew = !entries.has(key);\n // Always delete first so re-insert puts the entry at the\n // most-recently-used position regardless of overwrite or new.\n if (!isNew) entries.delete(key);\n\n entries.set(key, {\n value,\n expires: ttl !== undefined ? Date.now() + ttl : undefined,\n });\n\n counters.writes++;\n if (isNew) counters.populates++;\n\n if (entries.size > maxEntries) evictOverflow();\n },\n\n delete(key: string): void {\n if (entries.delete(key)) counters.deletes++;\n },\n\n get counters() {\n // Return a snapshot so external callers can't mutate internal state.\n return { ...counters };\n },\n\n destroy(): void {\n if (sweepTimer !== undefined) {\n clearInterval(sweepTimer);\n sweepTimer = undefined;\n }\n entries.clear();\n },\n };\n\n return store;\n}\n","import type { Cache, Collector, Logger, Store } from '@walkeros/core';\nimport { compileMatcher, emitStep } from '@walkeros/core';\nimport { buildBaseState } from './observerEmit';\n\n/**\n * Options passed to `wrapStoreWithCache`. Pre-resolved by `initStores` phase\n * 2 so the wrapper itself stays small and side-effect free at construction.\n *\n * - `cacheStore` is the store layer where cached values live. Defaults to\n * the collector's `__cache` instance, but may be any other initialized\n * store (e.g. a fs-backed cache for cross-process sharing).\n * - `namespace` is the prefix prepended to every key written to the cache\n * layer. Defaults to `storeId` when the user did not override\n * `cache.namespace`.\n * - `logger` is the collector's scoped logger, used for the best-effort\n * warnings emitted when a cache-side write or delete fails. Optional only\n * to keep test setups lightweight — production call sites pass\n * `collector.logger`.\n */\nexport interface WrappedStoreOptions {\n storeId: string;\n cacheConfig: Cache.Cache<Cache.StoreCacheRule>;\n cacheStore: Store.Instance;\n namespace: string;\n logger?: Logger.Instance;\n /**\n * Optional collector reference for cache-level observability. When\n * provided, the wrapper emits a `FlowState` (`stepType: 'store'`,\n * `meta.op: 'cache'`) on every wrapped `get`, carrying the resolved\n * cache status (`'hit'` or `'miss'`) and the key. Observers attached\n * to `collector.observers` see HIT/MISS without coupling to wrapper\n * internals. Optional only to keep unit-test setups lightweight;\n * production call sites pass it.\n */\n collector?: Collector.Instance;\n}\n\ninterface CompiledStoreCacheRule {\n match: (context: Record<string, unknown>) => boolean;\n ttl: number;\n}\n\n/**\n * Per-wrapped-store observability counters. The `evictions_*` counters live on\n * the underlying cache store (`createCacheStore` returns its own counters\n * surface for the global `__cache`), so they are deliberately absent here.\n *\n * Semantics:\n * - `hits` — `cacheStore.get` returned a defined value.\n * - `misses` — cache returned undefined AND no in-flight Promise was joined\n * (this caller is the one driving the backing fetch).\n * - `populates` — the wrapper wrote into the cache after a backing MISS that\n * returned a defined value AND matched a rule.\n * - `writes` — every call to `wrapper.set`, regardless of cache outcome.\n * - `deletes` — every call to `wrapper.delete`.\n * - `inflight_dedups` — a get found an in-flight Promise on the same key and\n * joined it instead of starting a new backing call.\n */\nexport interface WrappedStoreCounters {\n hits: number;\n misses: number;\n populates: number;\n writes: number;\n deletes: number;\n inflight_dedups: number;\n}\n\n/**\n * Public-facing extension of `Store.Instance` with the per-wrapper counter\n * surface. Consumers that need observability (operator UIs, debug endpoints)\n * cast to this type via `as WrappedStoreInstance`; everything else continues\n * to see the canonical `Store.Instance` shape and stays decoupled from the\n * wrapper's internals.\n */\nexport interface WrappedStoreInstance extends Store.Instance {\n /**\n * Snapshot accessor: returns a fresh copy of the counter map on every\n * access. Mutating the returned object never affects internal state, so\n * callers can serialize, diff, or send the snapshot freely. The returned\n * object always carries every counter key, zero-initialized.\n */\n readonly counters: WrappedStoreCounters;\n}\n\n/**\n * Wrap a backing `Store.Instance` with a read-through cache layer.\n *\n * Read semantics:\n * 1. Probe the cache at `namespace:key`. Any non-undefined value is a HIT.\n * 2. On MISS, delegate to `backing.get(key)`.\n * 3. If the backing returned a defined value AND a rule matches the\n * `{ key, value }` context, populate the cache with `rule.ttl * 1000` ms.\n * Negative caching (caching `undefined`) is intentionally not supported.\n *\n * Write semantics (`set` / `delete`) follow the \"cache is advisory\" policy\n * documented in `docs/plans/2026-05-13-store-cache-design.md` (Write path and\n * error policy):\n * - Backing first. If `backing.set`/`backing.delete` throws, the wrapper\n * throws and the cache layer is never touched. The backing is the source\n * of truth and its failures must surface to the caller.\n * - Cache best-effort. After a successful backing write, attempt the cache\n * write. A throwing cache layer is logged via `logger.warn` and swallowed\n * so the wrapper still resolves successfully — the next read will MISS\n * and re-populate. Failed cache deletes leave a stale entry that serves\n * until TTL; the warning lets operators react.\n */\nexport function wrapStoreWithCache(\n backing: Store.Instance,\n opts: WrappedStoreOptions,\n): WrappedStoreInstance {\n const { cacheConfig, cacheStore, namespace, logger, storeId, collector } =\n opts;\n\n // Cache observability. Each wrapped `get` resolves to a HIT or MISS;\n // the wrapper emits a `FlowState` on the collector so observers can\n // record cache metadata without coupling to wrapper internals. When\n // `collector` is absent (unit-test path), reporting is skipped.\n const reportCacheStatus = (key: string, status: 'hit' | 'miss'): void => {\n if (!collector) return;\n const state = buildBaseState(collector, {\n stepId: `store.${storeId}`,\n stepType: 'store',\n phase: 'in',\n eventId: '',\n now: Date.now(),\n });\n state.meta = {\n op: 'cache',\n cached: status === 'hit',\n status,\n key,\n };\n emitStep(collector, state);\n };\n\n // Closure-scoped counters. Mutated directly at each path; the public\n // `counters` accessor on the returned instance returns a fresh shallow copy\n // so external consumers cannot mutate internal state.\n const counters: WrappedStoreCounters = {\n hits: 0,\n misses: 0,\n populates: 0,\n writes: 0,\n deletes: 0,\n inflight_dedups: 0,\n };\n\n // Pre-compile each rule's matcher once at wrap time. Rules without a `match`\n // clause are treated as always-matching, mirroring the EventCacheRule\n // helpers in `packages/core/src/cache.ts`.\n const compiledRules: CompiledStoreCacheRule[] = cacheConfig.rules.map(\n (rule) => ({\n match: rule.match ? compileMatcher(rule.match) : () => true,\n ttl: rule.ttl,\n }),\n );\n\n const prefixed = (key: string): string => `${namespace}:${key}`;\n\n function findMatchingRule(\n key: string,\n value: unknown,\n ): CompiledStoreCacheRule | undefined {\n // Store-cache context shape is `{ key, value? }` — no `ingest`. The value\n // is omitted when the caller has not yet read from the backing (e.g.\n // future write-path callers).\n const ctx: Record<string, unknown> =\n value === undefined ? { key } : { key, value };\n return compiledRules.find((r) => r.match(ctx));\n }\n\n // Closure-scoped in-flight registry: N concurrent gets on the same cold key\n // share one backing call. Keyed by the namespaced cache key so distinct\n // backing keys never collide. The entry is removed in `finally` so a\n // settled (resolved or rejected) Promise never lingers — a subsequent get\n // either hits the now-populated cache or retries the backing.\n const inFlight = new Map<string, Promise<unknown>>();\n\n return {\n type: backing.type,\n config: backing.config,\n setup: backing.setup,\n\n // Snapshot accessor. Returning a fresh shallow copy on every read keeps\n // the internal counter object un-aliased: consumers that store, diff, or\n // serialize the snapshot cannot inadvertently mutate state.\n get counters(): WrappedStoreCounters {\n return { ...counters };\n },\n\n async get(key: string): Promise<unknown> {\n const ns = prefixed(key);\n const cached = await cacheStore.get(ns);\n if (cached !== undefined) {\n counters.hits++;\n reportCacheStatus(key, 'hit');\n return cached;\n }\n\n // Single-flight: if another caller is already fetching this key, join\n // their Promise rather than starting a second backing call.\n const existing = inFlight.get(ns);\n if (existing) {\n counters.inflight_dedups++;\n reportCacheStatus(key, 'hit');\n return existing;\n }\n\n // This caller drives the backing fetch — count the MISS once here so\n // joined callers above are not double-counted as misses too.\n counters.misses++;\n reportCacheStatus(key, 'miss');\n\n const promise = (async () => {\n try {\n const value = await backing.get(key);\n if (value === undefined) return undefined;\n\n const rule = findMatchingRule(key, value);\n if (rule) {\n // Best-effort cache populate. Mirrors the Task 8 write-path\n // policy: backing has already returned, so a throwing cache layer\n // must not surface as an unhandled rejection on the shared\n // Promise that other concurrent callers are awaiting.\n try {\n // `cache.ttl` is documented in seconds; the underlying cache\n // store accepts ms. Multiply once at the boundary to keep the\n // rest of the pipeline consistent with EventCache semantics.\n await cacheStore.set(ns, value, rule.ttl * 1000);\n // Count the populate only after the cache write resolves so a\n // failed populate (logged below) does not inflate the counter.\n counters.populates++;\n } catch (error) {\n warnCacheFailure('set', key, error);\n }\n }\n return value;\n } finally {\n // Always release the slot — on resolve so the next read hits the\n // now-populated cache, on reject so a transient backing failure\n // doesn't freeze the key forever behind a dead Promise.\n inFlight.delete(ns);\n }\n })();\n inFlight.set(ns, promise);\n return promise;\n },\n\n async set(key: string, value: unknown, ttl?: number): Promise<void> {\n // Count every set the moment the wrapper is entered, before any IO.\n // The counter reflects intent (how many writes the wrapper has been\n // asked to perform), independent of backing or cache success.\n counters.writes++;\n\n // Backing first. A throw here propagates: backing is the source of\n // truth, callers must see real write failures.\n await backing.set(key, value, ttl);\n\n const rule = findMatchingRule(key, value);\n if (!rule) return;\n\n // Best-effort cache populate. Wrap only the cache-side call: backing\n // errors above have already propagated, so this try/catch is scoped to\n // the advisory layer.\n try {\n await cacheStore.set(prefixed(key), value, rule.ttl * 1000);\n } catch (error) {\n warnCacheFailure('set', key, error);\n }\n },\n\n async delete(key: string): Promise<void> {\n // Mirrors `writes`: count intent at entry, before backing or cache IO.\n counters.deletes++;\n\n // Backing first; same propagation rules as `set`.\n await backing.delete(key);\n\n try {\n await cacheStore.delete(prefixed(key));\n } catch (error) {\n warnCacheFailure('delete', key, error);\n }\n },\n };\n\n function warnCacheFailure(\n op: 'set' | 'delete',\n key: string,\n error: unknown,\n ): void {\n const message = `store-cache(${storeId}): cache ${op} failed for \"${key}\"; backing succeeded, continuing`;\n if (logger) {\n logger.warn(message, { error });\n } else {\n // Defensive fallback so unit tests that do not thread a logger still\n // surface the failure rather than swallowing it silently. Production\n // call sites in `store.ts` always pass `collector.logger`.\n // eslint-disable-next-line no-console\n console.warn(message, error);\n }\n }\n}\n","import type { Collector, Source, WalkerOS, Elb } from '@walkeros/core';\nimport { createPushResult } from './destination';\n\n/**\n * Creates the default ELB source.\n * Routes between collector.push and collector.command based on input.\n * Provides backward-compatible flexible argument interface.\n *\n * @param collector - The walkerOS collector instance\n * @returns ELB source instance\n */\nexport function createElbSource(\n collector: Collector.Instance,\n): Source.Instance {\n return {\n type: 'elb',\n config: {},\n\n // The push function is the elb() interface users interact with\n push: async (\n eventOrCommand?: unknown,\n data?: unknown,\n context?: unknown,\n nested?: WalkerOS.Entities,\n custom?: WalkerOS.Properties,\n ): Promise<Elb.PushResult> => {\n // Detect walker commands\n if (\n typeof eventOrCommand === 'string' &&\n eventOrCommand.startsWith('walker ')\n ) {\n const command = eventOrCommand.replace('walker ', '');\n return collector.command(command, data);\n }\n\n // Build event object\n let event: WalkerOS.DeepPartialEvent;\n\n if (typeof eventOrCommand === 'string') {\n // Convert string to object: elb('page view', { title: 'Home' })\n event = { name: eventOrCommand };\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = data as WalkerOS.Properties;\n }\n } else if (eventOrCommand && typeof eventOrCommand === 'object') {\n // Use object directly: elb({ name: 'page view', data: {...} })\n event = eventOrCommand as WalkerOS.DeepPartialEvent;\n // Merge additional data if provided\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n event.data = {\n ...(event.data || {}),\n ...(data as WalkerOS.Properties),\n };\n }\n } else {\n // Invalid input\n return createPushResult({ ok: false });\n }\n\n // Add optional properties if provided\n if (context && typeof context === 'object') {\n event.context = context as WalkerOS.OrderedProperties;\n }\n if (nested && Array.isArray(nested)) {\n event.nested = nested;\n }\n if (custom && typeof custom === 'object') {\n event.custom = custom as WalkerOS.Properties;\n }\n\n // Call collector.push with event object\n return collector.push(event);\n },\n };\n}\n","import type { Collector, Elb } from '@walkeros/core';\nimport type { StartFlow } from './types';\nimport { collector } from './collector';\nimport { createElbSource } from './elb';\nimport { initSources } from './source';\n\nexport async function startFlow<ElbPush extends Elb.Fn = Elb.Fn>(\n initConfig?: Collector.InitConfig,\n): Promise<StartFlow<ElbPush>> {\n initConfig = initConfig || {};\n const instance = await collector(initConfig);\n\n // Create and register ELB source first\n const elbSource = createElbSource(instance);\n instance.sources.elb = elbSource;\n\n // Now initialize other sources with ELB source available\n await initSources(instance, initConfig.sources || {});\n\n const { consent, user, globals, custom } = initConfig;\n\n if (consent) await instance.command('consent', consent);\n if (user) await instance.command('user', user);\n if (globals) Object.assign(instance.globals, globals);\n if (custom) Object.assign(instance.custom, custom);\n\n if (instance.config.run) await instance.command('run');\n\n // Determine the primary elb:\n // 1. Use explicitly marked primary source\n // 2. Use first non-elb source if any exist\n // 3. Fallback to ELB source\n let primaryElb: Elb.Fn = elbSource.push as Elb.Fn;\n\n const sources = Object.values(instance.sources).filter(\n (source) => source.type !== 'elb',\n );\n\n // First, check for explicitly marked primary source\n const markedPrimary = sources.find(\n (source) => (source.config as { primary?: boolean }).primary,\n );\n\n if (markedPrimary) {\n primaryElb = markedPrimary.push as Elb.Fn;\n } else if (sources.length > 0) {\n // Use first source as default\n primaryElb = sources[0].push as Elb.Fn;\n }\n\n return {\n collector: instance,\n elb: primaryElb as ElbPush,\n };\n}\n","import type { Simulation } from '@walkeros/core';\n\ninterface WrapResult {\n /** Env with tracked paths wrapped by recording functions */\n wrappedEnv: Record<string, unknown>;\n /** Mutable array — calls are pushed here during step execution */\n calls: Simulation.Call[];\n}\n\nfunction deepClone(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') return obj;\n if (Array.isArray(obj)) return obj.map(deepClone);\n const clone: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj as Record<string, unknown>)) {\n clone[key] = typeof value === 'function' ? value : deepClone(value);\n }\n return clone;\n}\n\n/**\n * Wrap tracked paths in a destination env with recording wrappers.\n *\n * The env object must include a `simulation: string[]` declaring which\n * dot-paths to intercept. Returns a cloned env (without `simulation`)\n * where those paths record every call into the `calls` array.\n */\nexport function wrapEnv(\n env: Record<string, unknown> & { simulation: string[] },\n): WrapResult {\n const calls: Simulation.Call[] = [];\n const { simulation, ...rest } = env;\n\n // Deep clone the env to avoid mutating the original (preserves functions)\n const wrappedEnv = deepClone(rest) as Record<string, unknown>;\n\n for (const rawPath of simulation) {\n // Strip optional \"call:\" prefix\n const path = rawPath.startsWith('call:') ? rawPath.slice(5) : rawPath;\n const segments = path.split('.');\n\n // Navigate to the parent\n let target: Record<string, unknown> = wrappedEnv;\n for (let i = 0; i < segments.length - 1; i++) {\n if (target[segments[i]] == null) break;\n target = target[segments[i]] as Record<string, unknown>;\n }\n\n const leaf = segments[segments.length - 1];\n if (target == null || !(leaf in target)) continue;\n\n const original = target[leaf];\n\n if (typeof original === 'function') {\n target[leaf] = function (this: unknown, ...args: unknown[]) {\n calls.push({ fn: path, args, ts: Date.now() });\n return original.apply(this, args);\n };\n }\n }\n\n return { wrappedEnv, calls };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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a,YAAY;AAClC,aAAO,IAAI,IAAI,YAA4B,MAAiB;AAC1D,cAAM,KAAK,EAAE,IAAI,MAAM,MAAM,IAAI,KAAK,IAAI,EAAE,CAAC;AAC7C,eAAO,SAAS,MAAM,MAAM,IAAI;AAAA,MAClC;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,YAAY,MAAM;AAC7B;","names":["collector","import_core","import_core","import_core","collector","import_core","import_core","collector","require","import_core","import_core","collector","collector","initTransformers","collector","collector","on","option","collector","event","isInitialized","batchState","destIdResolved","destStatus","import_core","collector","collector","import_core","collector","import_core","collector","import_core","import_core","collector","collector","initStores","collector","collector","clone"]}