@walkeros/core 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Core collector configuration interface
3
3
  */
4
- interface Config$5 {
4
+ interface Config$6 {
5
5
  /** Whether to run collector automatically */
6
6
  run?: boolean;
7
7
  /** Version for event tagging */
@@ -10,17 +10,13 @@ interface Config$5 {
10
10
  globalsStatic: Properties;
11
11
  /** Static session data even on a new run */
12
12
  sessionStatic: Partial<SessionData>;
13
- /** Enable verbose logging */
14
- verbose: boolean;
15
- /** Error handler */
16
- onError?: Error;
17
- /** Log handler */
18
- onLog?: Log;
13
+ /** Logger configuration */
14
+ logger?: Config$3;
19
15
  }
20
16
  /**
21
17
  * Initialization configuration that extends Config with initial state
22
18
  */
23
- interface InitConfig extends Partial<Config$5> {
19
+ interface InitConfig extends Partial<Config$6> {
24
20
  /** Initial consent state */
25
21
  consent?: Consent;
26
22
  /** Initial user data */
@@ -50,7 +46,7 @@ interface Sources {
50
46
  [id: string]: Instance;
51
47
  }
52
48
  interface Destinations$1 {
53
- [id: string]: Instance$1;
49
+ [id: string]: Instance$2;
54
50
  }
55
51
  type CommandType = 'action' | 'config' | 'consent' | 'context' | 'destination' | 'elb' | 'globals' | 'hook' | 'init' | 'link' | 'run' | 'user' | 'walker' | string;
56
52
  /**
@@ -69,9 +65,9 @@ interface PushFn$1 {
69
65
  * Command function signature - handles walker commands only
70
66
  */
71
67
  interface CommandFn {
72
- (command: 'config', config: Partial<Config$5>): Promise<PushResult>;
68
+ (command: 'config', config: Partial<Config$6>): Promise<PushResult>;
73
69
  (command: 'consent', consent: Consent): Promise<PushResult>;
74
- <T extends Types$2>(command: 'destination', destination: Init$1<T> | Instance$1<T>, config?: Config$4<T>): Promise<PushResult>;
70
+ <T extends Types$2>(command: 'destination', destination: Init$1<T> | Instance$2<T>, config?: Config$5<T>): Promise<PushResult>;
75
71
  <K extends keyof Functions>(command: 'hook', name: K, hookFn: Functions[K]): Promise<PushResult>;
76
72
  (command: 'on', type: Types$1, rules: SingleOrArray<Options>): Promise<PushResult>;
77
73
  (command: 'user', user: User): Promise<PushResult>;
@@ -83,11 +79,11 @@ interface CommandFn {
83
79
  }): Promise<PushResult>;
84
80
  (command: string, data?: unknown, options?: unknown): Promise<PushResult>;
85
81
  }
86
- interface Instance$2 {
82
+ interface Instance$3 {
87
83
  push: PushFn$1;
88
84
  command: CommandFn;
89
85
  allowed: boolean;
90
- config: Config$5;
86
+ config: Config$6;
91
87
  consent: Consent;
92
88
  count: number;
93
89
  custom: Properties;
@@ -96,6 +92,7 @@ interface Instance$2 {
96
92
  globals: Properties;
97
93
  group: string;
98
94
  hooks: Functions;
95
+ logger: Instance$1;
99
96
  on: OnConfig;
100
97
  queue: Events;
101
98
  round: number;
@@ -111,7 +108,7 @@ type collector_InitConfig = InitConfig;
111
108
  type collector_SessionData = SessionData;
112
109
  type collector_Sources = Sources;
113
110
  declare namespace collector {
114
- export type { collector_CommandFn as CommandFn, collector_CommandType as CommandType, Config$5 as Config, Destinations$1 as Destinations, collector_InitConfig as InitConfig, Instance$2 as Instance, PushContext$1 as PushContext, PushFn$1 as PushFn, collector_SessionData as SessionData, collector_Sources as Sources };
111
+ export type { collector_CommandFn as CommandFn, collector_CommandType as CommandType, Config$6 as Config, Destinations$1 as Destinations, collector_InitConfig as InitConfig, Instance$3 as Instance, PushContext$1 as PushContext, PushFn$1 as PushFn, collector_SessionData as SessionData, collector_Sources as Sources };
115
112
  }
116
113
 
117
114
  interface Contract$1 {
@@ -209,9 +206,9 @@ type Env$1<T extends TypesGeneric$1 = Types$2> = T['env'];
209
206
  /**
210
207
  * Inference helper: Extract Types from Instance
211
208
  */
212
- type TypesOf$1<I> = I extends Instance$1<infer T> ? T : never;
213
- interface Instance$1<T extends TypesGeneric$1 = Types$2> {
214
- config: Config$4<T>;
209
+ type TypesOf$1<I> = I extends Instance$2<infer T> ? T : never;
210
+ interface Instance$2<T extends TypesGeneric$1 = Types$2> {
211
+ config: Config$5<T>;
215
212
  queue?: Events;
216
213
  dlq?: DLQ;
217
214
  type?: string;
@@ -221,7 +218,7 @@ interface Instance$1<T extends TypesGeneric$1 = Types$2> {
221
218
  pushBatch?: PushBatchFn<T>;
222
219
  on?: OnFn;
223
220
  }
224
- interface Config$4<T extends TypesGeneric$1 = Types$2> {
221
+ interface Config$5<T extends TypesGeneric$1 = Types$2> {
225
222
  consent?: Consent;
226
223
  settings?: InitSettings$1<T>;
227
224
  data?: Value | Values;
@@ -229,39 +226,39 @@ interface Config$4<T extends TypesGeneric$1 = Types$2> {
229
226
  id?: string;
230
227
  init?: boolean;
231
228
  loadScript?: boolean;
229
+ logger?: Config$3;
232
230
  mapping?: Rules<Rule<Mapping$1<T>>>;
233
231
  policy?: Policy$1;
234
232
  queue?: boolean;
235
- verbose?: boolean;
236
- onError?: Error;
237
- onLog?: Log;
238
233
  }
239
- type PartialConfig$1<T extends TypesGeneric$1 = Types$2> = Config$4<Types$2<Partial<Settings$1<T>> | Settings$1<T>, Partial<Mapping$1<T>> | Mapping$1<T>, Env$1<T>>>;
234
+ type PartialConfig$1<T extends TypesGeneric$1 = Types$2> = Config$5<Types$2<Partial<Settings$1<T>> | Settings$1<T>, Partial<Mapping$1<T>> | Mapping$1<T>, Env$1<T>>>;
240
235
  interface Policy$1 {
241
236
  [key: string]: Value;
242
237
  }
243
238
  type Init$1<T extends TypesGeneric$1 = Types$2> = {
244
- code: Instance$1<T>;
245
- config?: Partial<Config$4<T>>;
239
+ code: Instance$2<T>;
240
+ config?: Partial<Config$5<T>>;
246
241
  env?: Partial<Env$1<T>>;
247
242
  };
248
243
  interface InitDestinations {
249
244
  [key: string]: Init$1<any>;
250
245
  }
251
246
  interface Destinations {
252
- [key: string]: Instance$1;
247
+ [key: string]: Instance$2;
253
248
  }
254
249
  interface Context$2<T extends TypesGeneric$1 = Types$2> {
255
- collector: Instance$2;
256
- config: Config$4<T>;
250
+ collector: Instance$3;
251
+ config: Config$5<T>;
257
252
  data?: Data$1;
258
253
  env: Env$1<T>;
254
+ logger: Instance$1;
259
255
  }
260
256
  interface InitContext<T extends TypesGeneric$1 = Types$2> {
261
- collector: Instance$2;
262
- config: Config$4<Types$2<Partial<Settings$1<T>>, Mapping$1<T>, Env$1<T>>>;
257
+ collector: Instance$3;
258
+ config: Config$5<Types$2<Partial<Settings$1<T>>, Mapping$1<T>, Env$1<T>>>;
263
259
  data?: Data$1;
264
260
  env: Env$1<T>;
261
+ logger: Instance$1;
265
262
  }
266
263
  interface PushContext<T extends TypesGeneric$1 = Types$2> extends Context$2<T> {
267
264
  mapping?: Rule<Mapping$1<T>>;
@@ -269,7 +266,7 @@ interface PushContext<T extends TypesGeneric$1 = Types$2> extends Context$2<T> {
269
266
  interface PushBatchContext<T extends TypesGeneric$1 = Types$2> extends Context$2<T> {
270
267
  mapping?: Rule<Mapping$1<T>>;
271
268
  }
272
- type InitFn<T extends TypesGeneric$1 = Types$2> = (context: InitContext<T>) => PromiseOrValue<void | false | Config$4<T>>;
269
+ type InitFn<T extends TypesGeneric$1 = Types$2> = (context: InitContext<T>) => PromiseOrValue<void | false | Config$5<T>>;
273
270
  type PushFn<T extends TypesGeneric$1 = Types$2> = (event: Event, context: PushContext<T>) => PromiseOrValue<void>;
274
271
  type PushBatchFn<T extends TypesGeneric$1 = Types$2> = (batch: Batch<Mapping$1<T>>, context: PushBatchContext<T>) => void;
275
272
  type PushEvent<Mapping = unknown> = {
@@ -286,7 +283,7 @@ interface Batch<Mapping> {
286
283
  type Data$1 = Property | undefined | Array<Property | undefined>;
287
284
  type Ref = {
288
285
  id: string;
289
- destination: Instance$1;
286
+ destination: Instance$2;
290
287
  };
291
288
  type Push$1 = {
292
289
  queue?: Events;
@@ -313,7 +310,7 @@ type destination_PushEvents<Mapping = unknown> = PushEvents<Mapping>;
313
310
  type destination_PushFn<T extends TypesGeneric$1 = Types$2> = PushFn<T>;
314
311
  type destination_Ref = Ref;
315
312
  declare namespace destination {
316
- export type { BaseEnv$1 as BaseEnv, destination_Batch as Batch, Config$4 as Config, Context$2 as Context, destination_DLQ as DLQ, Data$1 as Data, destination_Destinations as Destinations, Env$1 as Env, Init$1 as Init, destination_InitContext as InitContext, destination_InitDestinations as InitDestinations, destination_InitFn as InitFn, InitSettings$1 as InitSettings, Instance$1 as Instance, Mapping$1 as Mapping, PartialConfig$1 as PartialConfig, Policy$1 as Policy, Push$1 as Push, destination_PushBatchContext as PushBatchContext, destination_PushBatchFn as PushBatchFn, destination_PushContext as PushContext, destination_PushEvent as PushEvent, destination_PushEvents as PushEvents, destination_PushFn as PushFn, destination_Ref as Ref, Result$1 as Result, Settings$1 as Settings, Types$2 as Types, TypesGeneric$1 as TypesGeneric, TypesOf$1 as TypesOf };
313
+ export type { BaseEnv$1 as BaseEnv, destination_Batch as Batch, Config$5 as Config, Context$2 as Context, destination_DLQ as DLQ, Data$1 as Data, destination_Destinations as Destinations, Env$1 as Env, Init$1 as Init, destination_InitContext as InitContext, destination_InitDestinations as InitDestinations, destination_InitFn as InitFn, InitSettings$1 as InitSettings, Instance$2 as Instance, Mapping$1 as Mapping, PartialConfig$1 as PartialConfig, Policy$1 as Policy, Push$1 as Push, destination_PushBatchContext as PushBatchContext, destination_PushBatchFn as PushBatchFn, destination_PushContext as PushContext, destination_PushEvent as PushEvent, destination_PushEvents as PushEvents, destination_PushFn as PushFn, destination_Ref as Ref, Result$1 as Result, Settings$1 as Settings, Types$2 as Types, TypesGeneric$1 as TypesGeneric, TypesOf$1 as TypesOf };
317
314
  }
318
315
 
319
316
  interface EventFn<R = Promise<PushResult>> {
@@ -326,7 +323,7 @@ interface Fn$1<R = Promise<PushResult>, Config = unknown> extends EventFn<R>, Wa
326
323
  interface WalkerCommands<R = Promise<PushResult>, Config = unknown> {
327
324
  (event: 'walker config', config: Partial<Config>): R;
328
325
  (event: 'walker consent', consent: Consent): R;
329
- <T extends Types$2>(event: 'walker destination', destination: Init$1<T> | Instance$1<T>, config?: Config$4<T>): R;
326
+ <T extends Types$2>(event: 'walker destination', destination: Init$1<T> | Instance$2<T>, config?: Config$5<T>): R;
330
327
  <K extends keyof Functions>(event: 'walker hook', name: K, hookFn: Functions[K]): R;
331
328
  (event: 'walker on', type: Types$1, rules: SingleOrArray<Options>): R;
332
329
  (event: 'walker user', user: User): R;
@@ -361,7 +358,7 @@ declare namespace elb {
361
358
  * Platform-agnostic, runtime-focused.
362
359
  *
363
360
  * The Flow system enables "one config to rule them all" - a single
364
- * walkeros.config.json file that manages multiple environments
361
+ * walkeros.config.json file that manages multiple flows
365
362
  * (web_prod, web_stage, server_prod, etc.) with shared configuration,
366
363
  * variables, and reusable definitions.
367
364
  *
@@ -373,25 +370,68 @@ declare namespace elb {
373
370
  */
374
371
  type Primitive = string | number | boolean;
375
372
  /**
376
- * Complete multi-environment configuration.
377
- * This is the root type for walkeros.config.json files.
373
+ * Variables record type for interpolation.
374
+ * Used at Setup, Config, Source, and Destination levels.
375
+ */
376
+ type Variables = Record<string, Primitive>;
377
+ /**
378
+ * Definitions record type for reusable configurations.
379
+ * Used at Setup, Config, Source, and Destination levels.
380
+ */
381
+ type Definitions = Record<string, unknown>;
382
+ /**
383
+ * Packages configuration for build.
384
+ */
385
+ type Packages = Record<string, {
386
+ version?: string;
387
+ imports?: string[];
388
+ path?: string;
389
+ }>;
390
+ /**
391
+ * Web platform configuration.
392
+ *
393
+ * @remarks
394
+ * Presence of this key indicates web platform (browser-based tracking).
395
+ * Builds to IIFE format, ES2020 target, browser platform.
396
+ */
397
+ interface Web {
398
+ /**
399
+ * Window property name for collector instance.
400
+ * @default "collector"
401
+ */
402
+ windowCollector?: string;
403
+ /**
404
+ * Window property name for elb function.
405
+ * @default "elb"
406
+ */
407
+ windowElb?: string;
408
+ }
409
+ /**
410
+ * Server platform configuration.
411
+ *
412
+ * @remarks
413
+ * Presence of this key indicates server platform (Node.js).
414
+ * Builds to ESM format, Node18 target, node platform.
415
+ * Reserved for future server-specific options.
416
+ */
417
+ interface Server {
418
+ }
419
+ /**
420
+ * Complete multi-flow configuration.
421
+ * Root type for walkeros.config.json files.
378
422
  *
379
423
  * @remarks
380
- * The Setup interface represents the entire configuration file,
381
- * containing multiple named environments that can share variables
382
- * and definitions.
424
+ * If only one flow exists, it's auto-selected without --flow flag.
425
+ * Convention: use "default" as the flow name for single-flow configs.
383
426
  *
384
427
  * @example
385
428
  * ```json
386
429
  * {
387
430
  * "version": 1,
388
431
  * "$schema": "https://walkeros.io/schema/flow/v1.json",
389
- * "variables": {
390
- * "CURRENCY": "USD"
391
- * },
392
- * "environments": {
393
- * "web_prod": { "platform": "web", ... },
394
- * "server_prod": { "platform": "server", ... }
432
+ * "variables": { "CURRENCY": "USD" },
433
+ * "flows": {
434
+ * "default": { "web": {}, ... }
395
435
  * }
396
436
  * }
397
437
  * ```
@@ -399,141 +439,71 @@ type Primitive = string | number | boolean;
399
439
  interface Setup {
400
440
  /**
401
441
  * Configuration schema version.
402
- * Used for compatibility checks and migrations.
403
- *
404
- * @remarks
405
- * - Version 1: Initial Flow configuration system
406
- * - Future versions will be documented as they're released
407
442
  */
408
443
  version: 1;
409
444
  /**
410
- * JSON Schema reference for IDE validation and autocomplete.
411
- *
412
- * @remarks
413
- * When set, IDEs like VSCode will provide:
414
- * - Autocomplete for all fields
415
- * - Inline documentation
416
- * - Validation errors before deployment
417
- *
418
- * @example
419
- * "$schema": "https://walkeros.io/schema/flow/v1.json"
445
+ * JSON Schema reference for IDE validation.
446
+ * @example "https://walkeros.io/schema/flow/v1.json"
420
447
  */
421
448
  $schema?: string;
422
449
  /**
423
- * Shared variables for interpolation across all environments.
450
+ * Folders to include in the bundle output.
451
+ * These folders are copied to dist/ during bundle, making them available
452
+ * at runtime for both local and Docker execution.
424
453
  *
425
454
  * @remarks
426
- * Variables can be referenced using `${VAR_NAME:default}` syntax.
427
- * Resolution order:
428
- * 1. Environment variable (process.env.VAR_NAME)
429
- * 2. Config variable (config.variables.VAR_NAME)
430
- * 3. Inline default value
455
+ * Use for credential files, configuration, or other runtime assets.
456
+ * Paths are relative to the config file location.
457
+ * Default: `["./shared"]` if the folder exists, otherwise `[]`.
431
458
  *
432
459
  * @example
433
460
  * ```json
434
461
  * {
435
- * "variables": {
436
- * "CURRENCY": "USD",
437
- * "GA4_ID": "G-DEFAULT"
438
- * },
439
- * "environments": {
440
- * "prod": {
441
- * "collector": {
442
- * "globals": {
443
- * "currency": "${CURRENCY}"
444
- * }
445
- * }
446
- * }
447
- * }
462
+ * "include": ["./credentials", "./config"]
448
463
  * }
449
464
  * ```
450
465
  */
451
- variables?: Record<string, Primitive>;
466
+ include?: string[];
467
+ /**
468
+ * Shared variables for interpolation.
469
+ * Resolution: process.env > Config.variables > Setup.variables > inline default
470
+ * Syntax: ${VAR_NAME} or ${VAR_NAME:default}
471
+ */
472
+ variables?: Variables;
452
473
  /**
453
474
  * Reusable configuration definitions.
454
- *
455
- * @remarks
456
- * Definitions can be referenced using JSON Schema `$ref` syntax.
457
- * Useful for sharing mapping rules, common settings, etc.
458
- *
459
- * @example
460
- * ```json
461
- * {
462
- * "definitions": {
463
- * "gtag_base_mapping": {
464
- * "page": {
465
- * "view": { "name": "page_view" }
466
- * }
467
- * }
468
- * },
469
- * "environments": {
470
- * "prod": {
471
- * "destinations": {
472
- * "gtag": {
473
- * "config": {
474
- * "mapping": { "$ref": "#/definitions/gtag_base_mapping" }
475
- * }
476
- * }
477
- * }
478
- * }
479
- * }
480
- * }
481
- * ```
475
+ * Referenced via JSON Schema $ref syntax: { "$ref": "#/definitions/name" }
482
476
  */
483
- definitions?: Record<string, unknown>;
477
+ definitions?: Definitions;
484
478
  /**
485
- * Named environment configurations.
486
- *
487
- * @remarks
488
- * Each environment represents a deployment target:
489
- * - web_prod, web_stage, web_dev (client-side tracking)
490
- * - server_prod, server_stage (server-side collection)
491
- *
492
- * Environment names are arbitrary and user-defined.
493
- *
494
- * @example
495
- * ```json
496
- * {
497
- * "environments": {
498
- * "web_prod": {
499
- * "platform": "web",
500
- * "sources": { ... },
501
- * "destinations": { ... }
502
- * },
503
- * "server_prod": {
504
- * "platform": "server",
505
- * "destinations": { ... }
506
- * }
507
- * }
508
- * }
509
- * ```
479
+ * Named flow configurations.
480
+ * If only one flow exists, it's auto-selected.
510
481
  */
511
- environments: Record<string, Config$3>;
482
+ flows: Record<string, Config$4>;
512
483
  }
513
484
  /**
514
- * Single environment configuration.
485
+ * Single flow configuration.
515
486
  * Represents one deployment target (e.g., web_prod, server_stage).
516
487
  *
517
488
  * @remarks
518
- * This is the core runtime configuration used by `startFlow()`.
519
- * Platform-agnostic and independent of build/deployment tools.
489
+ * Platform is determined by presence of `web` or `server` key.
490
+ * Exactly one must be present.
520
491
  *
521
- * Extensions (build, docker, etc.) are added via `[key: string]: unknown`.
492
+ * Variables/definitions cascade: source/destination > config > setup
522
493
  */
523
- interface Config$3 {
494
+ interface Config$4 {
524
495
  /**
525
- * Target platform for this environment.
526
- *
527
- * @remarks
528
- * - `web`: Browser-based tracking (IIFE bundles, browser sources)
529
- * - `server`: Node.js server-side collection (CJS bundles, HTTP sources)
530
- *
531
- * This determines:
532
- * - Available packages (web-* vs server-*)
533
- * - Default build settings
534
- * - Template selection
496
+ * Web platform configuration.
497
+ * Presence indicates web platform (browser-based tracking).
498
+ * Mutually exclusive with `server`.
499
+ */
500
+ web?: Web;
501
+ /**
502
+ * Server platform configuration.
503
+ * Presence indicates server platform (Node.js).
504
+ * Mutually exclusive with `web`.
535
505
  */
536
- platform: 'web' | 'server';
506
+ server?: Server;
537
507
  /**
538
508
  * Source configurations (data capture).
539
509
  *
@@ -628,35 +598,19 @@ interface Config$3 {
628
598
  */
629
599
  collector?: InitConfig;
630
600
  /**
631
- * Environment-specific variables.
632
- *
633
- * @remarks
634
- * These override root-level variables for this specific environment.
635
- * Useful for environment-specific API keys, endpoints, etc.
636
- *
637
- * @example
638
- * ```json
639
- * {
640
- * "env": {
641
- * "API_ENDPOINT": "https://api.production.com",
642
- * "DEBUG": "false"
643
- * }
644
- * }
645
- * ```
601
+ * NPM packages to bundle.
646
602
  */
647
- env?: Record<string, string>;
603
+ packages?: Packages;
648
604
  /**
649
- * Extension point for package-specific fields.
650
- *
651
- * @remarks
652
- * Allows packages to add their own configuration fields:
653
- * - CLI adds `build` field (Bundle.Config)
654
- * - Docker adds `docker` field (Docker.Config)
655
- * - Lambda adds `lambda` field (Lambda.Config)
656
- *
657
- * Core doesn't validate these fields - packages handle validation.
605
+ * Flow-level variables.
606
+ * Override Setup.variables, overridden by source/destination variables.
658
607
  */
659
- [key: string]: unknown;
608
+ variables?: Variables;
609
+ /**
610
+ * Flow-level definitions.
611
+ * Extend Setup.definitions, overridden by source/destination definitions.
612
+ */
613
+ definitions?: Definitions;
660
614
  }
661
615
  /**
662
616
  * Source reference with inline package syntax.
@@ -685,6 +639,14 @@ interface SourceReference {
685
639
  * "package": "@walkeros/web-source-browser@latest"
686
640
  */
687
641
  package: string;
642
+ /**
643
+ * Resolved import variable name.
644
+ *
645
+ * @remarks
646
+ * Auto-resolved from packages[package].imports[0] during getFlowConfig().
647
+ * Can also be provided explicitly for advanced use cases.
648
+ */
649
+ code?: string;
688
650
  /**
689
651
  * Source-specific configuration.
690
652
  *
@@ -720,11 +682,21 @@ interface SourceReference {
720
682
  *
721
683
  * @remarks
722
684
  * The primary source's ELB function is returned by `startFlow()`.
723
- * Only one source should be marked as primary per environment.
685
+ * Only one source should be marked as primary per flow.
724
686
  *
725
687
  * @default false
726
688
  */
727
689
  primary?: boolean;
690
+ /**
691
+ * Source-level variables (highest priority in cascade).
692
+ * Overrides flow and setup variables.
693
+ */
694
+ variables?: Variables;
695
+ /**
696
+ * Source-level definitions (highest priority in cascade).
697
+ * Overrides flow and setup definitions.
698
+ */
699
+ definitions?: Definitions;
728
700
  }
729
701
  /**
730
702
  * Destination reference with inline package syntax.
@@ -744,6 +716,14 @@ interface DestinationReference {
744
716
  * "package": "@walkeros/web-destination-gtag@2.0.0"
745
717
  */
746
718
  package: string;
719
+ /**
720
+ * Resolved import variable name.
721
+ *
722
+ * @remarks
723
+ * Auto-resolved from packages[package].imports[0] during getFlowConfig().
724
+ * Can also be provided explicitly for advanced use cases.
725
+ */
726
+ code?: string;
747
727
  /**
748
728
  * Destination-specific configuration.
749
729
  *
@@ -785,23 +765,29 @@ interface DestinationReference {
785
765
  * Merged with default destination environment.
786
766
  */
787
767
  env?: unknown;
768
+ /**
769
+ * Destination-level variables (highest priority in cascade).
770
+ * Overrides flow and setup variables.
771
+ */
772
+ variables?: Variables;
773
+ /**
774
+ * Destination-level definitions (highest priority in cascade).
775
+ * Overrides flow and setup definitions.
776
+ */
777
+ definitions?: Definitions;
788
778
  }
789
779
 
780
+ type flow_Definitions = Definitions;
790
781
  type flow_DestinationReference = DestinationReference;
782
+ type flow_Packages = Packages;
791
783
  type flow_Primitive = Primitive;
784
+ type flow_Server = Server;
792
785
  type flow_Setup = Setup;
793
786
  type flow_SourceReference = SourceReference;
787
+ type flow_Variables = Variables;
788
+ type flow_Web = Web;
794
789
  declare namespace flow {
795
- export type { Config$3 as Config, flow_DestinationReference as DestinationReference, flow_Primitive as Primitive, flow_Setup as Setup, flow_SourceReference as SourceReference };
796
- }
797
-
798
- type Error = (error: unknown, state?: unknown) => void;
799
- type Log = (message: string, verbose?: boolean) => void;
800
-
801
- type handler_Error = Error;
802
- type handler_Log = Log;
803
- declare namespace handler {
804
- export type { handler_Error as Error, handler_Log as Log };
790
+ export type { Config$4 as Config, flow_Definitions as Definitions, flow_DestinationReference as DestinationReference, flow_Packages as Packages, flow_Primitive as Primitive, flow_Server as Server, flow_Setup as Setup, flow_SourceReference as SourceReference, flow_Variables as Variables, flow_Web as Web };
805
791
  }
806
792
 
807
793
  type AnyFunction$1<P extends unknown[] = never[], R = unknown> = (...args: P) => R;
@@ -820,6 +806,121 @@ declare namespace hooks {
820
806
  export type { AnyFunction$1 as AnyFunction, hooks_Functions as Functions, hooks_HookFn as HookFn };
821
807
  }
822
808
 
809
+ /**
810
+ * Log levels from most to least severe
811
+ */
812
+ declare enum Level {
813
+ ERROR = 0,
814
+ INFO = 1,
815
+ DEBUG = 2
816
+ }
817
+ /**
818
+ * Normalized error context extracted from Error objects
819
+ */
820
+ interface ErrorContext {
821
+ message: string;
822
+ name: string;
823
+ stack?: string;
824
+ cause?: unknown;
825
+ }
826
+ /**
827
+ * Context passed to log handlers
828
+ * If an Error was passed, it's normalized into the error property
829
+ */
830
+ interface LogContext {
831
+ [key: string]: unknown;
832
+ error?: ErrorContext;
833
+ }
834
+ /**
835
+ * Log message function signature
836
+ * Accepts string or Error as message, with optional context
837
+ */
838
+ type LogFn = (message: string | Error, context?: unknown | Error) => void;
839
+ /**
840
+ * Throw function signature - logs error then throws
841
+ * Returns never as it always throws
842
+ */
843
+ type ThrowFn = (message: string | Error, context?: unknown) => never;
844
+ /**
845
+ * Default handler function (passed to custom handlers for chaining)
846
+ */
847
+ type DefaultHandler = (level: Level, message: string, context: LogContext, scope: string[]) => void;
848
+ /**
849
+ * Custom log handler function
850
+ * Receives originalHandler to allow middleware-style chaining
851
+ */
852
+ type Handler = (level: Level, message: string, context: LogContext, scope: string[], originalHandler: DefaultHandler) => void;
853
+ /**
854
+ * Logger instance with scoping support
855
+ * All logs automatically include trace path from scoping
856
+ */
857
+ interface Instance$1 {
858
+ /**
859
+ * Log an error message (always visible unless silenced)
860
+ */
861
+ error: LogFn;
862
+ /**
863
+ * Log an informational message
864
+ */
865
+ info: LogFn;
866
+ /**
867
+ * Log a debug message
868
+ */
869
+ debug: LogFn;
870
+ /**
871
+ * Log an error message and throw an Error
872
+ * Combines logging and throwing in one call
873
+ */
874
+ throw: ThrowFn;
875
+ /**
876
+ * Create a scoped child logger with automatic trace path
877
+ * @param name - Scope name (e.g., destination type, destination key)
878
+ * @returns A new logger instance with the scope applied
879
+ */
880
+ scope: (name: string) => Instance$1;
881
+ }
882
+ /**
883
+ * Logger configuration options
884
+ */
885
+ interface Config$3 {
886
+ /**
887
+ * Minimum log level to display
888
+ * @default Level.ERROR
889
+ */
890
+ level?: Level | keyof typeof Level;
891
+ /**
892
+ * Custom log handler function
893
+ * Receives originalHandler to preserve default behavior
894
+ */
895
+ handler?: Handler;
896
+ }
897
+ /**
898
+ * Internal config with resolved values and scope
899
+ */
900
+ interface InternalConfig {
901
+ level: Level;
902
+ handler?: Handler;
903
+ scope: string[];
904
+ }
905
+ /**
906
+ * Logger factory function type
907
+ */
908
+ type Factory = (config?: Config$3) => Instance$1;
909
+
910
+ type logger_DefaultHandler = DefaultHandler;
911
+ type logger_ErrorContext = ErrorContext;
912
+ type logger_Factory = Factory;
913
+ type logger_Handler = Handler;
914
+ type logger_InternalConfig = InternalConfig;
915
+ type logger_Level = Level;
916
+ declare const logger_Level: typeof Level;
917
+ type logger_LogContext = LogContext;
918
+ type logger_LogFn = LogFn;
919
+ type logger_ThrowFn = ThrowFn;
920
+ declare namespace logger {
921
+ export { type Config$3 as Config, type logger_DefaultHandler as DefaultHandler, type logger_ErrorContext as ErrorContext, type logger_Factory as Factory, type logger_Handler as Handler, type Instance$1 as Instance, type logger_InternalConfig as InternalConfig, logger_Level as Level, type logger_LogContext as LogContext, type logger_LogFn as LogFn, type logger_ThrowFn as ThrowFn };
922
+ }
923
+
823
924
  /**
824
925
  * Shared mapping configuration interface.
825
926
  * Used by both Source.Config and Destination.Config.
@@ -838,7 +939,7 @@ interface Rules<T = Rule> {
838
939
  }
839
940
  interface Rule<Settings = unknown> {
840
941
  batch?: number;
841
- batchFn?: (destination: Instance$1, collector: Instance$2) => void;
942
+ batchFn?: (destination: Instance$2, collector: Instance$3) => void;
842
943
  batched?: Batch<Settings>;
843
944
  condition?: Condition;
844
945
  consent?: Consent;
@@ -867,7 +968,7 @@ interface ValueConfig {
867
968
  validate?: Validate;
868
969
  value?: PropertyType;
869
970
  }
870
- type Condition = (value: DeepPartialEvent | unknown, mapping?: Value, collector?: Instance$2) => PromiseOrValue<boolean>;
971
+ type Condition = (value: DeepPartialEvent | unknown, mapping?: Value, collector?: Instance$3) => PromiseOrValue<boolean>;
871
972
  type Fn = (value: DeepPartialEvent | unknown, mapping: Value, options: Options$1) => PromiseOrValue<Property | unknown>;
872
973
  type Loop = [Value, Value];
873
974
  type Map = {
@@ -875,7 +976,7 @@ type Map = {
875
976
  };
876
977
  interface Options$1 {
877
978
  consent?: Consent;
878
- collector?: Instance$2;
979
+ collector?: Instance$3;
879
980
  props?: unknown;
880
981
  }
881
982
  type Validate = (value?: unknown) => PromiseOrValue<boolean>;
@@ -921,13 +1022,13 @@ type Options = ConsentConfig | ReadyConfig | RunConfig | SessionConfig;
921
1022
  interface ConsentConfig {
922
1023
  [key: string]: ConsentFn;
923
1024
  }
924
- type ConsentFn = (collector: Instance$2, consent: Consent) => void;
1025
+ type ConsentFn = (collector: Instance$3, consent: Consent) => void;
925
1026
  type ReadyConfig = ReadyFn;
926
- type ReadyFn = (collector: Instance$2) => void;
1027
+ type ReadyFn = (collector: Instance$3) => void;
927
1028
  type RunConfig = RunFn;
928
- type RunFn = (collector: Instance$2) => void;
1029
+ type RunFn = (collector: Instance$3) => void;
929
1030
  type SessionConfig = SessionFn;
930
- type SessionFn = (collector: Instance$2, session?: unknown) => void;
1031
+ type SessionFn = (collector: Instance$3, session?: unknown) => void;
931
1032
  interface OnConfig {
932
1033
  consent?: ConsentConfig[];
933
1034
  ready?: ReadyConfig[];
@@ -1015,6 +1116,7 @@ interface BaseEnv {
1015
1116
  command: CommandFn;
1016
1117
  sources?: Sources;
1017
1118
  elb: Fn$1;
1119
+ logger: Instance$1;
1018
1120
  }
1019
1121
  /**
1020
1122
  * Type bundle for source generics.
@@ -1059,7 +1161,7 @@ interface Config<T extends TypesGeneric = Types> extends Config$2<Mapping<T>> {
1059
1161
  settings?: InitSettings<T>;
1060
1162
  env?: Env<T>;
1061
1163
  id?: string;
1062
- onError?: Error;
1164
+ logger?: Config$3;
1063
1165
  disabled?: boolean;
1064
1166
  primary?: boolean;
1065
1167
  }
@@ -1249,6 +1351,53 @@ interface SendResponse {
1249
1351
  */
1250
1352
  declare function anonymizeIP(ip: string): string;
1251
1353
 
1354
+ /**
1355
+ * Flow Configuration Utilities
1356
+ *
1357
+ * Functions for resolving and processing Flow configurations.
1358
+ *
1359
+ * @packageDocumentation
1360
+ */
1361
+
1362
+ /**
1363
+ * Get resolved flow configuration for a named flow.
1364
+ *
1365
+ * @param setup - The complete setup configuration
1366
+ * @param flowName - Flow name (auto-selected if only one exists)
1367
+ * @returns Resolved Config with variables/definitions interpolated and $refs resolved
1368
+ * @throws Error if flow selection is required but not specified, or flow not found
1369
+ *
1370
+ * @example
1371
+ * ```typescript
1372
+ * import { getFlowConfig } from '@walkeros/core';
1373
+ *
1374
+ * const setup = JSON.parse(fs.readFileSync('walkeros.config.json', 'utf8'));
1375
+ *
1376
+ * // Auto-select if only one flow
1377
+ * const config = getFlowConfig(setup);
1378
+ *
1379
+ * // Or specify flow
1380
+ * const prodConfig = getFlowConfig(setup, 'production');
1381
+ * ```
1382
+ */
1383
+ declare function getFlowConfig(setup: Setup, flowName?: string): Config$4;
1384
+ /**
1385
+ * Get platform from config (web or server).
1386
+ *
1387
+ * @param config - Flow configuration
1388
+ * @returns "web" or "server"
1389
+ * @throws Error if neither web nor server is present
1390
+ *
1391
+ * @example
1392
+ * ```typescript
1393
+ * import { getPlatform } from '@walkeros/core';
1394
+ *
1395
+ * const platform = getPlatform(config);
1396
+ * // Returns "web" or "server"
1397
+ * ```
1398
+ */
1399
+ declare function getPlatform(config: Config$4): 'web' | 'server';
1400
+
1252
1401
  /**
1253
1402
  * @interface Assign
1254
1403
  * @description Options for the assign function.
@@ -1343,7 +1492,7 @@ declare function getGrantedConsent(required: Consent | undefined, state?: Consen
1343
1492
  * }));
1344
1493
  * ```
1345
1494
  */
1346
- declare function createDestination<I extends Instance$1>(baseDestination: I, config: Partial<Config$4<TypesOf$1<I>>>): I;
1495
+ declare function createDestination<I extends Instance$2>(baseDestination: I, config: Partial<Config$5<TypesOf$1<I>>>): I;
1347
1496
 
1348
1497
  /**
1349
1498
  * Creates a complete event with default values.
@@ -1477,6 +1626,36 @@ declare function isSameType<T>(variable: unknown, type: T): variable is typeof t
1477
1626
  */
1478
1627
  declare function isString(value: unknown): value is string;
1479
1628
 
1629
+ /**
1630
+ * Create a logger instance
1631
+ *
1632
+ * @param config - Logger configuration
1633
+ * @returns Logger instance with all log methods and scoping support
1634
+ *
1635
+ * @example
1636
+ * ```typescript
1637
+ * // Basic usage
1638
+ * const logger = createLogger({ level: 'DEBUG' });
1639
+ * logger.info('Hello world');
1640
+ *
1641
+ * // With scoping
1642
+ * const destLogger = logger.scope('gtag').scope('myInstance');
1643
+ * destLogger.debug('Processing event'); // DEBUG [gtag:myInstance] Processing event
1644
+ *
1645
+ * // With custom handler
1646
+ * const logger = createLogger({
1647
+ * handler: (level, message, context, scope, originalHandler) => {
1648
+ * // Custom logic (e.g., send to Sentry)
1649
+ * originalHandler(level, message, context, scope);
1650
+ * }
1651
+ * });
1652
+ * ```
1653
+ *
1654
+ * // TODO: Consider compile-time stripping of debug logs in production builds
1655
+ * // e.g., if (__DEV__) { logger.debug(...) }
1656
+ */
1657
+ declare function createLogger(config?: Config$3): Instance$1;
1658
+
1480
1659
  /**
1481
1660
  * Gets the mapping for an event.
1482
1661
  *
@@ -1513,7 +1692,7 @@ declare function getMappingValue(value: DeepPartialEvent | unknown | undefined,
1513
1692
  * @param collector - Collector instance for context
1514
1693
  * @returns Object with transformed event, data, mapping rule, and ignore flag
1515
1694
  */
1516
- declare function processEventMapping<T extends DeepPartialEvent | Event>(event: T, config: Config$2, collector: Instance$2): Promise<{
1695
+ declare function processEventMapping<T extends DeepPartialEvent | Event>(event: T, config: Config$2, collector: Instance$3): Promise<{
1517
1696
  event: T;
1518
1697
  data?: Property;
1519
1698
  mapping?: Rule;
@@ -1588,12 +1767,42 @@ declare function mockEnv<T extends object>(env: T, interceptor: InterceptorFn):
1588
1767
  declare function traverseEnv<T extends object>(env: T, replacer: (value: unknown, path: string[]) => unknown): T;
1589
1768
 
1590
1769
  /**
1591
- * Logs a message to the console if verbose logging is enabled.
1770
+ * Mock logger instance for testing
1771
+ * Includes all logger methods as jest.fn() plus tracking of scoped loggers
1772
+ * Extends Instance to ensure type compatibility
1773
+ */
1774
+ interface MockLogger extends Instance$1 {
1775
+ error: jest.Mock;
1776
+ info: jest.Mock;
1777
+ debug: jest.Mock;
1778
+ throw: jest.Mock<never, [string | Error, unknown?]>;
1779
+ scope: jest.Mock<MockLogger, [string]>;
1780
+ /**
1781
+ * Array of all scoped loggers created by this logger
1782
+ * Useful for asserting on scoped logger calls in tests
1783
+ */
1784
+ scopedLoggers: MockLogger[];
1785
+ }
1786
+ /**
1787
+ * Create a mock logger for testing
1788
+ * All methods are jest.fn() that can be used for assertions
1789
+ *
1790
+ * @example
1791
+ * ```typescript
1792
+ * const mockLogger = createMockLogger();
1592
1793
  *
1593
- * @param message The message to log.
1594
- * @param verbose Whether to log the message.
1794
+ * // Use in code under test
1795
+ * someFunction(mockLogger);
1796
+ *
1797
+ * // Assert on calls
1798
+ * expect(mockLogger.error).toHaveBeenCalledWith('error message');
1799
+ *
1800
+ * // Assert on scoped logger
1801
+ * const scoped = mockLogger.scopedLoggers[0];
1802
+ * expect(scoped.debug).toHaveBeenCalledWith('debug in scope');
1803
+ * ```
1595
1804
  */
1596
- declare function onLog(message: unknown, verbose?: boolean): void;
1805
+ declare function createMockLogger(): MockLogger;
1597
1806
 
1598
1807
  /**
1599
1808
  * Checks if a value is a valid property type.
@@ -1758,4 +1967,87 @@ declare function validateEvent(obj: unknown, customContracts?: Contracts): Event
1758
1967
  */
1759
1968
  declare function validateProperty(obj: AnyObject, key: string, value: unknown, schema: Property$1): Property | never;
1760
1969
 
1761
- export { collector as Collector, Const, data as Data, destination as Destination, elb as Elb, flow as Flow, handler as Handler, hooks as Hooks, mapping as Mapping, type MarketingParameters, on as On, request as Request, schema as Schema, type SendDataValue, type SendHeaders, type SendResponse, source as Source, type StorageType, walkeros as WalkerOS, anonymizeIP, assign, castToProperty, castValue, clone, createDestination, createEvent, debounce, filterValues, getBrowser, getBrowserVersion, getByPath, getDeviceType, getEvent, getGrantedConsent, getHeaders, getId, getMappingEvent, getMappingValue, getMarketingParameters, getOS, getOSVersion, isArguments, isArray, isBoolean, isCommand, isDefined, isElementOrDocument, isFunction, isNumber, isObject, isPropertyType, isSameType, isString, mockEnv, onLog, parseUserAgent, processEventMapping, requestToData, requestToParameter, setByPath, throttle, throwError, transformData, traverseEnv, trim, tryCatch, tryCatchAsync, useHooks, validateEvent, validateProperty };
1970
+ /**
1971
+ * Inline Code Wrapping Utilities
1972
+ *
1973
+ * Converts inline code strings to executable functions.
1974
+ * Used for mapping properties: condition, fn, validate.
1975
+ *
1976
+ * @packageDocumentation
1977
+ */
1978
+
1979
+ /**
1980
+ * Wrap inline code string as Condition function.
1981
+ *
1982
+ * @param code - Inline code string
1983
+ * @returns Condition function matching Mapping.Condition signature
1984
+ *
1985
+ * @remarks
1986
+ * Available parameters in code:
1987
+ * - `value` - The event or partial event being processed
1988
+ * - `mapping` - Current mapping configuration
1989
+ * - `collector` - Collector instance
1990
+ *
1991
+ * If code has no explicit return, it's auto-wrapped with `return`.
1992
+ *
1993
+ * @example
1994
+ * ```typescript
1995
+ * // One-liner (auto-wrapped)
1996
+ * const fn = wrapCondition('value.data.total > 100');
1997
+ * fn(event, mapping, collector); // returns boolean
1998
+ *
1999
+ * // Multi-statement (explicit return)
2000
+ * const fn = wrapCondition('const threshold = 100; return value.data.total > threshold');
2001
+ * ```
2002
+ */
2003
+ declare function wrapCondition(code: string): Condition;
2004
+ /**
2005
+ * Wrap inline code string as Fn function.
2006
+ *
2007
+ * @param code - Inline code string
2008
+ * @returns Fn function matching Mapping.Fn signature
2009
+ *
2010
+ * @remarks
2011
+ * Available parameters in code:
2012
+ * - `value` - The event or partial event being processed
2013
+ * - `mapping` - Current mapping configuration
2014
+ * - `options` - Options object with consent and collector
2015
+ *
2016
+ * If code has no explicit return, it's auto-wrapped with `return`.
2017
+ *
2018
+ * @example
2019
+ * ```typescript
2020
+ * // One-liner (auto-wrapped)
2021
+ * const fn = wrapFn('value.user.email.split("@")[1]');
2022
+ * fn(event, mapping, options); // returns domain
2023
+ *
2024
+ * // Multi-statement (explicit return)
2025
+ * const fn = wrapFn('const parts = value.user.email.split("@"); return parts[1].toUpperCase()');
2026
+ * ```
2027
+ */
2028
+ declare function wrapFn(code: string): Fn;
2029
+ /**
2030
+ * Wrap inline code string as Validate function.
2031
+ *
2032
+ * @param code - Inline code string
2033
+ * @returns Validate function matching Mapping.Validate signature
2034
+ *
2035
+ * @remarks
2036
+ * Available parameters in code:
2037
+ * - `value` - The current value being validated
2038
+ *
2039
+ * If code has no explicit return, it's auto-wrapped with `return`.
2040
+ *
2041
+ * @example
2042
+ * ```typescript
2043
+ * // One-liner (auto-wrapped)
2044
+ * const fn = wrapValidate('value && value.length > 0');
2045
+ * fn('hello'); // returns true
2046
+ *
2047
+ * // Multi-statement (explicit return)
2048
+ * const fn = wrapValidate('if (!value) return false; return value.length > 0');
2049
+ * ```
2050
+ */
2051
+ declare function wrapValidate(code: string): Validate;
2052
+
2053
+ export { collector as Collector, Const, data as Data, destination as Destination, elb as Elb, flow as Flow, hooks as Hooks, Level, logger as Logger, mapping as Mapping, type MarketingParameters, type MockLogger, on as On, request as Request, schema as Schema, type SendDataValue, type SendHeaders, type SendResponse, source as Source, type StorageType, walkeros as WalkerOS, anonymizeIP, assign, castToProperty, castValue, clone, createDestination, createEvent, createLogger, createMockLogger, debounce, filterValues, getBrowser, getBrowserVersion, getByPath, getDeviceType, getEvent, getFlowConfig, getGrantedConsent, getHeaders, getId, getMappingEvent, getMappingValue, getMarketingParameters, getOS, getOSVersion, getPlatform, isArguments, isArray, isBoolean, isCommand, isDefined, isElementOrDocument, isFunction, isNumber, isObject, isPropertyType, isSameType, isString, mockEnv, parseUserAgent, processEventMapping, requestToData, requestToParameter, setByPath, throttle, throwError, transformData, traverseEnv, trim, tryCatch, tryCatchAsync, useHooks, validateEvent, validateProperty, wrapCondition, wrapFn, wrapValidate };