@walkeros/core 4.1.1-next-1779485810490 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -220,6 +220,74 @@ interface Ingest {
220
220
  /** Create a fresh Ingest for a new pipeline invocation. */
221
221
  declare function createIngest(sourceId: string): Ingest;
222
222
 
223
+ /**
224
+ * FlowState is the canonical observation record emitted at each hop in a
225
+ * walkerOS pipeline. Telemetry helpers populate one of these per (step,
226
+ * phase) tuple and pass it to a user-supplied emit callback. The shape is
227
+ * stable across step kinds (source, transformer, collector, destination,
228
+ * store) so a single observer can correlate work across the pipeline.
229
+ *
230
+ * Optional fields are populated only when meaningful for the (step, phase)
231
+ * pair, or when the telemetry options explicitly opt in (e.g. trace level
232
+ * for inEvent/outEvent).
233
+ */
234
+ type FlowStatePhase = 'init' | 'in' | 'out' | 'error' | 'skip' | 'flush';
235
+ type FlowStepType = 'source' | 'transformer' | 'collector' | 'destination' | 'store';
236
+ interface FlowStateBatch {
237
+ size: number;
238
+ index: number;
239
+ }
240
+ interface FlowState {
241
+ /** The flow this state belongs to. */
242
+ flowId: string;
243
+ /** Step identifier, e.g. 'destination.gtag', 'transformer.consent', 'collector.push'. */
244
+ stepId: string;
245
+ stepType: FlowStepType;
246
+ phase: FlowStatePhase;
247
+ /** W3C span-id of the originating WalkerOS.Event. Sourced from event.id; never synthesized. */
248
+ eventId: string;
249
+ /** ISO 8601 timestamp. */
250
+ timestamp: string;
251
+ /** Milliseconds since the runtime's startedAt origin. Monotonic. */
252
+ elapsedMs: number;
253
+ /** Wall-clock duration of this step, if measured (typically only on 'out'). */
254
+ durationMs?: number;
255
+ /** Inbound walker event for this hop. Only populated when level === 'trace' or includeIn === true. */
256
+ inEvent?: unknown;
257
+ /** Outbound walker event/payload for this hop. Only populated when level === 'trace' or includeOut === true. */
258
+ outEvent?: unknown;
259
+ /** Error info when phase === 'error'. */
260
+ error?: {
261
+ name?: string;
262
+ message: string;
263
+ };
264
+ /** The mapping rule that matched, when one matched. */
265
+ mappingKey?: string;
266
+ /** Contract rule that matched, if any. */
267
+ contractRule?: string;
268
+ /** Consent gate snapshot at hop time. */
269
+ consent?: Record<string, boolean>;
270
+ /** Consent state actually applied (after policy resolution). */
271
+ consentApplied?: Record<string, boolean>;
272
+ /** W3C 16-hex span-id of the child branch for `many` fan-out. */
273
+ branchId?: string;
274
+ /** For phase === 'flush', the batch size + entry index. */
275
+ batch?: FlowStateBatch;
276
+ /** Discriminator when phase === 'skip'. */
277
+ skipReason?: 'consent' | 'cache_hit' | 'sampled_out' | 'disabled' | 'unknown';
278
+ /** Free-form metadata: store key/value, cached: true, etc. */
279
+ meta?: Record<string, unknown>;
280
+ }
281
+
282
+ /**
283
+ * Pipeline observation channel. Observers receive a FlowState record per
284
+ * step phase (init, in, out, error, skip, flush) and run synchronously in
285
+ * the collector's emit loop. They must not throw; emitStep swallows
286
+ * thrown values defensively so a slow or buggy observer cannot crash the
287
+ * pipeline. Observers must not perform synchronous IO.
288
+ */
289
+ type ObserverFn = (state: FlowState) => void;
290
+
223
291
  /** Identifies which kind of step a stepId belongs to. */
224
292
  type StepKind = 'collector' | 'source' | 'transformer' | 'destination';
225
293
  /**
@@ -404,6 +472,15 @@ interface Instance$6 {
404
472
  stores: Stores$1;
405
473
  globals: Properties;
406
474
  hooks: Functions;
475
+ /**
476
+ * First-class observation channel. The runtime self-emits FlowState
477
+ * records at canonical step sites (collector.push, destination.push,
478
+ * destination.init, destination.pushBatch, destination consent skip,
479
+ * transformer.push, store.get/set/delete, store cache HIT/MISS).
480
+ * Observers run synchronously inside emitStep; thrown values are
481
+ * swallowed. Subscribers add/remove via the standard Set API.
482
+ */
483
+ observers: Set<ObserverFn>;
407
484
  logger: Instance$3;
408
485
  on: OnConfig;
409
486
  queue: Events;
@@ -1290,6 +1367,29 @@ declare namespace Flow {
1290
1367
  * Consumed by the CLI bundler at build time.
1291
1368
  */
1292
1369
  bundle?: Bundle;
1370
+ /**
1371
+ * Observability configuration. Controls whether the runtime emits
1372
+ * FlowState records to a remote observer, and at what verbosity.
1373
+ *
1374
+ * When omitted, the runtime defaults to `{ level: 'standard' }` for
1375
+ * managed deployments. When `level: 'off'`, the bundle ships no
1376
+ * telemetry plumbing at all.
1377
+ */
1378
+ observe?: Observe;
1379
+ }
1380
+ /**
1381
+ * Observability configuration block.
1382
+ *
1383
+ * - `off` disables telemetry entirely (no hooks installed, no fetch).
1384
+ * - `standard` emits structural FlowState records (no inEvent/outEvent).
1385
+ * - `trace` emits full payloads on every hop. Use only for short debug
1386
+ * windows; the operator can also flip the deployment's `trace_until`
1387
+ * timestamp at runtime to enable trace without a redeploy.
1388
+ */
1389
+ interface Observe {
1390
+ level?: 'off' | 'standard' | 'trace';
1391
+ /** Deterministic sample fraction in [0, 1]. Defaults to 1. */
1392
+ sample?: number;
1293
1393
  }
1294
1394
  /**
1295
1395
  * Reusable values referenced via `$var.name` (with optional deep paths).
@@ -3406,18 +3506,193 @@ declare class FatalError extends Error {
3406
3506
  * A utility function that wraps a function with hooks.
3407
3507
  *
3408
3508
  * Pre/post hooks are user-supplied and may throw. A throwing hook must not
3409
- * crash the surrounding pipeline on failure, fall back to calling the
3509
+ * crash the surrounding pipeline. On failure, fall back to calling the
3410
3510
  * original function (pre-hook) or keep the original result (post-hook).
3411
3511
  *
3412
- * @template P, R
3512
+ * The generic `F` preserves the exact call shape of `fn`, including named
3513
+ * parameters and overloaded interfaces, so call sites can assign the result
3514
+ * to the same interface slot without a cast.
3515
+ *
3516
+ * @template F The exact function type being wrapped.
3413
3517
  * @param fn The function to wrap.
3414
3518
  * @param name The name of the function.
3415
3519
  * @param hooks The hooks to use.
3416
3520
  * @param logger Optional logger for hook failure warnings. Falls back to
3417
3521
  * `console.warn` when not provided.
3418
- * @returns The wrapped function.
3522
+ * @returns The wrapped function with the same call shape as `fn`.
3523
+ */
3524
+ declare function useHooks<F extends AnyFunction$1>(fn: F, name: string, hooks: Functions, logger?: Instance$3): F;
3525
+
3526
+ /**
3527
+ * Telemetry level. Off disables emission entirely. Standard projects
3528
+ * structural state without inEvent or outEvent payloads (unless explicitly
3529
+ * opted in). Trace emits full payloads on every hop.
3530
+ */
3531
+ type TelemetryLevel = 'off' | 'standard' | 'trace';
3532
+ /**
3533
+ * Options that shape the telemetry projection strategy. Defaults are chosen
3534
+ * so a caller can pass `{ flowId }` and get sensible behavior.
3535
+ */
3536
+ interface TelemetryOptions {
3537
+ /** Required flow identifier; observers may use this for cross-flow correlation. */
3538
+ flowId: string;
3539
+ /** Verbosity. Defaults to 'standard'. */
3540
+ level?: TelemetryLevel;
3541
+ /** Force-include the inbound event regardless of level. */
3542
+ includeIn?: boolean;
3543
+ /** Force-include the outbound event regardless of level. */
3544
+ includeOut?: boolean;
3545
+ /** Force-include the matched mapping key (only meaningful for transformers/destinations). */
3546
+ includeMappingKey?: boolean;
3547
+ /**
3548
+ * Fraction of events to emit, between 0 and 1. Deterministic by eventId:
3549
+ * the same eventId always falls on the same side of the threshold so
3550
+ * paired in/out states either both emit or both drop.
3551
+ */
3552
+ sample?: number;
3553
+ }
3554
+ type EmitFn = (state: FlowState) => void;
3555
+ /**
3556
+ * Optional supplier form. When passed instead of static `TelemetryOptions`,
3557
+ * the observer evaluates the supplier on every emit so toggle-style runtime
3558
+ * overrides (e.g. `WALKEROS_TRACE_UNTIL`) reach the projection without
3559
+ * rebuilding the observer.
3560
+ */
3561
+ type TelemetryOptionsSupplier = () => TelemetryOptions | null;
3562
+ /**
3563
+ * Build a telemetry observer that projects FlowState records according to
3564
+ * level/sample/include flags and forwards them to `emit`. The observer is
3565
+ * synchronous, never throws (a throwing emit is swallowed), and does no
3566
+ * IO of its own. Designed to be added to `collector.observers` so the
3567
+ * runtime self-emission loop drives it.
3568
+ *
3569
+ * Accepts either a static `TelemetryOptions` value or a supplier
3570
+ * `() => TelemetryOptions | null`. With a supplier, every emit reads the
3571
+ * current opts so toggles such as `WALKEROS_TRACE_UNTIL` reach the
3572
+ * projection without rebuilding the observer. A supplier returning `null`
3573
+ * suppresses the emit (telemetry off).
3574
+ */
3575
+ declare function createTelemetryObserver(emit: EmitFn, optsOrSupplier: TelemetryOptions | TelemetryOptionsSupplier): ObserverFn;
3576
+ /**
3577
+ * Convenience export: the internal sampling predicate so callers (and
3578
+ * tests) can verify the deterministic bucketing without importing the
3579
+ * private FNV-1a helper.
3580
+ */
3581
+ declare function isSampled(eventId: string, sample: number): boolean;
3582
+
3583
+ /**
3584
+ * Runtime telemetry resolver.
3585
+ *
3586
+ * Converts a flow-side `Flow.Config.observe` block plus a runtime override
3587
+ * (the `WALKEROS_TRACE_UNTIL` env var) into a concrete `TelemetryOptions`
3588
+ * the collector hooks installer can consume.
3589
+ *
3590
+ * Resolution order (highest priority first):
3591
+ * 1. `WALKEROS_TRACE_UNTIL` env var, if present and parses to a future ISO
3592
+ * timestamp -> force level=trace, sample=1, include in/out payloads.
3593
+ * 2. The `observe` block from `flow.config?.observe`.
3594
+ * 3. A tier default of `{ level: 'standard' }`.
3595
+ *
3596
+ * The full poll-and-update plumbing that lets an operator flip
3597
+ * `WALKEROS_TRACE_UNTIL` without redeploying the container is intentionally
3598
+ * stubbed at the env-var seam: the deployment record's `trace_until` is
3599
+ * written by the app, but a sidecar/heartbeat that propagates it into the
3600
+ * container is out of scope for this phase. For now an operator sets the
3601
+ * env var directly, or the next deploy picks it up at boot.
3602
+ */
3603
+
3604
+ interface ResolveTelemetryInput {
3605
+ flowId: string;
3606
+ /** From `flow.config?.observe`. May be undefined. */
3607
+ observe?: {
3608
+ level?: 'off' | 'standard' | 'trace';
3609
+ sample?: number;
3610
+ };
3611
+ /** Snapshot of `process.env` (or any equivalent). Test seam. */
3612
+ env?: Record<string, string | undefined>;
3613
+ /** Clock seam for tests. Defaults to `Date.now()`. */
3614
+ now?: () => number;
3615
+ }
3616
+ /**
3617
+ * Returns `TelemetryOptions` ready to pass to `createTelemetryObserver`,
3618
+ * or `null` if telemetry is disabled (`level === 'off'` with no trace
3619
+ * override). Callers should skip observer installation when this returns
3620
+ * null.
3621
+ */
3622
+ declare function resolveTelemetryOptions(input: ResolveTelemetryInput): TelemetryOptions | null;
3623
+
3624
+ /**
3625
+ * Synchronously fans out a FlowState record to every registered observer
3626
+ * on the collector. Each call is wrapped in try/catch so a misbehaving
3627
+ * observer cannot crash the runtime; observers are advisory and must not
3628
+ * affect pipeline outcomes.
3629
+ *
3630
+ * Iterates a snapshot of the observer set so an observer adding or removing
3631
+ * another observer during the emit does not re-enter or skip in the same
3632
+ * pass. The early return on an empty set keeps the zero-observer hot path
3633
+ * allocation-free.
3634
+ */
3635
+ declare function emitStep(collector: Instance$6, state: FlowState): void;
3636
+
3637
+ /**
3638
+ * Batched FlowState poster.
3639
+ *
3640
+ * Buffers FlowState records and flushes them to an HTTP endpoint either when
3641
+ * `batchMs` elapses since the first queued record, or when `batchSize` is
3642
+ * reached. Returns the emit callback that `createTelemetryObserver` consumes.
3643
+ *
3644
+ * Errors from the underlying fetch are swallowed (or routed through the
3645
+ * optional `onError` callback) so a transient observer outage cannot crash
3646
+ * the runtime.
3647
+ *
3648
+ * Uses the global `fetch` so the same primitive works in Node 18+, browsers,
3649
+ * and Edge runtimes. Tests may inject a stub via `opts.fetch`.
3650
+ */
3651
+
3652
+ /**
3653
+ * Minimum HTTP response surface the poster touches. Anything that exposes
3654
+ * `ok` and `status` works. Decoupling from the DOM `Response` type lets the
3655
+ * helper run in Edge, browser, and Node-only test environments without
3656
+ * requiring `lib: dom` or a polyfill.
3657
+ */
3658
+ interface PosterResponse {
3659
+ ok: boolean;
3660
+ status: number;
3661
+ }
3662
+ /**
3663
+ * Minimum fetch surface the poster needs. A subset of `typeof fetch` that
3664
+ * lets test harnesses pass a plain async function without dragging in the
3665
+ * Response/Request DOM types.
3666
+ */
3667
+ type PosterFetch = (url: string, init: {
3668
+ method: string;
3669
+ headers: Record<string, string>;
3670
+ body: string;
3671
+ }) => Promise<PosterResponse>;
3672
+ interface BatchedPosterOptions {
3673
+ /** Absolute HTTP endpoint URL. POST with JSON array body. */
3674
+ url: string;
3675
+ /** Bearer token sent in the `Authorization` header. */
3676
+ token: string;
3677
+ /** Max time to wait before flushing the current batch. Default 50 ms. */
3678
+ batchMs?: number;
3679
+ /** Max records per batch. When reached, flushes immediately. Default 50. */
3680
+ batchSize?: number;
3681
+ /** Test seam. Defaults to the global `fetch`. */
3682
+ fetch?: PosterFetch;
3683
+ /** Called when the underlying POST rejects. Defaults to swallowing. */
3684
+ onError?: (err: unknown) => void;
3685
+ }
3686
+ /**
3687
+ * Build a batched emit callback. The returned function is synchronous, never
3688
+ * throws, and schedules an async flush in the background.
3689
+ *
3690
+ * Concurrency model: a single in-memory buffer plus a single pending timer.
3691
+ * When the timer fires (or `batchSize` is hit) the buffer is moved into a
3692
+ * local variable and reset, then POSTed. New records arriving during the in-
3693
+ * flight POST land in the next batch.
3419
3694
  */
3420
- declare function useHooks<P extends unknown[], R>(fn: (...args: P) => R, name: string, hooks: Functions, logger?: Instance$3): (...args: P) => R;
3695
+ declare function createBatchedPoster(opts: BatchedPosterOptions): (state: FlowState) => void;
3421
3696
 
3422
3697
  /**
3423
3698
  * Parses a user agent string to extract browser, OS, and device information.
@@ -3714,4 +3989,4 @@ declare const REF_STORE: RegExp;
3714
3989
  declare const REF_SECRET: RegExp;
3715
3990
  declare const REF_CODE_PREFIX = "$code:";
3716
3991
 
3717
- export { cache as Cache, type CacheResult, type ClickIdEntry, collector as Collector, type CompiledCache, Const, context as Context, type Debounced, destination as Destination, type DestroyContext, type DestroyFn, type DroppedCounters, ENV_MARKER_PREFIX, elb as Elb, type ExampleSummary, FatalError, Flow, type FlowConfigResolver, hint as Hint, hooks as Hooks, type Ingest, type IngestMeta, type JsonSchema, Level, lifecycle as Lifecycle, type LifecycleContext, logger as Logger, mapping as Mapping, type MarketingParameters, matcher as Matcher, type MockLogger, on as On, REF_CODE_PREFIX, REF_CONTRACT, REF_ENV, REF_FLOW, REF_SECRET, REF_STORE, REF_VAR_FULL, REF_VAR_INLINE, request as Request, type ResolveOptions, type RespondFn, type RespondOptions, STEP_OPERATIVE_FIELDS, type ScheduleOptions, type SendDataValue, type SendHeaders, type SendResponse, type SetupFn, simulation as Simulation, source as Source, type StepEntryErrorCode, type StepEntryValidation, type StepKind, type StorageType, store as Store, transformer as Transformer, trigger as Trigger, type Validate, type ValidateEvents, walkeros as WalkerOS, type WalkerOSPackage, type WalkerOSPackageInfo, type WalkerOSPackageMeta, anonymizeIP, applyUpdate, assign, branch, buildCacheContext, castToProperty, castValue, checkCache, clone, compileCache, compileMatcher, createDestination, createEvent, createIngest, createLogger, createMockContext, createMockLogger, createRespond, debounce, deepMerge, defaultClickIds, deleteByPath, fetchPackage, fetchPackageSchema, filterValues, flattenIncludeSections, formatOut, getBrowser, getBrowserVersion, getByPath, getDeviceType, getEvent, getFlowSettings, getGrantedConsent, getHeaders, getId, getMappingEvent, getMappingValue, getMarketingParameters, getNextSteps, getOS, getOSVersion, getPlatform, getSpanId, isArguments, isArray, isBoolean, isCommand, isDefined, isElementOrDocument, isFunction, isNumber, isObject, isPathStepEntry, isPropertyType, isSameType, isString, mcpError, mcpResult, mergeContractSchemas, mergeMappingRule, mockEnv, packageNameToVariable, parseUserAgent, processEventMapping, requestToData, requestToParameter, resolveContracts, resolveSetup, setByPath, stepId, storeCache, throttle, throwError, transformData, traverseEnv, trim, tryCatch, tryCatchAsync, useHooks, validateStepEntry, walkPath, wrapCondition, wrapFn, wrapValidate };
3992
+ export { type BatchedPosterOptions, cache as Cache, type CacheResult, type ClickIdEntry, collector as Collector, type CompiledCache, Const, context as Context, type Debounced, destination as Destination, type DestroyContext, type DestroyFn, type DroppedCounters, ENV_MARKER_PREFIX, elb as Elb, type EmitFn, type ExampleSummary, FatalError, Flow, type FlowConfigResolver, type FlowState, type FlowStateBatch, type FlowStatePhase, type FlowStepType, hint as Hint, hooks as Hooks, type Ingest, type IngestMeta, type JsonSchema, Level, lifecycle as Lifecycle, type LifecycleContext, logger as Logger, mapping as Mapping, type MarketingParameters, matcher as Matcher, type MockLogger, type ObserverFn, on as On, type PosterFetch, type PosterResponse, REF_CODE_PREFIX, REF_CONTRACT, REF_ENV, REF_FLOW, REF_SECRET, REF_STORE, REF_VAR_FULL, REF_VAR_INLINE, request as Request, type ResolveOptions, type RespondFn, type RespondOptions, STEP_OPERATIVE_FIELDS, type ScheduleOptions, type SendDataValue, type SendHeaders, type SendResponse, type SetupFn, simulation as Simulation, source as Source, type StepEntryErrorCode, type StepEntryValidation, type StepKind, type StorageType, store as Store, type TelemetryLevel, type TelemetryOptions, type TelemetryOptionsSupplier, transformer as Transformer, trigger as Trigger, type Validate, type ValidateEvents, walkeros as WalkerOS, type WalkerOSPackage, type WalkerOSPackageInfo, type WalkerOSPackageMeta, anonymizeIP, applyUpdate, assign, branch, buildCacheContext, castToProperty, castValue, checkCache, clone, compileCache, compileMatcher, createBatchedPoster, createDestination, createEvent, createIngest, createLogger, createMockContext, createMockLogger, createRespond, createTelemetryObserver, debounce, deepMerge, defaultClickIds, deleteByPath, emitStep, fetchPackage, fetchPackageSchema, filterValues, flattenIncludeSections, formatOut, getBrowser, getBrowserVersion, getByPath, getDeviceType, getEvent, getFlowSettings, getGrantedConsent, getHeaders, getId, getMappingEvent, getMappingValue, getMarketingParameters, getNextSteps, getOS, getOSVersion, getPlatform, getSpanId, isArguments, isArray, isBoolean, isCommand, isDefined, isElementOrDocument, isFunction, isNumber, isObject, isPathStepEntry, isPropertyType, isSameType, isSampled, isString, mcpError, mcpResult, mergeContractSchemas, mergeMappingRule, mockEnv, packageNameToVariable, parseUserAgent, processEventMapping, requestToData, requestToParameter, resolveContracts, resolveSetup, resolveTelemetryOptions, setByPath, stepId, storeCache, throttle, throwError, transformData, traverseEnv, trim, tryCatch, tryCatchAsync, useHooks, validateStepEntry, walkPath, wrapCondition, wrapFn, wrapValidate };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,a=(e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})},i={};a(i,{Cache:()=>s,Collector:()=>c,Const:()=>P,Context:()=>u,Destination:()=>f,ENV_MARKER_PREFIX:()=>X,Elb:()=>d,FatalError:()=>Be,Hint:()=>N,Hooks:()=>m,Level:()=>y,Lifecycle:()=>A,Logger:()=>g,Mapping:()=>h,Matcher:()=>C,On:()=>v,REF_CODE_PREFIX:()=>J,REF_CONTRACT:()=>W,REF_ENV:()=>H,REF_FLOW:()=>B,REF_SECRET:()=>K,REF_STORE:()=>q,REF_VAR_FULL:()=>U,REF_VAR_INLINE:()=>Z,Request:()=>k,STEP_OPERATIVE_FIELDS:()=>Lt,Simulation:()=>_,Source:()=>$,Store:()=>x,Transformer:()=>b,Trigger:()=>S,WalkerOS:()=>E,anonymizeIP:()=>I,applyUpdate:()=>Vt,assign:()=>ae,branch:()=>R,buildCacheContext:()=>Mt,castToProperty:()=>Ze,castValue:()=>je,checkCache:()=>zt,clone:()=>he,compileCache:()=>Ft,compileMatcher:()=>_t,createDestination:()=>Oe,createEvent:()=>Ee,createIngest:()=>T,createLogger:()=>De,createMockContext:()=>nt,createMockLogger:()=>tt,createRespond:()=>Et,debounce:()=>Re,deepMerge:()=>Se,defaultClickIds:()=>Ne,deleteByPath:()=>we,fetchPackage:()=>jt,fetchPackageSchema:()=>Ot,filterValues:()=>Ue,flattenIncludeSections:()=>$e,formatOut:()=>qt,getBrowser:()=>ft,getBrowserVersion:()=>pt,getByPath:()=>ve,getDeviceType:()=>gt,getEvent:()=>_e,getFlowSettings:()=>ne,getGrantedConsent:()=>xe,getHeaders:()=>it,getId:()=>Ce,getMappingEvent:()=>qe,getMappingValue:()=>Ke,getMarketingParameters:()=>Pe,getNextSteps:()=>Rt,getOS:()=>dt,getOSVersion:()=>mt,getPlatform:()=>re,getSpanId:()=>Ae,isArguments:()=>ie,isArray:()=>se,isBoolean:()=>ce,isCommand:()=>le,isDefined:()=>ue,isElementOrDocument:()=>fe,isFunction:()=>pe,isNumber:()=>de,isObject:()=>me,isPathStepEntry:()=>Bt,isPropertyType:()=>Le,isSameType:()=>ge,isString:()=>ye,mcpError:()=>At,mcpResult:()=>St,mergeContractSchemas:()=>D,mergeMappingRule:()=>Ye,mockEnv:()=>Qe,packageNameToVariable:()=>te,parseUserAgent:()=>ut,processEventMapping:()=>Ge,requestToData:()=>rt,requestToParameter:()=>ot,resolveContracts:()=>z,resolveSetup:()=>st,setByPath:()=>be,stepId:()=>l,storeCache:()=>Dt,throttle:()=>Ie,throwError:()=>M,transformData:()=>at,traverseEnv:()=>et,trim:()=>ct,tryCatch:()=>He,tryCatchAsync:()=>We,useHooks:()=>lt,validateStepEntry:()=>Wt,walkPath:()=>Q,wrapCondition:()=>ht,wrapFn:()=>vt,wrapValidate:()=>bt}),module.exports=(e=i,((e,a,i,s)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let c of r(a))o.call(e,c)||c===i||t(e,c,{get:()=>a[c],enumerable:!(s=n(a,c))||s.enumerable});return e})(t({},"__esModule",{value:!0}),e));var s={},c={};function l(e,t){if("collector"===e)return"collector";if(!t)throw new Error(`stepId(${e}) requires an id`);return`${e}.${t}`}a(c,{stepId:()=>l});var u={},f={};function p(e,t){const n=e.destinations[t];if(!n)throw new Error(`Destination not found: ${t}`);return n}a(f,{getDestination:()=>p});var d={},m={},g={};a(g,{Level:()=>y});var y=(e=>(e[e.ERROR=0]="ERROR",e[e.WARN=1]="WARN",e[e.INFO=2]="INFO",e[e.DEBUG=3]="DEBUG",e))(y||{}),h={},v={},b={};function w(e,t){const n=e.transformers[t];if(!n)throw new Error(`Transformer not found: ${t}`);return n}a(b,{getTransformer:()=>w});var k={},$={};function j(e,t){const n=e.sources[t];if(!n)throw new Error(`Source not found: ${t}`);return n}a($,{getSource:()=>j});var x={};function O(e,t){const n=e.stores[t];if(!n)throw new Error(`Store not found: ${t}`);return n}a(x,{getStore:()=>O});var S={},A={},E={},_={},C={},N={},P={Utils:{Storage:{Local:"local",Session:"session",Cookie:"cookie"}}};function T(e){return{_meta:{hops:0,path:[e]}}}function R(e,t){return{event:e,next:t}}function I(e){return/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e)?e.replace(/\.\d+$/,".0"):""}function M(e){throw new Error(String(e))}var F=new Set(["description","examples","title","$comment"]);function z(e){const t={},n=new Set;function r(o){if(t[o])return t[o];n.has(o)&&M(`Circular extend chain detected: ${[...n,o].join(" → ")}`);const a=e[o];a||M(`Contract "${o}" not found`),n.add(o);let i={};if(a.extend){i=function(e,t){const n={};void 0===e.tagging&&void 0===t.tagging||(n.tagging=t.tagging??e.tagging);void 0===e.description&&void 0===t.description||(n.description=t.description??e.description);e.schema&&t.schema?n.schema=D(e.schema,t.schema):(e.schema||t.schema)&&(n.schema={...e.schema||t.schema});if(e.events||t.events){const r={},o=new Set([...Object.keys(e.events||{}),...Object.keys(t.events||{})]);for(const n of o){const o=e.events?.[n]||{},a=t.events?.[n]||{},i=new Set([...Object.keys(o),...Object.keys(a)]);r[n]={};for(const e of i){const t=o[e],i=a[e];r[n][e]=t&&i?D(t,i):{...t||i}}}n.events=r}return n}(r(a.extend),a)}else i={...a};if(delete i.extend,i.events&&(i.events=function(e){const t={};for(const n of Object.keys(e))if("*"!==n){t[n]={};for(const r of Object.keys(e[n]||{})){let o={};const a=e["*"]?.["*"];a&&(o=D(o,a));const i=e["*"]?.[r];i&&"*"!==r&&(o=D(o,i));const s=e[n]?.["*"];s&&"*"!==r&&(o=D(o,s));const c=e[n]?.[r];c&&(o=D(o,c)),t[n][r]=o}}e["*"]&&(t["*"]={...e["*"]});return t}(i.events)),i.events){const e={};for(const[t,n]of Object.entries(i.events)){e[t]={};for(const[r,o]of Object.entries(n))e[t][r]=V(o)}i.events=e}return n.delete(o),t[o]=i,i}for(const t of Object.keys(e))r(t);return t}function D(e,t){const n={...e};for(const r of Object.keys(t)){const o=e[r],a=t[r];"required"===r&&Array.isArray(o)&&Array.isArray(a)?n[r]=[...new Set([...o,...a])]:L(o)&&L(a)?n[r]=D(o,a):n[r]=a}return n}function V(e){const t={};for(const[n,r]of Object.entries(e))F.has(n)||(null===r||"object"!=typeof r||Array.isArray(r)?t[n]=r:t[n]=V(r));return t}function L(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}var U=/^\$var\.([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)$/,Z=/\$var\.([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)/g,H=/\$env\.([a-zA-Z_][a-zA-Z0-9_]*)(?::([^"}\s]*))?/g,W=/^\$contract\.([a-zA-Z_][a-zA-Z0-9_]*)(?:\.(.+))?$/,B=/^\$flow\.([a-zA-Z_][a-zA-Z0-9_]*)(?:\.([a-zA-Z0-9_.]+))?$/,q=/^\$store\.([a-zA-Z_][a-zA-Z0-9_]*)$/,K=/^\$secret\.([A-Z0-9_]+)$/,J="$code:";function G(...e){const t={};for(const n of e)n&&Object.assign(t,n);return t}var X="__WALKEROS_ENV:";function Y(e,t,n){const r=`$flow.${e}${t?`.${t}`:""}`;if("unknown-flow"===n)return`${r} cannot resolve: flow "${e}" does not exist in this config.`;return`${r} is empty. Set ${t?`flows.${e}.config.${t}`:`flows.${e}.config`}, or run \`walkeros deploy ${e}\` first.`}function Q(e,t,n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const a=r[e];if(null==o||"object"!=typeof o){const o=r.slice(0,e).join(".");M(`Path "${t}" not found in "${n}": "${a}" does not exist${o?` in "${o}"`:""}`)}const i=o;if(!(a in i)){const o=r.slice(0,e).join(".");M(`Path "${t}" not found in "${n}": "${a}" does not exist${o?` in "${o}"`:""}`)}o=i[a]}return o}function ee(e,t,n,r,o,a){if("string"==typeof e){const i=e.match(U);if(i){const e=i[1].split("."),s=e[0],c=e.slice(1).join(".");void 0===t[s]&&M(`Variable "${s}" not found`);const l=a??new Set;if(l.has(s)){M(`Cyclic $var reference: ${[...l,s].join(" -> ")}`)}let u;l.add(s);try{u=ee(t[s],t,n,r,o,l)}finally{l.delete(s)}return c&&(u=Q(u,c,`$var.${s}`)),u}const s=e.match(W);if(s&&r){const e=s[1],t=s[2];e in r||M(`Contract "${e}" not found`);let n=r[e];return t&&(n=Q(n,t,`$contract.${e}`)),n}const c=e.match(B);if(c){const t=c[1],r=c[2],a=!1===n?.strictFlowRefs;o||M(`$flow.${t}${r?`.${r}`:""} cannot be resolved without a flow resolver`);const i=o(t);if(!i){if(a)return n?.onWarning?.(Y(t,r,"unknown-flow")),e;M(`Flow "${t}" not found in $flow.${t}`)}let s=i;if(r)if(a){try{s=Q(s,r,`$flow.${t}`)}catch{return n?.onWarning?.(Y(t,r,"missing-key")),e}if(null==s||""===s)return n?.onWarning?.(Y(t,r,"missing-key")),e}else s=Q(s,r,`$flow.${t}`);return s}let l=e.replace(Z,(e,i)=>{const s=i.split("."),c=s[0],l=s.slice(1).join(".");void 0===t[c]&&M(`Variable "${c}" not found`);const u=a??new Set;if(u.has(c)){M(`Cyclic $var reference: ${[...u,c].join(" -> ")}`)}let f;u.add(c);try{f=ee(t[c],t,n,r,o,u)}finally{u.delete(c)}if(l&&(f=Q(f,l,`$var.${c}`)),null===f||"string"!=typeof f&&"number"!=typeof f&&"boolean"!=typeof f){M(`Variable "${i}" resolves to non-scalar (${Array.isArray(f)?"array":typeof f}) and cannot be inlined into a string. Use it as a whole-string reference: "$var.${i}"`)}return String(f)});return l=l.replace(H,(e,t,r)=>n?.deferred?void 0!==r?`${X}${t}:${r}`:`${X}${t}`:"undefined"!=typeof process&&void 0!==process.env?.[t]?process.env[t]:void 0!==r?r:void M(`Environment variable "${t}" not found and no default provided`)),l}if(Array.isArray(e))return e.map(e=>ee(e,t,n,r,o,a));if(null!==e&&"object"==typeof e){const i={};for(const[s,c]of Object.entries(e))i[s]=ee(c,t,n,r,o,a);return i}return e}function te(e){const t=e.startsWith("@"),n=e.replace("@","").replace(/[/-]/g,"_").split("_").filter(e=>e.length>0).map((e,t)=>0===t?e:e.charAt(0).toUpperCase()+e.slice(1)).join("");return t?"_"+n:n}function ne(e,t,n){const r=new Map,o=new Set,a=[],i=t=>{if(r.has(t))return r.get(t);const s=e.flows[t];if(s){if(o.has(t)){M(`Cyclic $flow reference: ${[...a,t].join(" -> ")}`)}o.add(t),a.push(t);try{const o=G(e.variables,s.variables),a=ee(s.config??{},o,n,void 0,i);return r.set(t,a),a}finally{o.delete(t),a.pop()}}},s=Object.keys(e.flows);t||(1===s.length?t=s[0]:M(`Multiple flows found (${s.join(", ")}). Please specify a flow.`));const c=e.flows[t];c||M(`Flow "${t}" not found. Available: ${s.join(", ")}`),o.add(t),a.push(t);try{return function(e,t,n,r){const o=JSON.parse(JSON.stringify(t));let a;if(e.contract){const o=G(e.variables,t.variables);a=z(ee(e.contract,o,n,void 0,r))}if(o.config){const i=G(e.variables,t.variables);o.config=ee(o.config,i,n,a,r)}if(o.sources)for(const[i,s]of Object.entries(o.sources)){const c=G(e.variables,t.variables,s.variables),l=ee(s.config,c,n,a,r),u=ee(s.env,c,n,a,r);o.sources[i]={package:s.package,import:s.import,config:l,env:u,primary:s.primary,variables:s.variables,before:s.before,next:s.next,cache:s.cache,validate:s.validate,code:s.code}}if(o.destinations)for(const[i,s]of Object.entries(o.destinations)){const c=G(e.variables,t.variables,s.variables),l=ee(s.config,c,n,a,r),u=ee(s.env,c,n,a,r);o.destinations[i]={package:s.package,import:s.import,config:l,env:u,variables:s.variables,before:s.before,next:s.next,cache:s.cache,validate:s.validate,code:s.code}}if(o.stores)for(const[i,s]of Object.entries(o.stores)){const c=G(e.variables,t.variables,s.variables),l=ee(s.config,c,n,a,r),u=ee(s.env,c,n,a,r);o.stores[i]={package:s.package,import:s.import,config:l,env:u,cache:s.cache,variables:s.variables,code:s.code}}if(o.transformers)for(const[i,s]of Object.entries(o.transformers)){const c=G(e.variables,t.variables,s.variables),l=ee(s.config,c,n,a,r),u=ee(s.env,c,n,a,r);o.transformers[i]={package:s.package,import:s.import,config:l,env:u,variables:s.variables,before:s.before,next:s.next,cache:s.cache,validate:s.validate,code:s.code}}if(o.collector){const i=G(e.variables,t.variables),s=ee(o.collector,i,n,a,r);o.collector=s}return o}(e,c,n,i)}finally{o.delete(t),a.pop()}}function re(e){const t=e.config?.platform;if("web"===t||"server"===t)return t;M('Flow must have config.platform set to "web" or "server"')}var oe={merge:!0,shallow:!0,extend:!0};function ae(e,t={},n={}){n={...oe,...n};const r=Object.entries(t).reduce((t,[r,o])=>{const a=e[r];return n.merge&&Array.isArray(a)&&Array.isArray(o)?t[r]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...a]):(n.extend||r in e)&&(t[r]=o),t},{});return n.shallow?{...e,...r}:(Object.assign(e,r),e)}function ie(e){return"[object Arguments]"===Object.prototype.toString.call(e)}function se(e){return Array.isArray(e)}function ce(e){return"boolean"==typeof e}function le(e){return"walker"===e}function ue(e){return void 0!==e}function fe(e){return!(!e||"object"!=typeof e)&&("body"in e||"tagName"in e)}function pe(e){return"function"==typeof e}function de(e){return"number"==typeof e&&!Number.isNaN(e)}function me(e){return"object"==typeof e&&null!==e&&!se(e)&&"[object Object]"===Object.prototype.toString.call(e)}function ge(e,t){return typeof e==typeof t}function ye(e){return"string"==typeof e}function he(e,t=new WeakMap){if("object"!=typeof e||null===e)return e;if(t.has(e))return t.get(e);const n=Object.prototype.toString.call(e);if("[object Object]"===n){const n={};t.set(e,n);for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=he(e[r],t));return n}if("[object Array]"===n){const n=[];return t.set(e,n),e.forEach(e=>{n.push(he(e,t))}),n}if("[object Date]"===n)return new Date(e.getTime());if("[object RegExp]"===n){const t=e;return new RegExp(t.source,t.flags)}return e}function ve(e,t="",n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const t=r[e];if("*"===t&&se(o)){const t=r.slice(e+1).join("."),a=[];for(const e of o){const r=ve(e,t,n);a.push(r)}return a}if(o=me(o)||se(o)?o[t]:void 0,void 0===o)break}return ue(o)?o:n}function be(e,t,n){if(!me(e))return e;const r=he(e),o=t.split(".");let a=r;for(let e=0;e<o.length;e++){const t=o[e];e===o.length-1?a[t]=n:(t in a&&"object"==typeof a[t]&&null!==a[t]||(a[t]={}),a=a[t])}return r}function we(e,t){if(!me(e)&&!se(e))return e;const n=he(e),r=t.split(".");let o=n;for(let e=0;e<r.length;e++){const t=r[e],a=e===r.length-1;if(se(o)){const e=Number(t);if(!Number.isInteger(e)||e<0||e>=o.length)return n;if(a)o.splice(e,1);else{const t=o[e];if(!me(t)&&!se(t))return n;o=t}}else if(a)delete o[t];else{const e=o[t];if(!me(e)&&!se(e))return n;o=e}}return n}var ke={data:e=>e.data,globals:e=>e.globals,context:e=>e.context,user:e=>e.user,source:e=>e.source,event:e=>({entity:e.entity,action:e.action,id:e.id,timestamp:e.timestamp,name:e.name,trigger:e.trigger,timing:e.timing})};function $e(e,t){const n={},r=t.includes("all")?Object.keys(ke):t;for(const t of r){const r=ke[t];if(!r)continue;const o=r(e);if(me(o))for(const[e,r]of Object.entries(o)){if(void 0===r)continue;const o="context"===t&&Array.isArray(r)?r[0]:r;n[`${t}_${e}`]=o}}return n}function je(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}function xe(e,t={},n={}){const r={...t,...n},o={};let a=!e||0===Object.keys(e).length;return Object.keys(r).forEach(t=>{r[t]&&(o[t]=!0,e&&e[t]&&(a=!0))}),!!a&&o}function Oe(e,t){const n={...e};return n.config=ae(e.config,t,{shallow:!0,merge:!0,extend:!0}),e.config.settings&&t.settings&&(n.config.settings=ae(e.config.settings,t.settings,{shallow:!0,merge:!0,extend:!0})),e.config.mapping&&t.mapping&&(n.config.mapping=ae(e.config.mapping,t.mapping,{shallow:!0,merge:!0,extend:!0})),n}function Se(e,t){if(!me(t))return e;for(const n of Object.keys(t)){const r=t[n];void 0!==r&&(me(r)&&me(e[n])?Se(e[n],r):e[n]=r)}return e}function Ae(){let e="";for(let t=0;t<16;t++)e+=(16*Math.random()|0).toString(16);return e}function Ee(e={}){const t=e.timestamp||(new Date).setHours(0,13,37,0),n=ae({name:"entity action",data:{string:"foo",number:1,boolean:!0,array:[0,"text",!1],not:void 0},context:{dev:["test",1]},globals:{lang:"elb"},custom:{completely:"random"},user:{id:"us3r",device:"c00k13",session:"s3ss10n"},nested:[{entity:"child",data:{is:"subordinated"}}],consent:{functional:!0},id:e.id||Ae(),trigger:"test",entity:"entity",action:"action",timestamp:t,timing:3.14,source:{type:"collector",schema:"4"}},e,{merge:!1});if(e.name){const[t,r]=e.name.split(" ")??[];t&&r&&(n.entity=t,n.action=r)}return n}function _e(e="entity action",t={}){const n=t.timestamp||(new Date).setHours(0,13,37,0),r={data:{id:"ers",name:"Everyday Ruck Snack",color:"black",size:"l",price:420}},o={data:{id:"cc",name:"Cool Cap",size:"one size",price:42}};return Ee({...{"cart view":{data:{currency:"EUR",value:2*r.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:{...r.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:r.data.price+o.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...r,context:{shopping:["checkout",0]},nested:[]},{entity:"product",...o,context:{shopping:["checkout",0]},nested:[]}],trigger:"load"},"order complete":{data:{id:"0rd3r1d",currency:"EUR",shipping:5.22,taxes:73.76,total:555},context:{shopping:["complete",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...r,context:{shopping:["complete",0]},nested:[]},{entity:"product",...o,context:{shopping:["complete",0]},nested:[]},{entity:"gift",data:{name:"Surprise"},context:{shopping:["complete",0]},nested:[]}],trigger:"load"},"page view":{data:{domain:"www.example.com",title:"walkerOS documentation",referrer:"https://www.walkeros.io/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...r,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...r,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...r.data,position:3,promo:!0},context:{shopping:["discover",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"promotion visible":{data:{name:"Setting up tracking easily",position:"hero"},context:{ab_test:["engagement",0]},globals:{pagegroup:"homepage"},trigger:"visible"},"session start":{data:{id:"s3ss10n",start:n,isNew:!0,count:1,runs:1,isStart:!0,storage:!0,referrer:"",device:"c00k13"},user:{id:"us3r",device:"c00k13",session:"s3ss10n",hash:"h4sh",address:"street number",email:"user@example.com",phone:"+49 123 456 789",userAgent:"Mozilla...",browser:"Chrome",browserVersion:"90",deviceType:"desktop",language:"de-DE",country:"DE",region:"HH",city:"Hamburg",zip:"20354",timezone:"Berlin",os:"walkerOS",osVersion:"1.0",screenSize:"1337x420",ip:"127.0.0.0",internal:!0,custom:"value"}}}[e],...t,name:e})}function Ce(e=6,t){if(t){const n=t.length;let r="";for(let o=0;o<e;o++)r+=t[Math.random()*n|0];return r}let n="";for(let t=36;n.length<e;)n+=(Math.random()*t|0).toString(t);return n}var Ne=[{param:"gclid",platform:"google"},{param:"wbraid",platform:"google"},{param:"gbraid",platform:"google"},{param:"dclid",platform:"google"},{param:"gclsrc",platform:"google"},{param:"fbclid",platform:"meta"},{param:"igshid",platform:"meta"},{param:"msclkid",platform:"microsoft"},{param:"ttclid",platform:"tiktok"},{param:"twclid",platform:"twitter"},{param:"li_fat_id",platform:"linkedin"},{param:"epik",platform:"pinterest"},{param:"sclid",platform:"snapchat"},{param:"sccid",platform:"snapchat"},{param:"rdt_cid",platform:"reddit"},{param:"qclid",platform:"quora"},{param:"yclid",platform:"yandex"},{param:"ymclid",platform:"yandex"},{param:"ysclid",platform:"yandex"},{param:"dicbo",platform:"outbrain"},{param:"obclid",platform:"outbrain"},{param:"tblci",platform:"taboola"},{param:"mc_cid",platform:"mailchimp"},{param:"mc_eid",platform:"mailchimp"},{param:"_kx",platform:"klaviyo"},{param:"_hsenc",platform:"hubspot"},{param:"_hsmi",platform:"hubspot"},{param:"s_kwcid",platform:"adobe"},{param:"ef_id",platform:"adobe"},{param:"mkt_tok",platform:"adobe"},{param:"irclickid",platform:"impact"},{param:"cjevent",platform:"cj"},{param:"_branch_match_id",platform:"branch"}];function Pe(e,t={},n=[]){const r={};Object.entries(ae({utm_campaign:"campaign",utm_content:"content",utm_medium:"medium",utm_source:"source",utm_term:"term"},t)).forEach(([t,n])=>{const o=e.searchParams.get(t);o&&(r[n]=o)});const o=n.length?function(e){const t=new Map(e.map(e=>[e.param,e.platform])),n=new Set(Ne.map(e=>e.param));return[...Ne.map(e=>t.has(e.param)?{param:e.param,platform:t.get(e.param)}:e),...e.filter(e=>!n.has(e.param))]}(n):Ne,a=new Map;e.searchParams.forEach((e,t)=>{e&&a.set(t.toLowerCase(),e)});for(const e of o){const t=a.get(e.param);t&&(r[e.param]=t,r.clickId||(r.clickId=e.param,r.platform=e.platform))}return r}function Te(e,t){return"number"==typeof e?{wait:e}:e?{wait:e.wait??t,size:e.size,age:e.age}:{wait:t}}function Re(e,t=1e3,n=!1){const{wait:r,size:o,age:a}=Te(t,1e3);let i,s,c=null,l=null,u=!1,f=[],p=0;const d=()=>{c&&(clearTimeout(c),c=null),l&&(clearTimeout(l),l=null),p=0,s=void 0},m=()=>{const t=s,n=f;if(d(),f=[],t)return i=e(...t),n.forEach(e=>e(i)),i;n.forEach(e=>e(void 0))},g=(...t)=>new Promise(d=>{const g=n&&!u;if(s=t,p+=1,f.push(d),c&&clearTimeout(c),c=setTimeout(()=>{c=null,n&&!u||m()},r),void 0===a||l||(l=setTimeout(()=>{l=null,m()},a)),void 0!==o&&p>=o)m();else if(g){u=!0,i=e(...t);const n=f;f=[],n.forEach(e=>e(i))}});return g.flush=()=>s||0!==f.length?new Promise(e=>{f.push(e),m()}):Promise.resolve(void 0),g.cancel=()=>{const e=f;f=[],d(),e.forEach(e=>e(void 0))},g.size=()=>p,g}function Ie(e,t=1e3){const{wait:n}=Te(t,1e3);let r=null;return function(...t){if(null===r)return r=setTimeout(()=>{r=null},n),e(...t)}}function Me(e){return{message:e.message,name:e.name,stack:e.stack,cause:e.cause}}function Fe(e,t){let n,r={};return e instanceof Error?(n=e.message,r.error=Me(e)):n=e,void 0!==t&&(t instanceof Error?r.error=Me(t):"object"==typeof t&&null!==t?(r={...r,...t},"error"in r&&r.error instanceof Error&&(r.error=Me(r.error))):r.value=t),{message:n,context:r}}var ze=(e,t,n,r)=>{const o=`${y[e]}${r.length>0?` [${r.join(":")}]`:""}`,a=Object.keys(n).length>0,i=0===e?console.error:1===e?console.warn:console.log;a?i(o,t,n):i(o,t)};function De(e={}){return Ve({level:void 0!==e.level?function(e){return"string"==typeof e?y[e]:e}(e.level):0,handler:e.handler,jsonHandler:e.jsonHandler,scope:[]})}function Ve(e){const{level:t,handler:n,jsonHandler:r,scope:o}=e,a=(e,r,a)=>{if(e<=t){const t=Fe(r,a);n?n(e,t.message,t.context,o,ze):ze(e,t.message,t.context,o)}};return{error:(e,t)=>a(0,e,t),warn:(e,t)=>a(1,e,t),info:(e,t)=>a(2,e,t),debug:(e,t)=>a(3,e,t),throw:(e,t)=>{const r=Fe(e,t);throw n?n(0,r.message,r.context,o,ze):ze(0,r.message,r.context,o),new Error(r.message)},json:e=>{r?r(e):console.log(JSON.stringify(e,null,2))},scope:e=>Ve({level:t,handler:n,jsonHandler:r,scope:[...o,e]})}}function Le(e){return ce(e)||ye(e)||de(e)||!ue(e)||se(e)&&e.every(Le)||me(e)&&Object.values(e).every(Le)}function Ue(e){return ce(e)||ye(e)||de(e)?e:ie(e)?Ue(Array.from(e)):se(e)?e.map(e=>Ue(e)).filter(e=>void 0!==e):me(e)?Object.entries(e).reduce((e,[t,n])=>{const r=Ue(n);return void 0!==r&&(e[t]=r),e},{}):void 0}function Ze(e){return Le(e)?e:void 0}function He(e,t,n){return function(...r){try{return e(...r)}catch(e){if(!t)return;return t(e)}finally{n?.()}}}function We(e,t,n){return async function(...r){try{return await e(...r)}catch(e){if(!t)return;return await t(e)}finally{await(n?.())}}}var Be=class e extends Error{constructor(t,n){super(t,n),this.name="FatalError",Object.setPrototypeOf(this,e.prototype)}};async function qe(e,t,n){const[r,o]=(e.name||"").split(" ");if(!t||!r||!o)return{};let a,i="",s=r,c=o;const l=t=>{if(!t)return;return(se(t)?t:[t]).find(t=>{if(!t.condition)return!0;if(!n)return Boolean(t.condition(e,void 0));const r={event:e,mapping:t,collector:n,logger:n.logger,consent:me(e)&&e.consent||n.consent};return Boolean(t.condition(e,r))})};t[s]||(s="*");const u=t[s];return u&&(u[c]||(c="*"),a=l(u[c])),a||(s="*",c="*",a=l(t[s]?.[c])),a&&(i=`${s} ${c}`),{eventMapping:a,mappingKey:i}}async function Ke(e,t={},n={}){if(!ue(e))return;const r=me(e)&&e.consent||n.consent||n.collector?.consent,o=n.event??(me(e)?e:{});if(!n.collector)throw new Error("getMappingValue: context.collector is required");const a={event:o,mapping:t,collector:n.collector,logger:n.collector.logger,consent:r},i=se(t)?t:[t];for(const t of i){const r=await We(Je,e=>{if(e instanceof Be)throw e;n.collector&&n.collector.status.failed++,a.logger.error("mapping processing failed",{event:o,error:e})})(e,t,{...a,mapping:t});if(ue(r))return r}}async function Je(e,t,n){return(se(t)?t:[t]).reduce(async(t,r)=>{const o=await t;if(o)return o;const a=ye(r)?{key:r}:r;if(!Object.keys(a).length)return;const{condition:i,consent:s,fn:c,key:l,loop:u,map:f,set:p,validate:d,value:m}=a,g={...n,mapping:r};if(i&&!await We(i,e=>{if(e instanceof Be)throw e;return g.logger.error("mapping condition failed",{event:g.event,error:e}),!1})(e,g))return;if(s&&!xe(s,g.consent))return m;let y=ue(m)?m:e;if(c&&(y=await We(c,e=>{if(e instanceof Be)throw e;g.logger.error("mapping fn failed",{event:g.event,error:e})})(e,g)),l&&(y=ve(e,l,m)),u){const[t,n]=u,r="this"===t?[e]:await Ke(e,t,g);se(r)&&(y=(await Promise.all(r.map(e=>Ke(e,n,g)))).filter(ue))}else f?y=await Object.entries(f).reduce(async(t,[n,r])=>{const o=await t,a=await Ke(e,r,g);return ue(a)&&(o[n]=a),o},Promise.resolve({})):p&&(y=await Promise.all(p.map(t=>Je(e,t,g))));d&&!await We(d,e=>{if(e instanceof Be)throw e;return g.logger.error("mapping validate failed",{event:g.event,error:e}),!1})(y,g)&&(y=void 0);const h=Ze(y);return ue(h)?h:Ze(m)},Promise.resolve(void 0))}async function Ge(e,t,n){t.policy&&await Promise.all(Object.entries(t.policy).map(async([t,r])=>{const o=await Ke(e,r,{collector:n,event:e});e=be(e,t,o)}));const{eventMapping:r,mappingKey:o}=await qe(e,t.mapping,n);r?.policy&&await Promise.all(Object.entries(r.policy).map(async([t,r])=>{const o=await Ke(e,r,{collector:n,event:e});e=be(e,t,o)}));let a=t.data&&await Ke(e,t.data,{collector:n,event:e});const i=Boolean(r?.silent);if(r){if(r.ignore)return{event:e,data:a,mapping:r,mappingKey:o,ignore:!0,silent:i};if(r.name&&(e.name=r.name),r.data){const t=r.data&&await Ke(e,r.data,{collector:n,event:e});a=me(a)&&me(t)?ae(a,t):t}}const s=r?.include??t.include;if(s&&s.length>0){const t=$e(e,s);Object.keys(t).length>0&&(a=me(a)?ae(t,a):a??t)}if(r?.remove&&me(a))for(const e of r.remove)a=we(a,e);return{event:e,data:a,mapping:r,mappingKey:o,ignore:!1,silent:i}}function Xe(e,t){for(const n of Object.keys(t)){const r=t[n];if(void 0===r)continue;if(null===r){delete e[n];continue}const o=e[n];me(r)&&me(o)?Xe(o,r):e[n]=r}return e}function Ye(e,t){if(void 0===t.extend&&void 0===t.remove)return he(t);const n={...he(e)};if(t.extend){Xe(n,{...t.extend})}return delete n.extend,t.remove?n.remove=[...t.remove]:delete n.remove,n}function Qe(e,t){const n=(e,r=[])=>new Proxy(e,{get(e,o){const a=e[o],i=[...r,o];return"function"==typeof a?a.prototype&&a.prototype.constructor===a?a:(...e)=>{const r=t(i,e,a);if(r&&"object"==typeof r)return n(r,i);const o=a(...e);return o&&"object"==typeof o?n(o,i):r}:a&&"object"==typeof a?n(a,i):a}});return n(e)}function et(e,t){const n=(e,r=[])=>{if(!e||"object"!=typeof e)return e;const o=Array.isArray(e)?[]:{};for(const[a,i]of Object.entries(e)){const e=[...r,a];Array.isArray(o)?o[Number(a)]=t(i,e):o[a]=t(i,e),i&&"object"==typeof i&&"function"!=typeof i&&(Array.isArray(o)?o[Number(a)]=n(i,e):o[a]=n(i,e))}return o};return n(e)}function tt(){const e=[],t=jest.fn(e=>{const t=e instanceof Error?e.message:e;throw new Error(t)}),n=jest.fn(t=>{const n=tt();return e.push(n),n});return{error:jest.fn(),warn:jest.fn(),info:jest.fn(),debug:jest.fn(),throw:t,json:jest.fn(),scope:n,scopedLoggers:e}}function nt(e={}){return{collector:{},config:{},env:{},logger:tt(),id:"test",ingest:T("test"),...e}}function rt(e){const t=String(e),n=t.split("?")[1]||t;return He(()=>{const e=new URLSearchParams(n),t={};return e.forEach((e,n)=>{const r=n.split(/[[\]]+/).filter(Boolean);let o=t;r.forEach((t,n)=>{const a=n===r.length-1;if(se(o)){const i=parseInt(t,10);a?o[i]=je(e):(o[i]=o[i]||(isNaN(parseInt(r[n+1],10))?{}:[]),o=o[i])}else me(o)&&(a?o[t]=je(e):(o[t]=o[t]||(isNaN(parseInt(r[n+1],10))?{}:[]),o=o[t]))})}),t})()}function ot(e){if(!e)return"";const t=[],n=encodeURIComponent;function r(e,o){null!=o&&(se(o)?o.forEach((t,n)=>r(`${e}[${n}]`,t)):me(o)?Object.entries(o).forEach(([t,n])=>r(`${e}[${t}]`,n)):t.push(`${n(e)}=${n(String(o))}`))}return"object"!=typeof e?n(e):(Object.entries(e).forEach(([e,t])=>r(e,t)),t.join("&"))}function at(e){return void 0===e||ge(e,"")?e:JSON.stringify(e)}function it(e={}){return ae({"Content-Type":"application/json; charset=utf-8"},e)}function st(e,t){return!1===e||void 0===e?null:!0===e?t:{...t,...e}}function ct(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function lt(e,t,n,r){return function(...o){let a;const i="pre"+t,s="post"+t,c=n[i],l=n[s],u=(e,t)=>{r?r.warn(e,{error:t}):console.warn(e,t)};if(c)try{a=c({fn:e},...o)}catch(t){u(`Hook ${String(i)} failed, falling back to original function`,t),a=e(...o)}else a=e(...o);if(l)try{a=l({fn:e,result:a},...o)}catch(e){u(`Hook ${String(s)} failed, keeping original result`,e)}return a}}function ut(e){return e?{userAgent:e,browser:ft(e),browserVersion:pt(e),os:dt(e),osVersion:mt(e),deviceType:gt(e)}:{}}function ft(e){const t=[{name:"Edge",substr:"Edg"},{name:"Chrome",substr:"Chrome"},{name:"Safari",substr:"Safari",exclude:"Chrome"},{name:"Firefox",substr:"Firefox"},{name:"IE",substr:"MSIE"},{name:"IE",substr:"Trident"}];for(const n of t)if(e.includes(n.substr)&&(!n.exclude||!e.includes(n.exclude)))return n.name}function pt(e){const t=[/Edg\/([0-9]+)/,/Chrome\/([0-9]+)/,/Version\/([0-9]+).*Safari/,/Firefox\/([0-9]+)/,/MSIE ([0-9]+)/,/rv:([0-9]+).*Trident/];for(const n of t){const t=e.match(n);if(t)return t[1]}}function dt(e){const t=[{name:"Windows",substr:"Windows NT"},{name:"macOS",substr:"Mac OS X"},{name:"Android",substr:"Android"},{name:"iOS",substr:"iPhone OS"},{name:"Linux",substr:"Linux"}];for(const n of t)if(e.includes(n.substr))return n.name}function mt(e){const t=e.match(/(?:Windows NT|Mac OS X|Android|iPhone OS) ([0-9._]+)/);return t?t[1].replace(/_/g,"."):void 0}function gt(e){let t="Desktop";return/Tablet|iPad/i.test(e)?t="Tablet":/Mobi|Android|iPhone|iPod|BlackBerry|Opera Mini|IEMobile|WPDesktop/i.test(e)&&(t="Mobile"),t}function yt(e){return function(e){return/\breturn\b/.test(e)}(e)?e:`return ${e}`}function ht(e){const t=yt(e);return new Function("value","context",t)}function vt(e){const t=yt(e);return new Function("value","context",t)}function bt(e){const t=yt(e);return new Function("value","context",t)}var wt="https://cdn.jsdelivr.net/npm",kt="dist/walkerOS.json";function $t(e){return"string"==typeof e||Array.isArray(e)&&e.every(e=>"string"==typeof e)?e:void 0}async function jt(e,t){const n=t?.version||"latest",r=t?.timeout||1e4,o=new AbortController,a=setTimeout(()=>o.abort(),r),i=o.signal,s=t?.client?{"X-Walkeros-Client":t.client}:void 0;try{if(t?.baseUrl){const r=`${t.baseUrl}/api/packages/${encodeURIComponent(e)}?version=${encodeURIComponent(n)}&expand=all`,o=await fetch(r,{signal:i,...s&&{headers:s}});if(!o.ok)throw new Error(`Failed to fetch ${r} (HTTP ${o.status})`);return function(e,t,n){const r=n.schemas||{},o=n.examples||{},a=n.hints,i=n.hintKeys??(a?Object.keys(a):[]),s=n.exampleSummaries??[],c=n.platform;return{packageName:n.package||e,version:"string"==typeof n.version?n.version:t,...void 0!==n.description&&{description:n.description},...void 0!==n.type&&{type:n.type},...void 0!==c&&{platform:c},schemas:r,examples:o,...void 0!==n.docs&&{docs:n.docs},...void 0!==n.source&&{source:n.source},...a&&Object.keys(a).length>0?{hints:a}:{},hintKeys:i,exampleSummaries:s}}(e,n,await o.json())}const r=`${wt}/${e}@${n}`,o=await xt(`${r}/package.json`,i,s);return function(e,t,n,r){const o=r.$meta||{},a=r.schemas||{},i=r.examples||{},s=r.hints,c=s?Object.keys(s):[],l=[],u=i.step||{};for(const[e,t]of Object.entries(u)){const n=t,r={name:e};"string"==typeof n?.description&&(r.description=n.description),l.push(r)}const f="string"==typeof o.docs?o.docs:void 0,p="string"==typeof o.source?o.source:void 0;return{packageName:e,version:"string"==typeof n.version?n.version:t,description:"string"==typeof n.description?n.description:void 0,type:"string"==typeof o.type?o.type:void 0,platform:$t(o.platform),schemas:a,examples:i,...f?{docs:f}:{},...p?{source:p}:{},...s&&Object.keys(s).length>0?{hints:s}:{},hintKeys:c,exampleSummaries:l}}(e,n,o,await xt(`${r}/${kt}`,i,s))}finally{clearTimeout(a)}}async function xt(e,t,n){const r=await fetch(e,{signal:t,...n&&{headers:n}});if(!r.ok)throw new Error(`Failed to fetch ${e} (HTTP ${r.status})`);return await r.json()}async function Ot(e,t){const n=await jt(e,t);return{packageName:n.packageName,version:n.version,type:n.type,platform:n.platform,schemas:n.schemas,examples:n.examples,...n.hints?{hints:n.hints}:{}}}function St(e,t){const n=t?{...e,_hints:t}:e;return{content:[{type:"text",text:JSON.stringify(n,null,2)}],structuredContent:n}}function At(e,t){let n,r,o,a;if(e instanceof Error){n=e.message;const t=e;t.code&&(o=t.code),Array.isArray(t.details)&&(a=t.details)}else if("string"==typeof e)n=e;else if(e&&"object"==typeof e&&"issues"in e&&Array.isArray(e.issues)){const t=e.issues;n=t.map(e=>e.message).join("; "),r=t[0]?.path?.join(".")||void 0}else n=e&&"object"==typeof e&&"message"in e?String(e.message):"Unknown error";const i={error:n};return t&&(i.hint=t),r&&(i.path=r),o&&(i.code=o),a&&(i.details=a),{content:[{type:"text",text:JSON.stringify(i)}],structuredContent:i,isError:!0}}function Et(e){let t=!1;return(n={})=>{t||(t=!0,e(n))}}function _t(e){if(void 0===e||"*"===e)return()=>!0;if("and"in e){const t=e.and.map(_t);return e=>t.every(t=>t(e))}if("or"in e){const t=e.or.map(_t);return e=>t.some(t=>t(e))}return function(e){const{key:t,operator:n,value:r,not:o}=e,a=function(e,t){switch(e){case"eq":return e=>String(e??"")===t;case"contains":return e=>String(e??"").includes(t);case"prefix":return e=>String(e??"").startsWith(t);case"suffix":return e=>String(e??"").endsWith(t);case"regex":{const e=new RegExp(t);return t=>e.test(String(t??""))}case"gt":{const e=Number(t);return t=>Number(t)>e}case"lt":{const e=Number(t);return t=>Number(t)<e}case"exists":return e=>null!=e}}(n,r);return e=>{const n=ve(e,t),r=a(n);return o?!r:r}}(e)}function Ct(e){return Array.isArray(e)&&e.length>0&&e.every(e=>function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)&&("match"in e||"next"in e||"one"in e||"many"in e)}(e))}function Nt(e){return e.map(e=>{if("string"==typeof e)return{match:()=>!0,next:{type:"static",value:e}};if(Array.isArray(e))return{match:()=>!0,next:Pt(e)??{type:"chain",value:[]}};const t=e;return{match:t.match?_t(t.match):()=>!0,next:Pt(t)??{type:"chain",value:[]}}})}function Pt(e){if(null==e)return;if("string"==typeof e)return{type:"static",value:e};if(Array.isArray(e)){if(0===e.length)return;if(Ct(e))return Pt({one:e});if(e.every(e=>"string"==typeof e))return{type:"chain",value:e};const t=[];for(const n of e){const e=Pt(n);void 0!==e&&t.push(e)}if(0===t.length)return;return{type:"sequence",value:t}}const t=e;if("next"in t&&void 0!==t.next)return t.match?{type:"gate",match:_t(t.match),next:Pt(t.next)}:Pt(t.next);if("one"in t&&t.one){const e=Nt(t.one);return t.match?{type:"gate",match:_t(t.match),next:{type:"one",routes:e}}:{type:"one",routes:e}}if("many"in t&&t.many){const e=Nt(t.many);return t.match?{type:"gate",match:_t(t.match),next:{type:"many",routes:e}}:{type:"many",routes:e}}return t.match?{type:"gate",match:_t(t.match)}:void 0}var Tt=new WeakMap;function Rt(e,t={}){if(null==e)return[];let n;if("object"==typeof e){const t=Tt.get(e);t?n=t:(n=Pt(e),n&&Tt.set(e,n))}else n=Pt(e);if(!n)return[];const r=It(n,t);return void 0===r?[]:Array.isArray(r)?r:[r]}function It(e,t={}){if(e){if("static"===e.type)return e.value;if("chain"===e.type)return e.value;if("gate"===e.type){if(!e.match(t))return;return It(e.next,t)}if("sequence"===e.type){const n=[];for(const r of e.value){const e=It(r,t);void 0!==e&&(Array.isArray(e)?n.push(...e):n.push(e))}return n.length>0?n:void 0}if("many"===e.type){const n=[];for(const r of e.routes){if(!r.match(t))continue;const e=It(r.next,t);void 0!==e&&(Array.isArray(e)?n.push(...e):n.push(e))}return n.length>0?n:void 0}for(const n of e.routes)if(n.match(t))return It(n.next,t)}}function Mt(e,t){const n={ingest:e??{}};return void 0!==t&&(n.event=t),n}function Ft(e){return{stop:e.stop??!1,storeId:e.store,namespace:e.namespace,rules:e.rules.map(e=>({match:e.match?_t(e.match):()=>!0,key:e.key,ttl:e.ttl,update:e.update}))}}async function zt(e,t,n,r){const o=e.rules.find(e=>e.match(n));if(!o)return null;const a=o.key.map(e=>String(ve(n,e)??""));if(a.every(e=>""===e))return null;const i=a.join(":"),s=r??e.namespace,c=s?`${s}:${i}`:i,l=await t.get(c);return void 0!==l?{status:"HIT",key:c,value:l,rule:o}:{status:"MISS",key:c,rule:o}}function Dt(e,t,n,r){e.set(t,n,1e3*r)}async function Vt(e,t,n,r){if(!t)return e;let o=e;for(const[e,a]of Object.entries(t)){o=be(o,e,await Ke(n,a,{collector:r}))}return o}var Lt={Source:["code","package","import","before","next","cache"],Transformer:["code","package","import","before","next","cache","mapping"],Destination:["code","package","import","before","next","cache"],Store:["code","package","import","cache"]},Ut=["config","env","validate","variables","examples","disabled","id","logger","mock","chainMocks"],Zt={Source:["primary"],Transformer:[],Destination:[],Store:[]},Ht=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Wt(e,t){const n=function(e){return new Set([...Lt[e],...Ut,...Zt[e]])}(t);for(const r of Object.keys(e))if(!n.has(r))return{ok:!1,code:"UNKNOWN_KEY",key:r,reason:`Unknown key "${r}" on ${t}. Allowed: ${[...n].sort().join(", ")}.`};const r=void 0!==e.package,o=void 0!==e.import,a=void 0!==e.code;return a&&"string"==typeof e.code?{ok:!1,code:"OBSOLETE_CODE_STRING",key:"code",reason:`code: "<name>" is no longer supported. Use import: "${e.code}" with the package field instead.`}:a&&("object"!=typeof e.code&&"function"!=typeof e.code||null===e.code||Array.isArray(e.code))?{ok:!1,code:"INVALID_CODE_SHAPE",key:"code",reason:"code must be an object ({ push, type?, init? }) or a resolved function value."}:a&&r?{ok:!1,code:"CONFLICT",key:"package",reason:"Cannot specify both `code` and `package`. Use one or the other."}:a&&o?{ok:!1,code:"CONFLICT",key:"import",reason:"Cannot specify both `code` and `import`."}:o&&!r?{ok:!1,code:"MISSING_PACKAGE",key:"import",reason:"`import` requires `package` to be set."}:!o||"string"==typeof e.import&&Ht.test(e.import)?{ok:!0}:{ok:!1,code:"INVALID_IMPORT",key:"import",reason:`import must match ${Ht.source}. Got: ${JSON.stringify(e.import)}.`}}function Bt(e,t){return"Transformer"===t&&(void 0===e.code&&void 0===e.package&&void 0===e.import&&(void 0!==e.before||void 0!==e.next||void 0!==e.cache||void 0!==e.mapping))}function qt(e){return 0===e.length?"// no output":e.map(Kt).join(";\n\n")}function Kt(e){const[t,...n]=e,r=n.map(Jt).join(", ");return"return"===t?r?`return ${r}`:"return":`${t}(${r})`}function Jt(e){return void 0===e?"undefined":null===e?"null":"function"==typeof e?"[Function]":JSON.stringify(e,null,2)}//# sourceMappingURL=index.js.map
1
+ "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,i=(e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})},a={};i(a,{Cache:()=>s,Collector:()=>c,Const:()=>T,Context:()=>u,Destination:()=>f,ENV_MARKER_PREFIX:()=>X,Elb:()=>d,FatalError:()=>Be,Hint:()=>C,Hooks:()=>m,Level:()=>y,Lifecycle:()=>E,Logger:()=>g,Mapping:()=>h,Matcher:()=>N,On:()=>v,REF_CODE_PREFIX:()=>J,REF_CONTRACT:()=>H,REF_ENV:()=>Z,REF_FLOW:()=>B,REF_SECRET:()=>q,REF_STORE:()=>K,REF_VAR_FULL:()=>U,REF_VAR_INLINE:()=>W,Request:()=>k,STEP_OPERATIVE_FIELDS:()=>Kt,Simulation:()=>_,Source:()=>$,Store:()=>x,Transformer:()=>b,Trigger:()=>S,WalkerOS:()=>A,anonymizeIP:()=>R,applyUpdate:()=>Bt,assign:()=>ie,branch:()=>P,buildCacheContext:()=>Ut,castToProperty:()=>We,castValue:()=>je,checkCache:()=>Zt,clone:()=>he,compileCache:()=>Wt,compileMatcher:()=>Rt,createBatchedPoster:()=>gt,createDestination:()=>Oe,createEvent:()=>Ae,createIngest:()=>I,createLogger:()=>De,createMockContext:()=>nt,createMockLogger:()=>tt,createRespond:()=>Pt,createTelemetryObserver:()=>ft,debounce:()=>Pe,deepMerge:()=>Se,defaultClickIds:()=>Ce,deleteByPath:()=>we,emitStep:()=>mt,fetchPackage:()=>_t,fetchPackageSchema:()=>Ct,filterValues:()=>Ue,flattenIncludeSections:()=>$e,formatOut:()=>Qt,getBrowser:()=>ht,getBrowserVersion:()=>vt,getByPath:()=>ve,getDeviceType:()=>kt,getEvent:()=>_e,getFlowSettings:()=>ne,getGrantedConsent:()=>xe,getHeaders:()=>at,getId:()=>Ne,getMappingEvent:()=>Ke,getMappingValue:()=>qe,getMarketingParameters:()=>Te,getNextSteps:()=>Lt,getOS:()=>bt,getOSVersion:()=>wt,getPlatform:()=>re,getSpanId:()=>Ee,isArguments:()=>ae,isArray:()=>se,isBoolean:()=>ce,isCommand:()=>le,isDefined:()=>ue,isElementOrDocument:()=>fe,isFunction:()=>pe,isNumber:()=>de,isObject:()=>me,isPathStepEntry:()=>Yt,isPropertyType:()=>Ve,isSameType:()=>ge,isSampled:()=>pt,isString:()=>ye,mcpError:()=>It,mcpResult:()=>Tt,mergeContractSchemas:()=>D,mergeMappingRule:()=>Ye,mockEnv:()=>Qe,packageNameToVariable:()=>te,parseUserAgent:()=>yt,processEventMapping:()=>Ge,requestToData:()=>rt,requestToParameter:()=>ot,resolveContracts:()=>z,resolveSetup:()=>st,resolveTelemetryOptions:()=>dt,setByPath:()=>be,stepId:()=>l,storeCache:()=>Ht,throttle:()=>Re,throwError:()=>M,transformData:()=>it,traverseEnv:()=>et,trim:()=>ct,tryCatch:()=>Ze,tryCatchAsync:()=>He,useHooks:()=>lt,validateStepEntry:()=>Xt,walkPath:()=>Q,wrapCondition:()=>jt,wrapFn:()=>xt,wrapValidate:()=>Ot}),module.exports=(e=a,((e,i,a,s)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of r(i))o.call(e,c)||c===a||t(e,c,{get:()=>i[c],enumerable:!(s=n(i,c))||s.enumerable});return e})(t({},"__esModule",{value:!0}),e));var s={},c={};function l(e,t){if("collector"===e)return"collector";if(!t)throw new Error(`stepId(${e}) requires an id`);return`${e}.${t}`}i(c,{stepId:()=>l});var u={},f={};function p(e,t){const n=e.destinations[t];if(!n)throw new Error(`Destination not found: ${t}`);return n}i(f,{getDestination:()=>p});var d={},m={},g={};i(g,{Level:()=>y});var y=(e=>(e[e.ERROR=0]="ERROR",e[e.WARN=1]="WARN",e[e.INFO=2]="INFO",e[e.DEBUG=3]="DEBUG",e))(y||{}),h={},v={},b={};function w(e,t){const n=e.transformers[t];if(!n)throw new Error(`Transformer not found: ${t}`);return n}i(b,{getTransformer:()=>w});var k={},$={};function j(e,t){const n=e.sources[t];if(!n)throw new Error(`Source not found: ${t}`);return n}i($,{getSource:()=>j});var x={};function O(e,t){const n=e.stores[t];if(!n)throw new Error(`Store not found: ${t}`);return n}i(x,{getStore:()=>O});var S={},E={},A={},_={},N={},C={},T={Utils:{Storage:{Local:"local",Session:"session",Cookie:"cookie"}}};function I(e){return{_meta:{hops:0,path:[e]}}}function P(e,t){return{event:e,next:t}}function R(e){return/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e)?e.replace(/\.\d+$/,".0"):""}function M(e){throw new Error(String(e))}var F=new Set(["description","examples","title","$comment"]);function z(e){const t={},n=new Set;function r(o){if(t[o])return t[o];n.has(o)&&M(`Circular extend chain detected: ${[...n,o].join(" → ")}`);const i=e[o];i||M(`Contract "${o}" not found`),n.add(o);let a={};if(i.extend){a=function(e,t){const n={};void 0===e.tagging&&void 0===t.tagging||(n.tagging=t.tagging??e.tagging);void 0===e.description&&void 0===t.description||(n.description=t.description??e.description);e.schema&&t.schema?n.schema=D(e.schema,t.schema):(e.schema||t.schema)&&(n.schema={...e.schema||t.schema});if(e.events||t.events){const r={},o=new Set([...Object.keys(e.events||{}),...Object.keys(t.events||{})]);for(const n of o){const o=e.events?.[n]||{},i=t.events?.[n]||{},a=new Set([...Object.keys(o),...Object.keys(i)]);r[n]={};for(const e of a){const t=o[e],a=i[e];r[n][e]=t&&a?D(t,a):{...t||a}}}n.events=r}return n}(r(i.extend),i)}else a={...i};if(delete a.extend,a.events&&(a.events=function(e){const t={};for(const n of Object.keys(e))if("*"!==n){t[n]={};for(const r of Object.keys(e[n]||{})){let o={};const i=e["*"]?.["*"];i&&(o=D(o,i));const a=e["*"]?.[r];a&&"*"!==r&&(o=D(o,a));const s=e[n]?.["*"];s&&"*"!==r&&(o=D(o,s));const c=e[n]?.[r];c&&(o=D(o,c)),t[n][r]=o}}e["*"]&&(t["*"]={...e["*"]});return t}(a.events)),a.events){const e={};for(const[t,n]of Object.entries(a.events)){e[t]={};for(const[r,o]of Object.entries(n))e[t][r]=L(o)}a.events=e}return n.delete(o),t[o]=a,a}for(const t of Object.keys(e))r(t);return t}function D(e,t){const n={...e};for(const r of Object.keys(t)){const o=e[r],i=t[r];"required"===r&&Array.isArray(o)&&Array.isArray(i)?n[r]=[...new Set([...o,...i])]:V(o)&&V(i)?n[r]=D(o,i):n[r]=i}return n}function L(e){const t={};for(const[n,r]of Object.entries(e))F.has(n)||(null===r||"object"!=typeof r||Array.isArray(r)?t[n]=r:t[n]=L(r));return t}function V(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}var U=/^\$var\.([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)$/,W=/\$var\.([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)/g,Z=/\$env\.([a-zA-Z_][a-zA-Z0-9_]*)(?::([^"}\s]*))?/g,H=/^\$contract\.([a-zA-Z_][a-zA-Z0-9_]*)(?:\.(.+))?$/,B=/^\$flow\.([a-zA-Z_][a-zA-Z0-9_]*)(?:\.([a-zA-Z0-9_.]+))?$/,K=/^\$store\.([a-zA-Z_][a-zA-Z0-9_]*)$/,q=/^\$secret\.([A-Z0-9_]+)$/,J="$code:";function G(...e){const t={};for(const n of e)n&&Object.assign(t,n);return t}var X="__WALKEROS_ENV:";function Y(e,t,n){const r=`$flow.${e}${t?`.${t}`:""}`;if("unknown-flow"===n)return`${r} cannot resolve: flow "${e}" does not exist in this config.`;return`${r} is empty. Set ${t?`flows.${e}.config.${t}`:`flows.${e}.config`}, or run \`walkeros deploy ${e}\` first.`}function Q(e,t,n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const i=r[e];if(null==o||"object"!=typeof o){const o=r.slice(0,e).join(".");M(`Path "${t}" not found in "${n}": "${i}" does not exist${o?` in "${o}"`:""}`)}const a=o;if(!(i in a)){const o=r.slice(0,e).join(".");M(`Path "${t}" not found in "${n}": "${i}" does not exist${o?` in "${o}"`:""}`)}o=a[i]}return o}function ee(e,t,n,r,o,i){if("string"==typeof e){const a=e.match(U);if(a){const e=a[1].split("."),s=e[0],c=e.slice(1).join(".");void 0===t[s]&&M(`Variable "${s}" not found`);const l=i??new Set;if(l.has(s)){M(`Cyclic $var reference: ${[...l,s].join(" -> ")}`)}let u;l.add(s);try{u=ee(t[s],t,n,r,o,l)}finally{l.delete(s)}return c&&(u=Q(u,c,`$var.${s}`)),u}const s=e.match(H);if(s&&r){const e=s[1],t=s[2];e in r||M(`Contract "${e}" not found`);let n=r[e];return t&&(n=Q(n,t,`$contract.${e}`)),n}const c=e.match(B);if(c){const t=c[1],r=c[2],i=!1===n?.strictFlowRefs;o||M(`$flow.${t}${r?`.${r}`:""} cannot be resolved without a flow resolver`);const a=o(t);if(!a){if(i)return n?.onWarning?.(Y(t,r,"unknown-flow")),e;M(`Flow "${t}" not found in $flow.${t}`)}let s=a;if(r)if(i){try{s=Q(s,r,`$flow.${t}`)}catch{return n?.onWarning?.(Y(t,r,"missing-key")),e}if(null==s||""===s)return n?.onWarning?.(Y(t,r,"missing-key")),e}else s=Q(s,r,`$flow.${t}`);return s}let l=e.replace(W,(e,a)=>{const s=a.split("."),c=s[0],l=s.slice(1).join(".");void 0===t[c]&&M(`Variable "${c}" not found`);const u=i??new Set;if(u.has(c)){M(`Cyclic $var reference: ${[...u,c].join(" -> ")}`)}let f;u.add(c);try{f=ee(t[c],t,n,r,o,u)}finally{u.delete(c)}if(l&&(f=Q(f,l,`$var.${c}`)),null===f||"string"!=typeof f&&"number"!=typeof f&&"boolean"!=typeof f){M(`Variable "${a}" resolves to non-scalar (${Array.isArray(f)?"array":typeof f}) and cannot be inlined into a string. Use it as a whole-string reference: "$var.${a}"`)}return String(f)});return l=l.replace(Z,(e,t,r)=>n?.deferred?void 0!==r?`${X}${t}:${r}`:`${X}${t}`:"undefined"!=typeof process&&void 0!==process.env?.[t]?process.env[t]:void 0!==r?r:void M(`Environment variable "${t}" not found and no default provided`)),l}if(Array.isArray(e))return e.map(e=>ee(e,t,n,r,o,i));if(null!==e&&"object"==typeof e){const a={};for(const[s,c]of Object.entries(e))a[s]=ee(c,t,n,r,o,i);return a}return e}function te(e){const t=e.startsWith("@"),n=e.replace("@","").replace(/[/-]/g,"_").split("_").filter(e=>e.length>0).map((e,t)=>0===t?e:e.charAt(0).toUpperCase()+e.slice(1)).join("");return t?"_"+n:n}function ne(e,t,n){const r=new Map,o=new Set,i=[],a=t=>{if(r.has(t))return r.get(t);const s=e.flows[t];if(s){if(o.has(t)){M(`Cyclic $flow reference: ${[...i,t].join(" -> ")}`)}o.add(t),i.push(t);try{const o=G(e.variables,s.variables),i=ee(s.config??{},o,n,void 0,a);return r.set(t,i),i}finally{o.delete(t),i.pop()}}},s=Object.keys(e.flows);t||(1===s.length?t=s[0]:M(`Multiple flows found (${s.join(", ")}). Please specify a flow.`));const c=e.flows[t];c||M(`Flow "${t}" not found. Available: ${s.join(", ")}`),o.add(t),i.push(t);try{return function(e,t,n,r){const o=JSON.parse(JSON.stringify(t));let i;if(e.contract){const o=G(e.variables,t.variables);i=z(ee(e.contract,o,n,void 0,r))}if(o.config){const a=G(e.variables,t.variables);o.config=ee(o.config,a,n,i,r)}if(o.sources)for(const[a,s]of Object.entries(o.sources)){const c=G(e.variables,t.variables,s.variables),l=ee(s.config,c,n,i,r),u=ee(s.env,c,n,i,r);o.sources[a]={package:s.package,import:s.import,config:l,env:u,primary:s.primary,variables:s.variables,before:s.before,next:s.next,cache:s.cache,validate:s.validate,code:s.code}}if(o.destinations)for(const[a,s]of Object.entries(o.destinations)){const c=G(e.variables,t.variables,s.variables),l=ee(s.config,c,n,i,r),u=ee(s.env,c,n,i,r);o.destinations[a]={package:s.package,import:s.import,config:l,env:u,variables:s.variables,before:s.before,next:s.next,cache:s.cache,validate:s.validate,code:s.code}}if(o.stores)for(const[a,s]of Object.entries(o.stores)){const c=G(e.variables,t.variables,s.variables),l=ee(s.config,c,n,i,r),u=ee(s.env,c,n,i,r);o.stores[a]={package:s.package,import:s.import,config:l,env:u,cache:s.cache,variables:s.variables,code:s.code}}if(o.transformers)for(const[a,s]of Object.entries(o.transformers)){const c=G(e.variables,t.variables,s.variables),l=ee(s.config,c,n,i,r),u=ee(s.env,c,n,i,r);o.transformers[a]={package:s.package,import:s.import,config:l,env:u,variables:s.variables,before:s.before,next:s.next,cache:s.cache,validate:s.validate,code:s.code}}if(o.collector){const a=G(e.variables,t.variables),s=ee(o.collector,a,n,i,r);o.collector=s}return o}(e,c,n,a)}finally{o.delete(t),i.pop()}}function re(e){const t=e.config?.platform;if("web"===t||"server"===t)return t;M('Flow must have config.platform set to "web" or "server"')}var oe={merge:!0,shallow:!0,extend:!0};function ie(e,t={},n={}){n={...oe,...n};const r=Object.entries(t).reduce((t,[r,o])=>{const i=e[r];return n.merge&&Array.isArray(i)&&Array.isArray(o)?t[r]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...i]):(n.extend||r in e)&&(t[r]=o),t},{});return n.shallow?{...e,...r}:(Object.assign(e,r),e)}function ae(e){return"[object Arguments]"===Object.prototype.toString.call(e)}function se(e){return Array.isArray(e)}function ce(e){return"boolean"==typeof e}function le(e){return"walker"===e}function ue(e){return void 0!==e}function fe(e){return!(!e||"object"!=typeof e)&&("body"in e||"tagName"in e)}function pe(e){return"function"==typeof e}function de(e){return"number"==typeof e&&!Number.isNaN(e)}function me(e){return"object"==typeof e&&null!==e&&!se(e)&&"[object Object]"===Object.prototype.toString.call(e)}function ge(e,t){return typeof e==typeof t}function ye(e){return"string"==typeof e}function he(e,t=new WeakMap){if("object"!=typeof e||null===e)return e;if(t.has(e))return t.get(e);const n=Object.prototype.toString.call(e);if("[object Object]"===n){const n={};t.set(e,n);for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=he(e[r],t));return n}if("[object Array]"===n){const n=[];return t.set(e,n),e.forEach(e=>{n.push(he(e,t))}),n}if("[object Date]"===n)return new Date(e.getTime());if("[object RegExp]"===n){const t=e;return new RegExp(t.source,t.flags)}return e}function ve(e,t="",n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const t=r[e];if("*"===t&&se(o)){const t=r.slice(e+1).join("."),i=[];for(const e of o){const r=ve(e,t,n);i.push(r)}return i}if(o=me(o)||se(o)?o[t]:void 0,void 0===o)break}return ue(o)?o:n}function be(e,t,n){if(!me(e))return e;const r=he(e),o=t.split(".");let i=r;for(let e=0;e<o.length;e++){const t=o[e];e===o.length-1?i[t]=n:(t in i&&"object"==typeof i[t]&&null!==i[t]||(i[t]={}),i=i[t])}return r}function we(e,t){if(!me(e)&&!se(e))return e;const n=he(e),r=t.split(".");let o=n;for(let e=0;e<r.length;e++){const t=r[e],i=e===r.length-1;if(se(o)){const e=Number(t);if(!Number.isInteger(e)||e<0||e>=o.length)return n;if(i)o.splice(e,1);else{const t=o[e];if(!me(t)&&!se(t))return n;o=t}}else if(i)delete o[t];else{const e=o[t];if(!me(e)&&!se(e))return n;o=e}}return n}var ke={data:e=>e.data,globals:e=>e.globals,context:e=>e.context,user:e=>e.user,source:e=>e.source,event:e=>({entity:e.entity,action:e.action,id:e.id,timestamp:e.timestamp,name:e.name,trigger:e.trigger,timing:e.timing})};function $e(e,t){const n={},r=t.includes("all")?Object.keys(ke):t;for(const t of r){const r=ke[t];if(!r)continue;const o=r(e);if(me(o))for(const[e,r]of Object.entries(o)){if(void 0===r)continue;const o="context"===t&&Array.isArray(r)?r[0]:r;n[`${t}_${e}`]=o}}return n}function je(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}function xe(e,t={},n={}){const r={...t,...n},o={};let i=!e||0===Object.keys(e).length;return Object.keys(r).forEach(t=>{r[t]&&(o[t]=!0,e&&e[t]&&(i=!0))}),!!i&&o}function Oe(e,t){const n={...e};return n.config=ie(e.config,t,{shallow:!0,merge:!0,extend:!0}),e.config.settings&&t.settings&&(n.config.settings=ie(e.config.settings,t.settings,{shallow:!0,merge:!0,extend:!0})),e.config.mapping&&t.mapping&&(n.config.mapping=ie(e.config.mapping,t.mapping,{shallow:!0,merge:!0,extend:!0})),n}function Se(e,t){if(!me(t))return e;for(const n of Object.keys(t)){const r=t[n];void 0!==r&&(me(r)&&me(e[n])?Se(e[n],r):e[n]=r)}return e}function Ee(){let e="";for(let t=0;t<16;t++)e+=(16*Math.random()|0).toString(16);return e}function Ae(e={}){const t=e.timestamp||(new Date).setHours(0,13,37,0),n=ie({name:"entity action",data:{string:"foo",number:1,boolean:!0,array:[0,"text",!1],not:void 0},context:{dev:["test",1]},globals:{lang:"elb"},custom:{completely:"random"},user:{id:"us3r",device:"c00k13",session:"s3ss10n"},nested:[{entity:"child",data:{is:"subordinated"}}],consent:{functional:!0},id:e.id||Ee(),trigger:"test",entity:"entity",action:"action",timestamp:t,timing:3.14,source:{type:"collector",schema:"4"}},e,{merge:!1});if(e.name){const[t,r]=e.name.split(" ")??[];t&&r&&(n.entity=t,n.action=r)}return n}function _e(e="entity action",t={}){const n=t.timestamp||(new Date).setHours(0,13,37,0),r={data:{id:"ers",name:"Everyday Ruck Snack",color:"black",size:"l",price:420}},o={data:{id:"cc",name:"Cool Cap",size:"one size",price:42}};return Ae({...{"cart view":{data:{currency:"EUR",value:2*r.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:{...r.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:r.data.price+o.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...r,context:{shopping:["checkout",0]},nested:[]},{entity:"product",...o,context:{shopping:["checkout",0]},nested:[]}],trigger:"load"},"order complete":{data:{id:"0rd3r1d",currency:"EUR",shipping:5.22,taxes:73.76,total:555},context:{shopping:["complete",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...r,context:{shopping:["complete",0]},nested:[]},{entity:"product",...o,context:{shopping:["complete",0]},nested:[]},{entity:"gift",data:{name:"Surprise"},context:{shopping:["complete",0]},nested:[]}],trigger:"load"},"page view":{data:{domain:"www.example.com",title:"walkerOS documentation",referrer:"https://www.walkeros.io/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...r,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...r,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...r.data,position:3,promo:!0},context:{shopping:["discover",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"promotion visible":{data:{name:"Setting up tracking easily",position:"hero"},context:{ab_test:["engagement",0]},globals:{pagegroup:"homepage"},trigger:"visible"},"session start":{data:{id:"s3ss10n",start:n,isNew:!0,count:1,runs:1,isStart:!0,storage:!0,referrer:"",device:"c00k13"},user:{id:"us3r",device:"c00k13",session:"s3ss10n",hash:"h4sh",address:"street number",email:"user@example.com",phone:"+49 123 456 789",userAgent:"Mozilla...",browser:"Chrome",browserVersion:"90",deviceType:"desktop",language:"de-DE",country:"DE",region:"HH",city:"Hamburg",zip:"20354",timezone:"Berlin",os:"walkerOS",osVersion:"1.0",screenSize:"1337x420",ip:"127.0.0.0",internal:!0,custom:"value"}}}[e],...t,name:e})}function Ne(e=6,t){if(t){const n=t.length;let r="";for(let o=0;o<e;o++)r+=t[Math.random()*n|0];return r}let n="";for(let t=36;n.length<e;)n+=(Math.random()*t|0).toString(t);return n}var Ce=[{param:"gclid",platform:"google"},{param:"wbraid",platform:"google"},{param:"gbraid",platform:"google"},{param:"dclid",platform:"google"},{param:"gclsrc",platform:"google"},{param:"fbclid",platform:"meta"},{param:"igshid",platform:"meta"},{param:"msclkid",platform:"microsoft"},{param:"ttclid",platform:"tiktok"},{param:"twclid",platform:"twitter"},{param:"li_fat_id",platform:"linkedin"},{param:"epik",platform:"pinterest"},{param:"sclid",platform:"snapchat"},{param:"sccid",platform:"snapchat"},{param:"rdt_cid",platform:"reddit"},{param:"qclid",platform:"quora"},{param:"yclid",platform:"yandex"},{param:"ymclid",platform:"yandex"},{param:"ysclid",platform:"yandex"},{param:"dicbo",platform:"outbrain"},{param:"obclid",platform:"outbrain"},{param:"tblci",platform:"taboola"},{param:"mc_cid",platform:"mailchimp"},{param:"mc_eid",platform:"mailchimp"},{param:"_kx",platform:"klaviyo"},{param:"_hsenc",platform:"hubspot"},{param:"_hsmi",platform:"hubspot"},{param:"s_kwcid",platform:"adobe"},{param:"ef_id",platform:"adobe"},{param:"mkt_tok",platform:"adobe"},{param:"irclickid",platform:"impact"},{param:"cjevent",platform:"cj"},{param:"_branch_match_id",platform:"branch"}];function Te(e,t={},n=[]){const r={};Object.entries(ie({utm_campaign:"campaign",utm_content:"content",utm_medium:"medium",utm_source:"source",utm_term:"term"},t)).forEach(([t,n])=>{const o=e.searchParams.get(t);o&&(r[n]=o)});const o=n.length?function(e){const t=new Map(e.map(e=>[e.param,e.platform])),n=new Set(Ce.map(e=>e.param));return[...Ce.map(e=>t.has(e.param)?{param:e.param,platform:t.get(e.param)}:e),...e.filter(e=>!n.has(e.param))]}(n):Ce,i=new Map;e.searchParams.forEach((e,t)=>{e&&i.set(t.toLowerCase(),e)});for(const e of o){const t=i.get(e.param);t&&(r[e.param]=t,r.clickId||(r.clickId=e.param,r.platform=e.platform))}return r}function Ie(e,t){return"number"==typeof e?{wait:e}:e?{wait:e.wait??t,size:e.size,age:e.age}:{wait:t}}function Pe(e,t=1e3,n=!1){const{wait:r,size:o,age:i}=Ie(t,1e3);let a,s,c=null,l=null,u=!1,f=[],p=0;const d=()=>{c&&(clearTimeout(c),c=null),l&&(clearTimeout(l),l=null),p=0,s=void 0},m=()=>{const t=s,n=f;if(d(),f=[],t)return a=e(...t),n.forEach(e=>e(a)),a;n.forEach(e=>e(void 0))},g=(...t)=>new Promise(d=>{const g=n&&!u;if(s=t,p+=1,f.push(d),c&&clearTimeout(c),c=setTimeout(()=>{c=null,n&&!u||m()},r),void 0===i||l||(l=setTimeout(()=>{l=null,m()},i)),void 0!==o&&p>=o)m();else if(g){u=!0,a=e(...t);const n=f;f=[],n.forEach(e=>e(a))}});return g.flush=()=>s||0!==f.length?new Promise(e=>{f.push(e),m()}):Promise.resolve(void 0),g.cancel=()=>{const e=f;f=[],d(),e.forEach(e=>e(void 0))},g.size=()=>p,g}function Re(e,t=1e3){const{wait:n}=Ie(t,1e3);let r=null;return function(...t){if(null===r)return r=setTimeout(()=>{r=null},n),e(...t)}}function Me(e){return{message:e.message,name:e.name,stack:e.stack,cause:e.cause}}function Fe(e,t){let n,r={};return e instanceof Error?(n=e.message,r.error=Me(e)):n=e,void 0!==t&&(t instanceof Error?r.error=Me(t):"object"==typeof t&&null!==t?(r={...r,...t},"error"in r&&r.error instanceof Error&&(r.error=Me(r.error))):r.value=t),{message:n,context:r}}var ze=(e,t,n,r)=>{const o=`${y[e]}${r.length>0?` [${r.join(":")}]`:""}`,i=Object.keys(n).length>0,a=0===e?console.error:1===e?console.warn:console.log;i?a(o,t,n):a(o,t)};function De(e={}){return Le({level:void 0!==e.level?function(e){return"string"==typeof e?y[e]:e}(e.level):0,handler:e.handler,jsonHandler:e.jsonHandler,scope:[]})}function Le(e){const{level:t,handler:n,jsonHandler:r,scope:o}=e,i=(e,r,i)=>{if(e<=t){const t=Fe(r,i);n?n(e,t.message,t.context,o,ze):ze(e,t.message,t.context,o)}};return{error:(e,t)=>i(0,e,t),warn:(e,t)=>i(1,e,t),info:(e,t)=>i(2,e,t),debug:(e,t)=>i(3,e,t),throw:(e,t)=>{const r=Fe(e,t);throw n?n(0,r.message,r.context,o,ze):ze(0,r.message,r.context,o),new Error(r.message)},json:e=>{r?r(e):console.log(JSON.stringify(e,null,2))},scope:e=>Le({level:t,handler:n,jsonHandler:r,scope:[...o,e]})}}function Ve(e){return ce(e)||ye(e)||de(e)||!ue(e)||se(e)&&e.every(Ve)||me(e)&&Object.values(e).every(Ve)}function Ue(e){return ce(e)||ye(e)||de(e)?e:ae(e)?Ue(Array.from(e)):se(e)?e.map(e=>Ue(e)).filter(e=>void 0!==e):me(e)?Object.entries(e).reduce((e,[t,n])=>{const r=Ue(n);return void 0!==r&&(e[t]=r),e},{}):void 0}function We(e){return Ve(e)?e:void 0}function Ze(e,t,n){return function(...r){try{return e(...r)}catch(e){if(!t)return;return t(e)}finally{n?.()}}}function He(e,t,n){return async function(...r){try{return await e(...r)}catch(e){if(!t)return;return await t(e)}finally{await(n?.())}}}var Be=class e extends Error{constructor(t,n){super(t,n),this.name="FatalError",Object.setPrototypeOf(this,e.prototype)}};async function Ke(e,t,n){const[r,o]=(e.name||"").split(" ");if(!t||!r||!o)return{};let i,a="",s=r,c=o;const l=t=>{if(!t)return;return(se(t)?t:[t]).find(t=>{if(!t.condition)return!0;if(!n)return Boolean(t.condition(e,void 0));const r={event:e,mapping:t,collector:n,logger:n.logger,consent:me(e)&&e.consent||n.consent};return Boolean(t.condition(e,r))})};t[s]||(s="*");const u=t[s];return u&&(u[c]||(c="*"),i=l(u[c])),i||(s="*",c="*",i=l(t[s]?.[c])),i&&(a=`${s} ${c}`),{eventMapping:i,mappingKey:a}}async function qe(e,t={},n={}){if(!ue(e))return;const r=me(e)&&e.consent||n.consent||n.collector?.consent,o=n.event??(me(e)?e:{});if(!n.collector)throw new Error("getMappingValue: context.collector is required");const i={event:o,mapping:t,collector:n.collector,logger:n.collector.logger,consent:r},a=se(t)?t:[t];for(const t of a){const r=await He(Je,e=>{if(e instanceof Be)throw e;n.collector&&n.collector.status.failed++,i.logger.error("mapping processing failed",{event:o,error:e})})(e,t,{...i,mapping:t});if(ue(r))return r}}async function Je(e,t,n){return(se(t)?t:[t]).reduce(async(t,r)=>{const o=await t;if(o)return o;const i=ye(r)?{key:r}:r;if(!Object.keys(i).length)return;const{condition:a,consent:s,fn:c,key:l,loop:u,map:f,set:p,validate:d,value:m}=i,g={...n,mapping:r};if(a&&!await He(a,e=>{if(e instanceof Be)throw e;return g.logger.error("mapping condition failed",{event:g.event,error:e}),!1})(e,g))return;if(s&&!xe(s,g.consent))return m;let y=ue(m)?m:e;if(c&&(y=await He(c,e=>{if(e instanceof Be)throw e;g.logger.error("mapping fn failed",{event:g.event,error:e})})(e,g)),l&&(y=ve(e,l,m)),u){const[t,n]=u,r="this"===t?[e]:await qe(e,t,g);se(r)&&(y=(await Promise.all(r.map(e=>qe(e,n,g)))).filter(ue))}else f?y=await Object.entries(f).reduce(async(t,[n,r])=>{const o=await t,i=await qe(e,r,g);return ue(i)&&(o[n]=i),o},Promise.resolve({})):p&&(y=await Promise.all(p.map(t=>Je(e,t,g))));d&&!await He(d,e=>{if(e instanceof Be)throw e;return g.logger.error("mapping validate failed",{event:g.event,error:e}),!1})(y,g)&&(y=void 0);const h=We(y);return ue(h)?h:We(m)},Promise.resolve(void 0))}async function Ge(e,t,n){t.policy&&await Promise.all(Object.entries(t.policy).map(async([t,r])=>{const o=await qe(e,r,{collector:n,event:e});e=be(e,t,o)}));const{eventMapping:r,mappingKey:o}=await Ke(e,t.mapping,n);r?.policy&&await Promise.all(Object.entries(r.policy).map(async([t,r])=>{const o=await qe(e,r,{collector:n,event:e});e=be(e,t,o)}));let i=t.data&&await qe(e,t.data,{collector:n,event:e});const a=Boolean(r?.silent);if(r){if(r.ignore)return{event:e,data:i,mapping:r,mappingKey:o,ignore:!0,silent:a};if(r.name&&(e.name=r.name),r.data){const t=r.data&&await qe(e,r.data,{collector:n,event:e});i=me(i)&&me(t)?ie(i,t):t}}const s=r?.include??t.include;if(s&&s.length>0){const t=$e(e,s);Object.keys(t).length>0&&(i=me(i)?ie(t,i):i??t)}if(r?.remove&&me(i))for(const e of r.remove)i=we(i,e);return{event:e,data:i,mapping:r,mappingKey:o,ignore:!1,silent:a}}function Xe(e,t){for(const n of Object.keys(t)){const r=t[n];if(void 0===r)continue;if(null===r){delete e[n];continue}const o=e[n];me(r)&&me(o)?Xe(o,r):e[n]=r}return e}function Ye(e,t){if(void 0===t.extend&&void 0===t.remove)return he(t);const n={...he(e)};if(t.extend){Xe(n,{...t.extend})}return delete n.extend,t.remove?n.remove=[...t.remove]:delete n.remove,n}function Qe(e,t){const n=(e,r=[])=>new Proxy(e,{get(e,o){const i=e[o],a=[...r,o];return"function"==typeof i?i.prototype&&i.prototype.constructor===i?i:(...e)=>{const r=t(a,e,i);if(r&&"object"==typeof r)return n(r,a);const o=i(...e);return o&&"object"==typeof o?n(o,a):r}:i&&"object"==typeof i?n(i,a):i}});return n(e)}function et(e,t){const n=(e,r=[])=>{if(!e||"object"!=typeof e)return e;const o=Array.isArray(e)?[]:{};for(const[i,a]of Object.entries(e)){const e=[...r,i];Array.isArray(o)?o[Number(i)]=t(a,e):o[i]=t(a,e),a&&"object"==typeof a&&"function"!=typeof a&&(Array.isArray(o)?o[Number(i)]=n(a,e):o[i]=n(a,e))}return o};return n(e)}function tt(){const e=[],t=jest.fn(e=>{const t=e instanceof Error?e.message:e;throw new Error(t)}),n=jest.fn(t=>{const n=tt();return e.push(n),n});return{error:jest.fn(),warn:jest.fn(),info:jest.fn(),debug:jest.fn(),throw:t,json:jest.fn(),scope:n,scopedLoggers:e}}function nt(e={}){return{collector:{},config:{},env:{},logger:tt(),id:"test",ingest:I("test"),...e}}function rt(e){const t=String(e),n=t.split("?")[1]||t;return Ze(()=>{const e=new URLSearchParams(n),t={};return e.forEach((e,n)=>{const r=n.split(/[[\]]+/).filter(Boolean);let o=t;r.forEach((t,n)=>{const i=n===r.length-1;if(se(o)){const a=parseInt(t,10);i?o[a]=je(e):(o[a]=o[a]||(isNaN(parseInt(r[n+1],10))?{}:[]),o=o[a])}else me(o)&&(i?o[t]=je(e):(o[t]=o[t]||(isNaN(parseInt(r[n+1],10))?{}:[]),o=o[t]))})}),t})()}function ot(e){if(!e)return"";const t=[],n=encodeURIComponent;function r(e,o){null!=o&&(se(o)?o.forEach((t,n)=>r(`${e}[${n}]`,t)):me(o)?Object.entries(o).forEach(([t,n])=>r(`${e}[${t}]`,n)):t.push(`${n(e)}=${n(String(o))}`))}return"object"!=typeof e?n(e):(Object.entries(e).forEach(([e,t])=>r(e,t)),t.join("&"))}function it(e){return void 0===e||ge(e,"")?e:JSON.stringify(e)}function at(e={}){return ie({"Content-Type":"application/json; charset=utf-8"},e)}function st(e,t){return!1===e||void 0===e?null:!0===e?t:{...t,...e}}function ct(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function lt(e,t,n,r){const o=e;return function(...e){let i;const a="pre"+t,s="post"+t,c=n[a],l=n[s],u=(e,t)=>{r?r.warn(e,{error:t}):console.warn(e,t)};if(c)try{i=c({fn:o},...e)}catch(t){u(`Hook ${String(a)} failed, falling back to original function`,t),i=o(...e)}else i=o(...e);if(l)try{i=l({fn:o,result:i},...e)}catch(e){u(`Hook ${String(s)} failed, keeping original result`,e)}return i}}function ut(e,t){if(t>=1)return!0;if(t<=0)return!1;return function(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=t+((t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24))>>>0;return t>>>0}(e)/4294967295<t}function ft(e,t){const n="function"==typeof t?t:()=>t;return function(t){const r=n();if(!r)return;const o=r.level??"standard";if("off"===o)return;const i=r.sample,a="number"==typeof i&&Number.isFinite(i)?i:1;if(t.eventId&&!ut(t.eventId,a))return;const s=r.includeIn??"trace"===o,c=r.includeOut??"trace"===o,l=r.includeMappingKey??"trace"===o,u={...t};s||delete u.inEvent,c||delete u.outEvent,l||delete u.mappingKey,"trace"!==o&&u.error?.message&&u.error.message.length>256&&(u.error={...u.error,message:u.error.message.slice(0,256)+"…"});try{e(u)}catch{}}}function pt(e,t){return ut(e,t)}function dt(e){const t=e.env??("undefined"!=typeof process?process.env:{}),n=e.now??(()=>Date.now()),r=t.WALKEROS_TRACE_UNTIL;if("string"==typeof r&&r.length>0){const t=Date.parse(r);if(!Number.isNaN(t)&&t>n())return{flowId:e.flowId,level:"trace",includeIn:!0,includeOut:!0,sample:1}}const o=e.observe?.level??"standard";if("off"===o)return null;const i=e.observe?.sample??1;return{flowId:e.flowId,level:o,sample:i}}function mt(e,t){if(0===e.observers.size)return;const n=Array.from(e.observers);for(const e of n)try{e(t)}catch{}}function gt(e){const t=e.batchMs,n="number"==typeof t&&Number.isFinite(t)&&t>0?Math.floor(t):50,r=e.batchSize,o="number"==typeof r&&Number.isFinite(r)&&r>=1?Math.floor(r):50,i=e.fetch??((e,t)=>globalThis.fetch(e,t)),a=e.onError??(()=>{});let s=[],c=null;function l(){if(0===s.length)return;const t=s;s=[],c&&(clearTimeout(c),c=null),Promise.resolve().then(()=>i(e.url,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},body:JSON.stringify(t)})).then(e=>{e&&"object"==typeof e&&"ok"in e&&!e.ok&&a(new Error(`Observer responded ${e.status}`))}).catch(e=>{a(e)})}return e=>{s.push(e),s.length>=o?l():null===c&&(c=setTimeout(l,n))}}function yt(e){return e?{userAgent:e,browser:ht(e),browserVersion:vt(e),os:bt(e),osVersion:wt(e),deviceType:kt(e)}:{}}function ht(e){const t=[{name:"Edge",substr:"Edg"},{name:"Chrome",substr:"Chrome"},{name:"Safari",substr:"Safari",exclude:"Chrome"},{name:"Firefox",substr:"Firefox"},{name:"IE",substr:"MSIE"},{name:"IE",substr:"Trident"}];for(const n of t)if(e.includes(n.substr)&&(!n.exclude||!e.includes(n.exclude)))return n.name}function vt(e){const t=[/Edg\/([0-9]+)/,/Chrome\/([0-9]+)/,/Version\/([0-9]+).*Safari/,/Firefox\/([0-9]+)/,/MSIE ([0-9]+)/,/rv:([0-9]+).*Trident/];for(const n of t){const t=e.match(n);if(t)return t[1]}}function bt(e){const t=[{name:"Windows",substr:"Windows NT"},{name:"macOS",substr:"Mac OS X"},{name:"Android",substr:"Android"},{name:"iOS",substr:"iPhone OS"},{name:"Linux",substr:"Linux"}];for(const n of t)if(e.includes(n.substr))return n.name}function wt(e){const t=e.match(/(?:Windows NT|Mac OS X|Android|iPhone OS) ([0-9._]+)/);return t?t[1].replace(/_/g,"."):void 0}function kt(e){let t="Desktop";return/Tablet|iPad/i.test(e)?t="Tablet":/Mobi|Android|iPhone|iPod|BlackBerry|Opera Mini|IEMobile|WPDesktop/i.test(e)&&(t="Mobile"),t}function $t(e){return function(e){return/\breturn\b/.test(e)}(e)?e:`return ${e}`}function jt(e){const t=$t(e);return new Function("value","context",t)}function xt(e){const t=$t(e);return new Function("value","context",t)}function Ot(e){const t=$t(e);return new Function("value","context",t)}var St="https://cdn.jsdelivr.net/npm",Et="dist/walkerOS.json";function At(e){return"string"==typeof e||Array.isArray(e)&&e.every(e=>"string"==typeof e)?e:void 0}async function _t(e,t){const n=t?.version||"latest",r=t?.timeout||1e4,o=new AbortController,i=setTimeout(()=>o.abort(),r),a=o.signal,s=t?.client?{"X-Walkeros-Client":t.client}:void 0;try{if(t?.baseUrl){const r=`${t.baseUrl}/api/packages/${encodeURIComponent(e)}?version=${encodeURIComponent(n)}&expand=all`,o=await fetch(r,{signal:a,...s&&{headers:s}});if(!o.ok)throw new Error(`Failed to fetch ${r} (HTTP ${o.status})`);return function(e,t,n){const r=n.schemas||{},o=n.examples||{},i=n.hints,a=n.hintKeys??(i?Object.keys(i):[]),s=n.exampleSummaries??[],c=n.platform;return{packageName:n.package||e,version:"string"==typeof n.version?n.version:t,...void 0!==n.description&&{description:n.description},...void 0!==n.type&&{type:n.type},...void 0!==c&&{platform:c},schemas:r,examples:o,...void 0!==n.docs&&{docs:n.docs},...void 0!==n.source&&{source:n.source},...i&&Object.keys(i).length>0?{hints:i}:{},hintKeys:a,exampleSummaries:s}}(e,n,await o.json())}const r=`${St}/${e}@${n}`,o=await Nt(`${r}/package.json`,a,s);return function(e,t,n,r){const o=r.$meta||{},i=r.schemas||{},a=r.examples||{},s=r.hints,c=s?Object.keys(s):[],l=[],u=a.step||{};for(const[e,t]of Object.entries(u)){const n=t,r={name:e};"string"==typeof n?.description&&(r.description=n.description),l.push(r)}const f="string"==typeof o.docs?o.docs:void 0,p="string"==typeof o.source?o.source:void 0;return{packageName:e,version:"string"==typeof n.version?n.version:t,description:"string"==typeof n.description?n.description:void 0,type:"string"==typeof o.type?o.type:void 0,platform:At(o.platform),schemas:i,examples:a,...f?{docs:f}:{},...p?{source:p}:{},...s&&Object.keys(s).length>0?{hints:s}:{},hintKeys:c,exampleSummaries:l}}(e,n,o,await Nt(`${r}/${Et}`,a,s))}finally{clearTimeout(i)}}async function Nt(e,t,n){const r=await fetch(e,{signal:t,...n&&{headers:n}});if(!r.ok)throw new Error(`Failed to fetch ${e} (HTTP ${r.status})`);return await r.json()}async function Ct(e,t){const n=await _t(e,t);return{packageName:n.packageName,version:n.version,type:n.type,platform:n.platform,schemas:n.schemas,examples:n.examples,...n.hints?{hints:n.hints}:{}}}function Tt(e,t){const n=t?{...e,_hints:t}:e;return{content:[{type:"text",text:JSON.stringify(n,null,2)}],structuredContent:n}}function It(e,t){let n,r,o,i;if(e instanceof Error){n=e.message;const t=e;t.code&&(o=t.code),Array.isArray(t.details)&&(i=t.details)}else if("string"==typeof e)n=e;else if(e&&"object"==typeof e&&"issues"in e&&Array.isArray(e.issues)){const t=e.issues;n=t.map(e=>e.message).join("; "),r=t[0]?.path?.join(".")||void 0}else n=e&&"object"==typeof e&&"message"in e?String(e.message):"Unknown error";const a={error:n};return t&&(a.hint=t),r&&(a.path=r),o&&(a.code=o),i&&(a.details=i),{content:[{type:"text",text:JSON.stringify(a)}],structuredContent:a,isError:!0}}function Pt(e){let t=!1;return(n={})=>{t||(t=!0,e(n))}}function Rt(e){if(void 0===e||"*"===e)return()=>!0;if("and"in e){const t=e.and.map(Rt);return e=>t.every(t=>t(e))}if("or"in e){const t=e.or.map(Rt);return e=>t.some(t=>t(e))}return function(e){const{key:t,operator:n,value:r,not:o}=e,i=function(e,t){switch(e){case"eq":return e=>String(e??"")===t;case"contains":return e=>String(e??"").includes(t);case"prefix":return e=>String(e??"").startsWith(t);case"suffix":return e=>String(e??"").endsWith(t);case"regex":{const e=new RegExp(t);return t=>e.test(String(t??""))}case"gt":{const e=Number(t);return t=>Number(t)>e}case"lt":{const e=Number(t);return t=>Number(t)<e}case"exists":return e=>null!=e}}(n,r);return e=>{const n=ve(e,t),r=i(n);return o?!r:r}}(e)}function Mt(e){return Array.isArray(e)&&e.length>0&&e.every(e=>function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)&&("match"in e||"next"in e||"one"in e||"many"in e)}(e))}function Ft(e){return e.map(e=>{if("string"==typeof e)return{match:()=>!0,next:{type:"static",value:e}};if(Array.isArray(e))return{match:()=>!0,next:zt(e)??{type:"chain",value:[]}};const t=e;return{match:t.match?Rt(t.match):()=>!0,next:zt(t)??{type:"chain",value:[]}}})}function zt(e){if(null==e)return;if("string"==typeof e)return{type:"static",value:e};if(Array.isArray(e)){if(0===e.length)return;if(Mt(e))return zt({one:e});if(e.every(e=>"string"==typeof e))return{type:"chain",value:e};const t=[];for(const n of e){const e=zt(n);void 0!==e&&t.push(e)}if(0===t.length)return;return{type:"sequence",value:t}}const t=e;if("next"in t&&void 0!==t.next)return t.match?{type:"gate",match:Rt(t.match),next:zt(t.next)}:zt(t.next);if("one"in t&&t.one){const e=Ft(t.one);return t.match?{type:"gate",match:Rt(t.match),next:{type:"one",routes:e}}:{type:"one",routes:e}}if("many"in t&&t.many){const e=Ft(t.many);return t.match?{type:"gate",match:Rt(t.match),next:{type:"many",routes:e}}:{type:"many",routes:e}}return t.match?{type:"gate",match:Rt(t.match)}:void 0}var Dt=new WeakMap;function Lt(e,t={}){if(null==e)return[];let n;if("object"==typeof e){const t=Dt.get(e);t?n=t:(n=zt(e),n&&Dt.set(e,n))}else n=zt(e);if(!n)return[];const r=Vt(n,t);return void 0===r?[]:Array.isArray(r)?r:[r]}function Vt(e,t={}){if(e){if("static"===e.type)return e.value;if("chain"===e.type)return e.value;if("gate"===e.type){if(!e.match(t))return;return Vt(e.next,t)}if("sequence"===e.type){const n=[];for(const r of e.value){const e=Vt(r,t);void 0!==e&&(Array.isArray(e)?n.push(...e):n.push(e))}return n.length>0?n:void 0}if("many"===e.type){const n=[];for(const r of e.routes){if(!r.match(t))continue;const e=Vt(r.next,t);void 0!==e&&(Array.isArray(e)?n.push(...e):n.push(e))}return n.length>0?n:void 0}for(const n of e.routes)if(n.match(t))return Vt(n.next,t)}}function Ut(e,t){const n={ingest:e??{}};return void 0!==t&&(n.event=t),n}function Wt(e){return{stop:e.stop??!1,storeId:e.store,namespace:e.namespace,rules:e.rules.map(e=>({match:e.match?Rt(e.match):()=>!0,key:e.key,ttl:e.ttl,update:e.update}))}}async function Zt(e,t,n,r){const o=e.rules.find(e=>e.match(n));if(!o)return null;const i=o.key.map(e=>String(ve(n,e)??""));if(i.every(e=>""===e))return null;const a=i.join(":"),s=r??e.namespace,c=s?`${s}:${a}`:a,l=await t.get(c);return void 0!==l?{status:"HIT",key:c,value:l,rule:o}:{status:"MISS",key:c,rule:o}}function Ht(e,t,n,r){e.set(t,n,1e3*r)}async function Bt(e,t,n,r){if(!t)return e;let o=e;for(const[e,i]of Object.entries(t)){o=be(o,e,await qe(n,i,{collector:r}))}return o}var Kt={Source:["code","package","import","before","next","cache"],Transformer:["code","package","import","before","next","cache","mapping"],Destination:["code","package","import","before","next","cache"],Store:["code","package","import","cache"]},qt=["config","env","validate","variables","examples","disabled","id","logger","mock","chainMocks"],Jt={Source:["primary"],Transformer:[],Destination:[],Store:[]},Gt=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Xt(e,t){const n=function(e){return new Set([...Kt[e],...qt,...Jt[e]])}(t);for(const r of Object.keys(e))if(!n.has(r))return{ok:!1,code:"UNKNOWN_KEY",key:r,reason:`Unknown key "${r}" on ${t}. Allowed: ${[...n].sort().join(", ")}.`};const r=void 0!==e.package,o=void 0!==e.import,i=void 0!==e.code;return i&&"string"==typeof e.code?{ok:!1,code:"OBSOLETE_CODE_STRING",key:"code",reason:`code: "<name>" is no longer supported. Use import: "${e.code}" with the package field instead.`}:i&&("object"!=typeof e.code&&"function"!=typeof e.code||null===e.code||Array.isArray(e.code))?{ok:!1,code:"INVALID_CODE_SHAPE",key:"code",reason:"code must be an object ({ push, type?, init? }) or a resolved function value."}:i&&r?{ok:!1,code:"CONFLICT",key:"package",reason:"Cannot specify both `code` and `package`. Use one or the other."}:i&&o?{ok:!1,code:"CONFLICT",key:"import",reason:"Cannot specify both `code` and `import`."}:o&&!r?{ok:!1,code:"MISSING_PACKAGE",key:"import",reason:"`import` requires `package` to be set."}:!o||"string"==typeof e.import&&Gt.test(e.import)?{ok:!0}:{ok:!1,code:"INVALID_IMPORT",key:"import",reason:`import must match ${Gt.source}. Got: ${JSON.stringify(e.import)}.`}}function Yt(e,t){return"Transformer"===t&&(void 0===e.code&&void 0===e.package&&void 0===e.import&&(void 0!==e.before||void 0!==e.next||void 0!==e.cache||void 0!==e.mapping))}function Qt(e){return 0===e.length?"// no output":e.map(en).join(";\n\n")}function en(e){const[t,...n]=e,r=n.map(tn).join(", ");return"return"===t?r?`return ${r}`:"return":`${t}(${r})`}function tn(e){return void 0===e?"undefined":null===e?"null":"function"==typeof e?"[Function]":JSON.stringify(e,null,2)}//# sourceMappingURL=index.js.map