@walkeros/core 4.1.0 → 4.1.1-next-1779822275564
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/dev.d.mts +1042 -60
- package/dist/dev.d.ts +1042 -60
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/index.d.mts +310 -11
- package/dist/index.d.ts +310 -11
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -56,7 +56,31 @@ interface Rule<Settings = unknown> {
|
|
|
56
56
|
silent?: boolean;
|
|
57
57
|
name?: string;
|
|
58
58
|
policy?: Policy$1;
|
|
59
|
+
/**
|
|
60
|
+
* Merge mode (config layer): a partial Rule deep-merged onto the
|
|
61
|
+
* package-shipped default rule at the same key, instead of replacing it.
|
|
62
|
+
* Resolved at the consuming package's init via `mergeMappingRule`; not
|
|
63
|
+
* seen by the runtime evaluator. A `null` value clears an inherited field.
|
|
64
|
+
* Presence of `extend` or `remove` switches this rule from replace to merge.
|
|
65
|
+
*/
|
|
66
|
+
extend?: RulePatch<Settings>;
|
|
67
|
+
/**
|
|
68
|
+
* Output layer: dotted paths stripped from the produced data payload
|
|
69
|
+
* after evaluation, regardless of how each field was produced. Applied
|
|
70
|
+
* last, so it always wins.
|
|
71
|
+
*/
|
|
72
|
+
remove?: string[];
|
|
59
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* A partial Rule used by `Rule.extend`. Every field is optional, and a
|
|
76
|
+
* `null` value clears the inherited field (JSON merge-patch delete). The
|
|
77
|
+
* control fields `extend` and `remove` are excluded: a patch models only
|
|
78
|
+
* direct rule fields, matching what the runtime patch schema accepts.
|
|
79
|
+
*/
|
|
80
|
+
type RulePatchFields<Settings = unknown> = Omit<Rule<Settings>, 'extend' | 'remove'>;
|
|
81
|
+
type RulePatch<Settings = unknown> = {
|
|
82
|
+
[K in keyof RulePatchFields<Settings>]?: RulePatchFields<Settings>[K] | null;
|
|
83
|
+
};
|
|
60
84
|
interface Result$2 {
|
|
61
85
|
eventMapping?: Rule;
|
|
62
86
|
mappingKey?: string;
|
|
@@ -96,13 +120,14 @@ type mapping_Condition = Condition;
|
|
|
96
120
|
type mapping_Loop = Loop;
|
|
97
121
|
type mapping_Map = Map;
|
|
98
122
|
type mapping_Rule<Settings = unknown> = Rule<Settings>;
|
|
123
|
+
type mapping_RulePatch<Settings = unknown> = RulePatch<Settings>;
|
|
99
124
|
type mapping_Rules<T = Rule> = Rules<T>;
|
|
100
125
|
type mapping_Value = Value;
|
|
101
126
|
type mapping_ValueConfig = ValueConfig;
|
|
102
127
|
type mapping_ValueType = ValueType;
|
|
103
128
|
type mapping_Values = Values;
|
|
104
129
|
declare namespace mapping {
|
|
105
|
-
export type { mapping_Condition as Condition, Config$7 as Config, Context$6 as Context, Data$1 as Data, Fn$4 as Fn, mapping_Loop as Loop, mapping_Map as Map, Policy$1 as Policy, Result$2 as Result, mapping_Rule as Rule, mapping_Rules as Rules, Validate$1 as Validate, mapping_Value as Value, mapping_ValueConfig as ValueConfig, mapping_ValueType as ValueType, mapping_Values as Values };
|
|
130
|
+
export type { mapping_Condition as Condition, Config$7 as Config, Context$6 as Context, Data$1 as Data, Fn$4 as Fn, mapping_Loop as Loop, mapping_Map as Map, Policy$1 as Policy, Result$2 as Result, mapping_Rule as Rule, mapping_RulePatch as RulePatch, mapping_Rules as Rules, Validate$1 as Validate, mapping_Value as Value, mapping_ValueConfig as ValueConfig, mapping_ValueType as ValueType, mapping_Values as Values };
|
|
106
131
|
}
|
|
107
132
|
|
|
108
133
|
interface BaseCacheRule {
|
|
@@ -195,6 +220,74 @@ interface Ingest {
|
|
|
195
220
|
/** Create a fresh Ingest for a new pipeline invocation. */
|
|
196
221
|
declare function createIngest(sourceId: string): Ingest;
|
|
197
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
|
+
|
|
198
291
|
/** Identifies which kind of step a stepId belongs to. */
|
|
199
292
|
type StepKind = 'collector' | 'source' | 'transformer' | 'destination';
|
|
200
293
|
/**
|
|
@@ -379,6 +472,15 @@ interface Instance$6 {
|
|
|
379
472
|
stores: Stores$1;
|
|
380
473
|
globals: Properties;
|
|
381
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>;
|
|
382
484
|
logger: Instance$3;
|
|
383
485
|
on: OnConfig;
|
|
384
486
|
queue: Events;
|
|
@@ -1265,6 +1367,29 @@ declare namespace Flow {
|
|
|
1265
1367
|
* Consumed by the CLI bundler at build time.
|
|
1266
1368
|
*/
|
|
1267
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;
|
|
1268
1393
|
}
|
|
1269
1394
|
/**
|
|
1270
1395
|
* Reusable values referenced via `$var.name` (with optional deep paths).
|
|
@@ -1625,8 +1750,8 @@ declare namespace Flow {
|
|
|
1625
1750
|
* ```json
|
|
1626
1751
|
* {
|
|
1627
1752
|
* "default": { "globals": { ... }, "consent": { ... } },
|
|
1628
|
-
* "web": { "
|
|
1629
|
-
* "server": { "
|
|
1753
|
+
* "web": { "extend": "default", "events": { ... } },
|
|
1754
|
+
* "server": { "extend": "default", "events": { ... } }
|
|
1630
1755
|
* }
|
|
1631
1756
|
* ```
|
|
1632
1757
|
*/
|
|
@@ -1638,11 +1763,11 @@ declare namespace Flow {
|
|
|
1638
1763
|
* globals, context, custom, user, consent.
|
|
1639
1764
|
* Entity-action schemas live under `events`.
|
|
1640
1765
|
*
|
|
1641
|
-
* Use `
|
|
1766
|
+
* Use `extend` to inherit from another named contract (additive merge).
|
|
1642
1767
|
*/
|
|
1643
1768
|
interface ContractRule {
|
|
1644
1769
|
/** Inherit from another named contract entry. */
|
|
1645
|
-
|
|
1770
|
+
extend?: string;
|
|
1646
1771
|
/** Contract revision marker. */
|
|
1647
1772
|
tagging?: number;
|
|
1648
1773
|
/** Human-readable note. */
|
|
@@ -2772,6 +2897,14 @@ declare function getByPath(event: unknown, key?: string, defaultValue?: unknown)
|
|
|
2772
2897
|
* @returns A new object with the updated value.
|
|
2773
2898
|
*/
|
|
2774
2899
|
declare function setByPath<T = unknown>(obj: T, key: string, value: unknown): T;
|
|
2900
|
+
/**
|
|
2901
|
+
* Deletes a value in an object by a dot-notation string.
|
|
2902
|
+
* Returns a new object; the input is not mutated. No-op when the path is
|
|
2903
|
+
* absent or the target is neither an object nor an array. Numeric segments
|
|
2904
|
+
* index into arrays; a final numeric segment splices the element out so no
|
|
2905
|
+
* empty slot is left behind.
|
|
2906
|
+
*/
|
|
2907
|
+
declare function deleteByPath<T = unknown>(obj: T, key: string): T;
|
|
2775
2908
|
|
|
2776
2909
|
declare function flattenIncludeSections(event: DeepPartialEvent, sections: string[]): Record<string, unknown>;
|
|
2777
2910
|
|
|
@@ -3107,6 +3240,15 @@ declare function processEventMapping<T extends DeepPartialEvent | Event>(event:
|
|
|
3107
3240
|
silent: boolean;
|
|
3108
3241
|
}>;
|
|
3109
3242
|
|
|
3243
|
+
/**
|
|
3244
|
+
* Resolve a user mapping rule against a package-shipped default rule.
|
|
3245
|
+
* - No extend/remove → replace (clone of override; today's behavior).
|
|
3246
|
+
* - extend → partial rule deep-merged onto base (null clears a field).
|
|
3247
|
+
* - remove → carried onto the merged rule for eval-time output stripping.
|
|
3248
|
+
* The returned rule never contains `extend`.
|
|
3249
|
+
*/
|
|
3250
|
+
declare function mergeMappingRule(base: Rule, override: Rule): Rule;
|
|
3251
|
+
|
|
3110
3252
|
/**
|
|
3111
3253
|
* Environment mocking utilities for walkerOS destinations
|
|
3112
3254
|
*
|
|
@@ -3364,18 +3506,175 @@ declare class FatalError extends Error {
|
|
|
3364
3506
|
* A utility function that wraps a function with hooks.
|
|
3365
3507
|
*
|
|
3366
3508
|
* Pre/post hooks are user-supplied and may throw. A throwing hook must not
|
|
3367
|
-
* crash the surrounding pipeline
|
|
3509
|
+
* crash the surrounding pipeline. On failure, fall back to calling the
|
|
3368
3510
|
* original function (pre-hook) or keep the original result (post-hook).
|
|
3369
3511
|
*
|
|
3370
|
-
*
|
|
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.
|
|
3371
3517
|
* @param fn The function to wrap.
|
|
3372
3518
|
* @param name The name of the function.
|
|
3373
3519
|
* @param hooks The hooks to use.
|
|
3374
3520
|
* @param logger Optional logger for hook failure warnings. Falls back to
|
|
3375
3521
|
* `console.warn` when not provided.
|
|
3376
|
-
* @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
|
+
* Build a telemetry observer that projects FlowState records according to
|
|
3557
|
+
* level/sample/include flags and forwards them to `emit`. The observer is
|
|
3558
|
+
* synchronous, never throws (a throwing emit is swallowed), and does no
|
|
3559
|
+
* IO of its own. Designed to be added to `collector.observers` so the
|
|
3560
|
+
* runtime self-emission loop drives it.
|
|
3561
|
+
*/
|
|
3562
|
+
declare function createTelemetryObserver(emit: EmitFn, opts: TelemetryOptions): ObserverFn;
|
|
3563
|
+
/**
|
|
3564
|
+
* Convenience export: the internal sampling predicate so callers (and
|
|
3565
|
+
* tests) can verify the deterministic bucketing without importing the
|
|
3566
|
+
* private FNV-1a helper.
|
|
3567
|
+
*/
|
|
3568
|
+
declare function isSampled(eventId: string, sample: number): boolean;
|
|
3569
|
+
|
|
3570
|
+
/**
|
|
3571
|
+
* Runtime telemetry resolver.
|
|
3572
|
+
*
|
|
3573
|
+
* Converts a flow-side `Flow.Config.observe` block plus a runtime override
|
|
3574
|
+
* (the `WALKEROS_TRACE_UNTIL` env var) into a concrete `TelemetryOptions`
|
|
3575
|
+
* the collector hooks installer can consume.
|
|
3576
|
+
*
|
|
3577
|
+
* Resolution order (highest priority first):
|
|
3578
|
+
* 1. `WALKEROS_TRACE_UNTIL` env var, if present and parses to a future ISO
|
|
3579
|
+
* timestamp -> force level=trace, sample=1, include in/out payloads.
|
|
3580
|
+
* 2. The `observe` block from `flow.config?.observe`.
|
|
3581
|
+
* 3. A tier default of `{ level: 'standard' }`.
|
|
3582
|
+
*
|
|
3583
|
+
* The full poll-and-update plumbing that lets an operator flip
|
|
3584
|
+
* `WALKEROS_TRACE_UNTIL` without redeploying the container is intentionally
|
|
3585
|
+
* stubbed at the env-var seam: the deployment record's `trace_until` is
|
|
3586
|
+
* written by the app, but a sidecar/heartbeat that propagates it into the
|
|
3587
|
+
* container is out of scope for this phase. For now an operator sets the
|
|
3588
|
+
* env var directly, or the next deploy picks it up at boot.
|
|
3589
|
+
*/
|
|
3590
|
+
|
|
3591
|
+
interface ResolveTelemetryInput {
|
|
3592
|
+
flowId: string;
|
|
3593
|
+
/** From `flow.config?.observe`. May be undefined. */
|
|
3594
|
+
observe?: {
|
|
3595
|
+
level?: 'off' | 'standard' | 'trace';
|
|
3596
|
+
sample?: number;
|
|
3597
|
+
};
|
|
3598
|
+
/** Snapshot of `process.env` (or any equivalent). Test seam. */
|
|
3599
|
+
env?: Record<string, string | undefined>;
|
|
3600
|
+
/** Clock seam for tests. Defaults to `Date.now()`. */
|
|
3601
|
+
now?: () => number;
|
|
3602
|
+
}
|
|
3603
|
+
/**
|
|
3604
|
+
* Returns `TelemetryOptions` ready to pass to `createTelemetryObserver`,
|
|
3605
|
+
* or `null` if telemetry is disabled (`level === 'off'` with no trace
|
|
3606
|
+
* override). Callers should skip observer installation when this returns
|
|
3607
|
+
* null.
|
|
3608
|
+
*/
|
|
3609
|
+
declare function resolveTelemetryOptions(input: ResolveTelemetryInput): TelemetryOptions | null;
|
|
3610
|
+
|
|
3611
|
+
/**
|
|
3612
|
+
* Synchronously fans out a FlowState record to every registered observer
|
|
3613
|
+
* on the collector. Each call is wrapped in try/catch so a misbehaving
|
|
3614
|
+
* observer cannot crash the runtime; observers are advisory and must not
|
|
3615
|
+
* affect pipeline outcomes.
|
|
3616
|
+
*/
|
|
3617
|
+
declare function emitStep(collector: Instance$6, state: FlowState): void;
|
|
3618
|
+
|
|
3619
|
+
/**
|
|
3620
|
+
* Batched FlowState poster.
|
|
3621
|
+
*
|
|
3622
|
+
* Buffers FlowState records and flushes them to an HTTP endpoint either when
|
|
3623
|
+
* `batchMs` elapses since the first queued record, or when `batchSize` is
|
|
3624
|
+
* reached. Returns the emit callback that `createTelemetryObserver` consumes.
|
|
3625
|
+
*
|
|
3626
|
+
* Errors from the underlying fetch are swallowed (or routed through the
|
|
3627
|
+
* optional `onError` callback) so a transient observer outage cannot crash
|
|
3628
|
+
* the runtime.
|
|
3629
|
+
*
|
|
3630
|
+
* Uses the global `fetch` so the same primitive works in Node 18+, browsers,
|
|
3631
|
+
* and Edge runtimes. Tests may inject a stub via `opts.fetch`.
|
|
3632
|
+
*/
|
|
3633
|
+
|
|
3634
|
+
/**
|
|
3635
|
+
* Minimum HTTP response surface the poster touches. Anything that exposes
|
|
3636
|
+
* `ok` and `status` works. Decoupling from the DOM `Response` type lets the
|
|
3637
|
+
* helper run in Edge, browser, and Node-only test environments without
|
|
3638
|
+
* requiring `lib: dom` or a polyfill.
|
|
3639
|
+
*/
|
|
3640
|
+
interface PosterResponse {
|
|
3641
|
+
ok: boolean;
|
|
3642
|
+
status: number;
|
|
3643
|
+
}
|
|
3644
|
+
/**
|
|
3645
|
+
* Minimum fetch surface the poster needs. A subset of `typeof fetch` that
|
|
3646
|
+
* lets test harnesses pass a plain async function without dragging in the
|
|
3647
|
+
* Response/Request DOM types.
|
|
3648
|
+
*/
|
|
3649
|
+
type PosterFetch = (url: string, init: {
|
|
3650
|
+
method: string;
|
|
3651
|
+
headers: Record<string, string>;
|
|
3652
|
+
body: string;
|
|
3653
|
+
}) => Promise<PosterResponse>;
|
|
3654
|
+
interface BatchedPosterOptions {
|
|
3655
|
+
/** Absolute HTTP endpoint URL. POST with JSON array body. */
|
|
3656
|
+
url: string;
|
|
3657
|
+
/** Bearer token sent in the `Authorization` header. */
|
|
3658
|
+
token: string;
|
|
3659
|
+
/** Max time to wait before flushing the current batch. Default 50 ms. */
|
|
3660
|
+
batchMs?: number;
|
|
3661
|
+
/** Max records per batch. When reached, flushes immediately. Default 50. */
|
|
3662
|
+
batchSize?: number;
|
|
3663
|
+
/** Test seam. Defaults to the global `fetch`. */
|
|
3664
|
+
fetch?: PosterFetch;
|
|
3665
|
+
/** Called when the underlying POST rejects. Defaults to swallowing. */
|
|
3666
|
+
onError?: (err: unknown) => void;
|
|
3667
|
+
}
|
|
3668
|
+
/**
|
|
3669
|
+
* Build a batched emit callback. The returned function is synchronous, never
|
|
3670
|
+
* throws, and schedules an async flush in the background.
|
|
3671
|
+
*
|
|
3672
|
+
* Concurrency model: a single in-memory buffer plus a single pending timer.
|
|
3673
|
+
* When the timer fires (or `batchSize` is hit) the buffer is moved into a
|
|
3674
|
+
* local variable and reset, then POSTed. New records arriving during the in-
|
|
3675
|
+
* flight POST land in the next batch.
|
|
3377
3676
|
*/
|
|
3378
|
-
declare function
|
|
3677
|
+
declare function createBatchedPoster(opts: BatchedPosterOptions): (state: FlowState) => void;
|
|
3379
3678
|
|
|
3380
3679
|
/**
|
|
3381
3680
|
* Parses a user agent string to extract browser, OS, and device information.
|
|
@@ -3518,7 +3817,7 @@ declare function fetchPackageSchema(packageName: string, options?: {
|
|
|
3518
3817
|
}): Promise<WalkerOSPackageInfo>;
|
|
3519
3818
|
|
|
3520
3819
|
/**
|
|
3521
|
-
* Resolve all named contracts: process
|
|
3820
|
+
* Resolve all named contracts: process extend chains, expand wildcards,
|
|
3522
3821
|
* strip annotations from event schemas.
|
|
3523
3822
|
*
|
|
3524
3823
|
* Returns a fully resolved map where each contract entry has inherited
|
|
@@ -3672,4 +3971,4 @@ declare const REF_STORE: RegExp;
|
|
|
3672
3971
|
declare const REF_SECRET: RegExp;
|
|
3673
3972
|
declare const REF_CODE_PREFIX = "$code:";
|
|
3674
3973
|
|
|
3675
|
-
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, 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, mockEnv, packageNameToVariable, parseUserAgent, processEventMapping, requestToData, requestToParameter, resolveContracts, resolveSetup, setByPath, stepId, storeCache, throttle, throwError, transformData, traverseEnv, trim, tryCatch, tryCatchAsync, useHooks, validateStepEntry, walkPath, wrapCondition, wrapFn, wrapValidate };
|
|
3974
|
+
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, 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:()=>We,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:()=>zt,Simulation:()=>_,Source:()=>$,Store:()=>x,Transformer:()=>b,Trigger:()=>S,WalkerOS:()=>E,anonymizeIP:()=>I,applyUpdate:()=>Ft,assign:()=>ae,branch:()=>R,buildCacheContext:()=>Tt,castToProperty:()=>Ue,castValue:()=>$e,checkCache:()=>It,clone:()=>he,compileCache:()=>Rt,compileMatcher:()=>St,createDestination:()=>xe,createEvent:()=>Ae,createIngest:()=>T,createLogger:()=>ze,createMockContext:()=>Qe,createMockLogger:()=>Ye,createRespond:()=>Ot,debounce:()=>Te,deepMerge:()=>Oe,defaultClickIds:()=>Ce,fetchPackage:()=>wt,fetchPackageSchema:()=>$t,filterValues:()=>Le,flattenIncludeSections:()=>ke,formatOut:()=>Ht,getBrowser:()=>ct,getBrowserVersion:()=>lt,getByPath:()=>ve,getDeviceType:()=>pt,getEvent:()=>Ee,getFlowSettings:()=>ne,getGrantedConsent:()=>je,getHeaders:()=>rt,getId:()=>_e,getMappingEvent:()=>Be,getMappingValue:()=>qe,getMarketingParameters:()=>Ne,getNextSteps:()=>Nt,getOS:()=>ut,getOSVersion:()=>ft,getPlatform:()=>re,getSpanId:()=>Se,isArguments:()=>ie,isArray:()=>se,isBoolean:()=>ce,isCommand:()=>le,isDefined:()=>ue,isElementOrDocument:()=>fe,isFunction:()=>pe,isNumber:()=>de,isObject:()=>me,isPathStepEntry:()=>Zt,isPropertyType:()=>Ve,isSameType:()=>ge,isString:()=>ye,mcpError:()=>xt,mcpResult:()=>jt,mergeContractSchemas:()=>D,mockEnv:()=>Ge,packageNameToVariable:()=>te,parseUserAgent:()=>st,processEventMapping:()=>Je,requestToData:()=>et,requestToParameter:()=>tt,resolveContracts:()=>z,resolveSetup:()=>ot,setByPath:()=>be,stepId:()=>l,storeCache:()=>Mt,throttle:()=>Re,throwError:()=>M,transformData:()=>nt,traverseEnv:()=>Xe,trim:()=>at,tryCatch:()=>Ze,tryCatchAsync:()=>He,useHooks:()=>it,validateStepEntry:()=>Ut,walkPath:()=>Q,wrapCondition:()=>mt,wrapFn:()=>gt,wrapValidate:()=>yt}),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 extends chain detected: ${[...n,o].join(" → ")}`);const a=e[o];a||M(`Contract "${o}" not found`),n.add(o);let i={};if(a.extends){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.extends),a)}else i={...a};if(delete i.extends,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}var we={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 ke(e,t){const n={},r=t.includes("all")?Object.keys(we):t;for(const t of r){const r=we[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 $e(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}function je(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 xe(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 Oe(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])?Oe(e[n],r):e[n]=r)}return e}function Se(){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=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||Se(),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 Ee(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 _e(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 Ne(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(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,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 Pe(e,t){return"number"==typeof e?{wait:e}:e?{wait:e.wait??t,size:e.size,age:e.age}:{wait:t}}function Te(e,t=1e3,n=!1){const{wait:r,size:o,age:a}=Pe(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 Re(e,t=1e3){const{wait:n}=Pe(t,1e3);let r=null;return function(...t){if(null===r)return r=setTimeout(()=>{r=null},n),e(...t)}}function Ie(e){return{message:e.message,name:e.name,stack:e.stack,cause:e.cause}}function Me(e,t){let n,r={};return e instanceof Error?(n=e.message,r.error=Ie(e)):n=e,void 0!==t&&(t instanceof Error?r.error=Ie(t):"object"==typeof t&&null!==t?(r={...r,...t},"error"in r&&r.error instanceof Error&&(r.error=Ie(r.error))):r.value=t),{message:n,context:r}}var Fe=(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 ze(e={}){return De({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 De(e){const{level:t,handler:n,jsonHandler:r,scope:o}=e,a=(e,r,a)=>{if(e<=t){const t=Me(r,a);n?n(e,t.message,t.context,o,Fe):Fe(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=Me(e,t);throw n?n(0,r.message,r.context,o,Fe):Fe(0,r.message,r.context,o),new Error(r.message)},json:e=>{r?r(e):console.log(JSON.stringify(e,null,2))},scope:e=>De({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 Le(e){return ce(e)||ye(e)||de(e)?e:ie(e)?Le(Array.from(e)):se(e)?e.map(e=>Le(e)).filter(e=>void 0!==e):me(e)?Object.entries(e).reduce((e,[t,n])=>{const r=Le(n);return void 0!==r&&(e[t]=r),e},{}):void 0}function Ue(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 We=class e extends Error{constructor(t,n){super(t,n),this.name="FatalError",Object.setPrototypeOf(this,e.prototype)}};async function Be(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 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 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 He(Ke,e=>{if(e instanceof We)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 Ke(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 He(i,e=>{if(e instanceof We)throw e;return g.logger.error("mapping condition failed",{event:g.event,error:e}),!1})(e,g))return;if(s&&!je(s,g.consent))return m;let y=ue(m)?m:e;if(c&&(y=await He(c,e=>{if(e instanceof We)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,a=await qe(e,r,g);return ue(a)&&(o[n]=a),o},Promise.resolve({})):p&&(y=await Promise.all(p.map(t=>Ke(e,t,g))));d&&!await He(d,e=>{if(e instanceof We)throw e;return g.logger.error("mapping validate failed",{event:g.event,error:e}),!1})(y,g)&&(y=void 0);const h=Ue(y);return ue(h)?h:Ue(m)},Promise.resolve(void 0))}async function Je(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 Be(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 a=t.data&&await qe(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 qe(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=ke(e,s);Object.keys(t).length>0&&(a=me(a)?ae(t,a):a??t)}return{event:e,data:a,mapping:r,mappingKey:o,ignore:!1,silent:i}}function Ge(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 Xe(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 Ye(){const e=[],t=jest.fn(e=>{const t=e instanceof Error?e.message:e;throw new Error(t)}),n=jest.fn(t=>{const n=Ye();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 Qe(e={}){return{collector:{},config:{},env:{},logger:Ye(),id:"test",ingest:T("test"),...e}}function et(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 a=n===r.length-1;if(se(o)){const i=parseInt(t,10);a?o[i]=$e(e):(o[i]=o[i]||(isNaN(parseInt(r[n+1],10))?{}:[]),o=o[i])}else me(o)&&(a?o[t]=$e(e):(o[t]=o[t]||(isNaN(parseInt(r[n+1],10))?{}:[]),o=o[t]))})}),t})()}function tt(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 nt(e){return void 0===e||ge(e,"")?e:JSON.stringify(e)}function rt(e={}){return ae({"Content-Type":"application/json; charset=utf-8"},e)}function ot(e,t){return!1===e||void 0===e?null:!0===e?t:{...t,...e}}function at(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function it(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 st(e){return e?{userAgent:e,browser:ct(e),browserVersion:lt(e),os:ut(e),osVersion:ft(e),deviceType:pt(e)}:{}}function ct(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 lt(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 ut(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 ft(e){const t=e.match(/(?:Windows NT|Mac OS X|Android|iPhone OS) ([0-9._]+)/);return t?t[1].replace(/_/g,"."):void 0}function pt(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 dt(e){return function(e){return/\breturn\b/.test(e)}(e)?e:`return ${e}`}function mt(e){const t=dt(e);return new Function("value","context",t)}function gt(e){const t=dt(e);return new Function("value","context",t)}function yt(e){const t=dt(e);return new Function("value","context",t)}var ht="https://cdn.jsdelivr.net/npm",vt="dist/walkerOS.json";function bt(e){return"string"==typeof e||Array.isArray(e)&&e.every(e=>"string"==typeof e)?e:void 0}async function wt(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=`${ht}/${e}@${n}`,o=await kt(`${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:bt(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 kt(`${r}/${vt}`,i,s))}finally{clearTimeout(a)}}async function kt(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 $t(e,t){const n=await wt(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 jt(e,t){const n=t?{...e,_hints:t}:e;return{content:[{type:"text",text:JSON.stringify(n,null,2)}],structuredContent:n}}function xt(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 Ot(e){let t=!1;return(n={})=>{t||(t=!0,e(n))}}function St(e){if(void 0===e||"*"===e)return()=>!0;if("and"in e){const t=e.and.map(St);return e=>t.every(t=>t(e))}if("or"in e){const t=e.or.map(St);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 At(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 Et(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:_t(e)??{type:"chain",value:[]}};const t=e;return{match:t.match?St(t.match):()=>!0,next:_t(t)??{type:"chain",value:[]}}})}function _t(e){if(null==e)return;if("string"==typeof e)return{type:"static",value:e};if(Array.isArray(e)){if(0===e.length)return;if(At(e))return _t({one:e});if(e.every(e=>"string"==typeof e))return{type:"chain",value:e};const t=[];for(const n of e){const e=_t(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:St(t.match),next:_t(t.next)}:_t(t.next);if("one"in t&&t.one){const e=Et(t.one);return t.match?{type:"gate",match:St(t.match),next:{type:"one",routes:e}}:{type:"one",routes:e}}if("many"in t&&t.many){const e=Et(t.many);return t.match?{type:"gate",match:St(t.match),next:{type:"many",routes:e}}:{type:"many",routes:e}}return t.match?{type:"gate",match:St(t.match)}:void 0}var Ct=new WeakMap;function Nt(e,t={}){if(null==e)return[];let n;if("object"==typeof e){const t=Ct.get(e);t?n=t:(n=_t(e),n&&Ct.set(e,n))}else n=_t(e);if(!n)return[];const r=Pt(n,t);return void 0===r?[]:Array.isArray(r)?r:[r]}function Pt(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 Pt(e.next,t)}if("sequence"===e.type){const n=[];for(const r of e.value){const e=Pt(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=Pt(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 Pt(n.next,t)}}function Tt(e,t){const n={ingest:e??{}};return void 0!==t&&(n.event=t),n}function Rt(e){return{stop:e.stop??!1,storeId:e.store,namespace:e.namespace,rules:e.rules.map(e=>({match:e.match?St(e.match):()=>!0,key:e.key,ttl:e.ttl,update:e.update}))}}async function It(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 Mt(e,t,n,r){e.set(t,n,1e3*r)}async function Ft(e,t,n,r){if(!t)return e;let o=e;for(const[e,a]of Object.entries(t)){o=be(o,e,await qe(n,a,{collector:r}))}return o}var zt={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"]},Dt=["config","env","validate","variables","examples","disabled","id","logger","mock","chainMocks"],Vt={Source:["primary"],Transformer:[],Destination:[],Store:[]},Lt=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function Ut(e,t){const n=function(e){return new Set([...zt[e],...Dt,...Vt[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&&Lt.test(e.import)?{ok:!0}:{ok:!1,code:"INVALID_IMPORT",key:"import",reason:`import must match ${Lt.source}. Got: ${JSON.stringify(e.import)}.`}}function Zt(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 Ht(e){return 0===e.length?"// no output":e.map(Wt).join(";\n\n")}function Wt(e){const[t,...n]=e,r=n.map(Bt).join(", ");return"return"===t?r?`return ${r}`:"return":`${t}(${r})`}function Bt(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=t.level??"standard";if("off"===n)return()=>{};const r=t.sample??1,o=t.includeIn??"trace"===n,i=t.includeOut??"trace"===n,a=t.includeMappingKey??"trace"===n;return function(t){if(t.eventId&&!ut(t.eventId,r))return;const n={...t};o||delete n.inEvent,i||delete n.outEvent,a||delete n.mappingKey;try{e(n)}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){for(const n of e.observers)try{n(t)}catch{}}function gt(e){const t=e.batchMs??50,n=e.batchSize??50,r=e.fetch??((e,t)=>globalThis.fetch(e,t)),o=e.onError??(()=>{});let i=[],a=null;function s(){if(0===i.length)return;const t=i;i=[],a&&(clearTimeout(a),a=null),Promise.resolve().then(()=>r(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&&o(new Error(`Observer responded ${e.status}`))}).catch(e=>{o(e)})}return e=>{i.push(e),i.length>=n?s():null===a&&(a=setTimeout(s,t))}}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
|