@walkeros/core 0.1.0 → 0.1.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.mts CHANGED
@@ -16,6 +16,8 @@ interface Config$4 {
16
16
  globalsStatic: Properties;
17
17
  /** Static session data even on a new run */
18
18
  sessionStatic: Partial<SessionData>;
19
+ /** Source configurations */
20
+ sources?: InitSources;
19
21
  /** Destination configurations */
20
22
  destinations?: InitDestinations;
21
23
  /** Initial custom properties */
@@ -41,17 +43,11 @@ interface SessionData extends Properties {
41
43
  runs?: number;
42
44
  }
43
45
  interface Sources {
44
- [id: string]: CollectorSource;
46
+ [id: string]: Instance;
45
47
  }
46
48
  interface Destinations$1 {
47
49
  [id: string]: Instance$1;
48
50
  }
49
- interface CollectorSource {
50
- type: string;
51
- mapping?: unknown;
52
- settings?: Record<string, unknown>;
53
- elb?: AnyFunction;
54
- }
55
51
  type CommandType = 'action' | 'config' | 'consent' | 'context' | 'destination' | 'elb' | 'globals' | 'hook' | 'init' | 'link' | 'run' | 'user' | 'walker' | string;
56
52
  interface Instance$2 {
57
53
  push: Fn$1;
@@ -74,12 +70,11 @@ interface Instance$2 {
74
70
  version: string;
75
71
  }
76
72
 
77
- type collector_CollectorSource = CollectorSource;
78
73
  type collector_CommandType = CommandType;
79
74
  type collector_SessionData = SessionData;
80
75
  type collector_Sources = Sources;
81
76
  declare namespace collector {
82
- export type { collector_CollectorSource as CollectorSource, collector_CommandType as CommandType, Config$4 as Config, Destinations$1 as Destinations, InitConfig$1 as InitConfig, Instance$2 as Instance, collector_SessionData as SessionData, collector_Sources as Sources };
77
+ export type { collector_CommandType as CommandType, Config$4 as Config, Destinations$1 as Destinations, InitConfig$1 as InitConfig, Instance$2 as Instance, collector_SessionData as SessionData, collector_Sources as Sources };
83
78
  }
84
79
 
85
80
  interface Contract$1 {
@@ -139,21 +134,21 @@ interface Instance$1<Settings = unknown, Mapping = unknown> {
139
134
  queue?: Events;
140
135
  dlq?: DLQ;
141
136
  type?: string;
142
- env?: Environment;
137
+ env?: Environment$1;
143
138
  init?: InitFn<Settings, Mapping>;
144
139
  push: PushFn<Settings, Mapping>;
145
140
  pushBatch?: PushBatchFn<Settings, Mapping>;
141
+ on?(event: Types, context?: unknown): void | Promise<void>;
146
142
  }
147
143
  interface Config$3<Settings = unknown, Mapping = unknown> {
148
144
  consent?: Consent;
149
145
  settings?: Settings;
150
146
  data?: Value | Values;
151
- env?: Environment;
147
+ env?: Environment$1;
152
148
  id?: string;
153
149
  init?: boolean;
154
150
  loadScript?: boolean;
155
151
  mapping?: Rules<Rule<Mapping>>;
156
- on?: Config$1;
157
152
  policy?: Policy;
158
153
  queue?: boolean;
159
154
  verbose?: boolean;
@@ -164,12 +159,13 @@ type PartialConfig<Settings = unknown, Mapping = unknown> = Config$3<Partial<Set
164
159
  interface Policy {
165
160
  [key: string]: Value;
166
161
  }
167
- type Init$1 = Partial<Omit<Instance$1, 'push'>> & Pick<Instance$1, 'push'>;
168
- type InitDestination<Settings = unknown, Mapping = unknown> = Omit<Instance$1<Settings, Mapping>, 'config'> & {
169
- config?: Config$3<Settings, Mapping>;
162
+ type Init$1<Settings = unknown, Mapping = unknown> = {
163
+ code: Instance$1<Settings, Mapping>;
164
+ config?: Partial<Config$3<Settings, Mapping>>;
165
+ env?: Partial<Environment$1>;
170
166
  };
171
167
  interface InitDestinations {
172
- [key: string]: InitDestination<any, any>;
168
+ [key: string]: Init$1<any, any>;
173
169
  }
174
170
  interface Destinations {
175
171
  [key: string]: Instance$1;
@@ -178,7 +174,7 @@ interface Context$1<Settings = unknown, Mapping = unknown> {
178
174
  collector: Instance$2;
179
175
  config: Config$3<Settings, Mapping>;
180
176
  data?: Data$1;
181
- env: Environment;
177
+ env: Environment$1;
182
178
  }
183
179
  interface PushContext<Settings = unknown, Mapping = unknown> extends Context$1<Settings, Mapping> {
184
180
  mapping?: Rule<Mapping>;
@@ -222,7 +218,7 @@ type Result$1 = {
222
218
  * their runtime environment requirements. Platform-specific extensions
223
219
  * should extend this interface.
224
220
  */
225
- interface Environment {
221
+ interface Environment$1 {
226
222
  /**
227
223
  * Generic global properties that destinations may require
228
224
  * Platform-specific implementations can extend this interface
@@ -233,8 +229,6 @@ interface Environment {
233
229
  type destination_Batch<Mapping> = Batch<Mapping>;
234
230
  type destination_DLQ = DLQ;
235
231
  type destination_Destinations = Destinations;
236
- type destination_Environment = Environment;
237
- type destination_InitDestination<Settings = unknown, Mapping = unknown> = InitDestination<Settings, Mapping>;
238
232
  type destination_InitDestinations = InitDestinations;
239
233
  type destination_InitFn<Settings, Mapping> = InitFn<Settings, Mapping>;
240
234
  type destination_PartialConfig<Settings = unknown, Mapping = unknown> = PartialConfig<Settings, Mapping>;
@@ -248,7 +242,7 @@ type destination_PushEvents<Mapping = unknown> = PushEvents<Mapping>;
248
242
  type destination_PushFn<Settings, Mapping> = PushFn<Settings, Mapping>;
249
243
  type destination_Ref = Ref;
250
244
  declare namespace destination {
251
- export type { destination_Batch as Batch, Config$3 as Config, Context$1 as Context, destination_DLQ as DLQ, Data$1 as Data, destination_Destinations as Destinations, destination_Environment as Environment, Init$1 as Init, destination_InitDestination as InitDestination, destination_InitDestinations as InitDestinations, destination_InitFn as InitFn, Instance$1 as Instance, destination_PartialConfig as PartialConfig, destination_Policy as Policy, destination_Push 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 };
245
+ export type { destination_Batch as Batch, Config$3 as Config, Context$1 as Context, destination_DLQ as DLQ, Data$1 as Data, destination_Destinations as Destinations, Environment$1 as Environment, Init$1 as Init, destination_InitDestinations as InitDestinations, destination_InitFn as InitFn, Instance$1 as Instance, destination_PartialConfig as PartialConfig, destination_Policy as Policy, destination_Push 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 };
252
246
  }
253
247
 
254
248
  interface EventFn<R = Promise<PushResult>> {
@@ -261,7 +255,7 @@ interface Fn$1<R = Promise<PushResult>, Config = unknown> extends EventFn<R>, Wa
261
255
  interface WalkerCommands<R = Promise<PushResult>, Config = unknown> {
262
256
  (event: 'walker config', config: Partial<Config>): R;
263
257
  (event: 'walker consent', consent: Consent): R;
264
- (event: 'walker destination', destination: Init$1 | Instance$1, config?: Config$3): R;
258
+ <S, M>(event: 'walker destination', destination: Init$1<S, M> | Instance$1<S, M>, config?: Config$3<S, M>): R;
265
259
  <K extends keyof Functions>(event: 'walker hook', name: K, hookFn: Functions[K]): R;
266
260
  (event: 'walker on', type: Types, rules: SingleOrArray<Options>): R;
267
261
  (event: 'walker user', user: User): R;
@@ -279,18 +273,14 @@ interface PushResult extends Result$1 {
279
273
  ok: boolean;
280
274
  }
281
275
  type Layer = Array<IArguments | DeepPartialEvent | unknown[]>;
282
- interface RegisterDestination<Destination, Config> {
283
- (event: 'walker destination', destination: Destination, config?: Config): Promise<PushResult>;
284
- }
285
276
 
286
277
  type elb_EventFn<R = Promise<PushResult>> = EventFn<R>;
287
278
  type elb_Layer = Layer;
288
279
  type elb_PushData<Config = unknown> = PushData<Config>;
289
280
  type elb_PushResult = PushResult;
290
- type elb_RegisterDestination<Destination, Config> = RegisterDestination<Destination, Config>;
291
281
  type elb_WalkerCommands<R = Promise<PushResult>, Config = unknown> = WalkerCommands<R, Config>;
292
282
  declare namespace elb {
293
- export type { Event$1 as Event, elb_EventFn as EventFn, Fn$1 as Fn, elb_Layer as Layer, elb_PushData as PushData, elb_PushResult as PushResult, elb_RegisterDestination as RegisterDestination, elb_WalkerCommands as WalkerCommands };
283
+ export type { Event$1 as Event, elb_EventFn as EventFn, Fn$1 as Fn, elb_Layer as Layer, elb_PushData as PushData, elb_PushResult as PushResult, elb_WalkerCommands as WalkerCommands };
294
284
  }
295
285
 
296
286
  /**
@@ -484,46 +474,78 @@ declare namespace schema {
484
474
  }
485
475
 
486
476
  interface Config {
487
- type: string;
488
477
  id?: string;
489
478
  disabled?: boolean;
490
479
  settings: AnyObject;
491
480
  onError?: AnyFunction;
492
481
  }
493
482
  type InitConfig = Partial<Config>;
494
- interface Init<T extends Config = Config, E = AnyFunction> {
495
- (collector: Instance$2, config: T): CreateSource<T, E> | Promise<CreateSource<T, E>>;
496
- }
497
- interface CreateSource<T extends Config = Config, E = AnyFunction> {
498
- source?: Instance<T>;
499
- elb?: E;
483
+ /**
484
+ * Environment interface for dependency injection into sources.
485
+ *
486
+ * Sources receive all their dependencies through this environment object,
487
+ * making them platform-agnostic and easily testable.
488
+ */
489
+ interface Environment {
490
+ elb: Fn$1;
491
+ [key: string]: unknown;
500
492
  }
493
+ /**
494
+ * Source instance returned by Source.Init function.
495
+ *
496
+ * Sources are stateless and contain no collector references.
497
+ * All communication with collector happens via env.elb function.
498
+ */
501
499
  interface Instance<T extends Config = Config> {
502
500
  type: string;
503
501
  config: T;
504
- collector: Instance$2;
502
+ push: Fn$1;
505
503
  destroy?(): void | Promise<void>;
504
+ on?(event: Types, context?: unknown): void | Promise<void>;
505
+ }
506
+ /**
507
+ * Source initialization function signature.
508
+ *
509
+ * Sources are functions that receive configuration and environment dependencies
510
+ * and return a stateless instance.
511
+ *
512
+ * @param config - Source configuration (settings, type, etc.)
513
+ * @param env - Environment with elb function and platform APIs (defaults to {})
514
+ * @returns Source instance or promise of instance
515
+ */
516
+ type Init<T extends Config = Config> = (config: Partial<T>, env?: Environment) => Instance<T> | Promise<Instance<T>>;
517
+ /**
518
+ * Source configuration interface for collector initialization.
519
+ * Similar to destinations, this defines the structure for source definitions.
520
+ */
521
+ type InitSource<T extends Config = Config> = {
522
+ code: Init<T>;
523
+ config?: T;
524
+ env?: Partial<Environment>;
525
+ };
526
+ /**
527
+ * Sources configuration for collector.
528
+ * Maps source IDs to their initialization configurations.
529
+ */
530
+ interface InitSources {
531
+ [sourceId: string]: InitSource<any>;
506
532
  }
507
533
 
508
534
  type source_Config = Config;
509
- type source_CreateSource<T extends Config = Config, E = AnyFunction> = CreateSource<T, E>;
510
- type source_Init<T extends Config = Config, E = AnyFunction> = Init<T, E>;
535
+ type source_Environment = Environment;
536
+ type source_Init<T extends Config = Config> = Init<T>;
511
537
  type source_InitConfig = InitConfig;
538
+ type source_InitSource<T extends Config = Config> = InitSource<T>;
539
+ type source_InitSources = InitSources;
512
540
  type source_Instance<T extends Config = Config> = Instance<T>;
513
541
  declare namespace source {
514
- export type { source_Config as Config, source_CreateSource as CreateSource, source_Init as Init, source_InitConfig as InitConfig, source_Instance as Instance };
542
+ export type { source_Config as Config, source_Environment as Environment, source_Init as Init, source_InitConfig as InitConfig, source_InitSource as InitSource, source_InitSources as InitSources, source_Instance as Instance };
515
543
  }
516
544
 
517
545
  type AnyObject<T = unknown> = Record<string, T>;
518
- type Elb = globalThis.WalkerOS.Elb;
546
+ type Elb = Fn$1;
519
547
  type AnyFunction = (...args: unknown[]) => unknown;
520
548
  type SingleOrArray<T> = T | Array<T>;
521
- declare global {
522
- namespace WalkerOS {
523
- interface Elb extends Fn$1 {
524
- }
525
- }
526
- }
527
549
  type Events = Array<Event>;
528
550
  type PartialEvent = Partial<Event>;
529
551
  type DeepPartialEvent = DeepPartial<Event>;
@@ -757,39 +779,6 @@ declare function getGrantedConsent(required: Consent | undefined, state?: Consen
757
779
  */
758
780
  declare function createDestination<Settings = unknown, Mapping = unknown>(baseDestination: Instance$1<Settings, Mapping>, config: Partial<Config$3<Settings, Mapping>>): Instance$1<Settings, Mapping>;
759
781
 
760
- /**
761
- * Creates a new source function by merging a base source with additional configuration.
762
- *
763
- * This utility enables elegant source configuration while avoiding config side-effects
764
- * that could occur when reusing source functions across multiple collector instances.
765
- *
766
- * @template T - The source config type extending Source.Config
767
- * @template E - The source elb function type
768
- * @param source - The base source function to extend
769
- * @param config - Additional configuration to merge with the source's config
770
- * @returns A new source function with merged configuration
771
- *
772
- * @example
773
- * ```typescript
774
- * import { createSource } from '@walkeros/core';
775
- * import { sourceBrowser } from '@walkeros/web-source-browser';
776
- *
777
- * const configuredSource = createSource(sourceBrowser, {
778
- * settings: {
779
- * scope: document.body,
780
- * session: true
781
- * }
782
- * });
783
- *
784
- * const { elb } = await createCollector({
785
- * sources: {
786
- * browser: configuredSource
787
- * }
788
- * });
789
- * ```
790
- */
791
- declare function createSource<T extends Config, E = unknown>(source: Init<T, E>, config: Partial<T>): Init<T, E>;
792
-
793
782
  /**
794
783
  * Creates a complete event with default values.
795
784
  * Used for testing and debugging.
@@ -1120,4 +1109,4 @@ declare function validateEvent(obj: unknown, customContracts?: Contracts): Event
1120
1109
  */
1121
1110
  declare function validateProperty(obj: AnyObject, key: string, value: unknown, schema: Property$1): Property | never;
1122
1111
 
1123
- 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, createSource, 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, onLog, parseUserAgent, requestToData, requestToParameter, setByPath, throttle, throwError, transformData, trim, tryCatch, tryCatchAsync, useHooks, validateEvent, validateProperty };
1112
+ 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, onLog, parseUserAgent, requestToData, requestToParameter, setByPath, throttle, throwError, transformData, trim, tryCatch, tryCatchAsync, useHooks, validateEvent, validateProperty };
package/dist/index.d.ts CHANGED
@@ -16,6 +16,8 @@ interface Config$4 {
16
16
  globalsStatic: Properties;
17
17
  /** Static session data even on a new run */
18
18
  sessionStatic: Partial<SessionData>;
19
+ /** Source configurations */
20
+ sources?: InitSources;
19
21
  /** Destination configurations */
20
22
  destinations?: InitDestinations;
21
23
  /** Initial custom properties */
@@ -41,17 +43,11 @@ interface SessionData extends Properties {
41
43
  runs?: number;
42
44
  }
43
45
  interface Sources {
44
- [id: string]: CollectorSource;
46
+ [id: string]: Instance;
45
47
  }
46
48
  interface Destinations$1 {
47
49
  [id: string]: Instance$1;
48
50
  }
49
- interface CollectorSource {
50
- type: string;
51
- mapping?: unknown;
52
- settings?: Record<string, unknown>;
53
- elb?: AnyFunction;
54
- }
55
51
  type CommandType = 'action' | 'config' | 'consent' | 'context' | 'destination' | 'elb' | 'globals' | 'hook' | 'init' | 'link' | 'run' | 'user' | 'walker' | string;
56
52
  interface Instance$2 {
57
53
  push: Fn$1;
@@ -74,12 +70,11 @@ interface Instance$2 {
74
70
  version: string;
75
71
  }
76
72
 
77
- type collector_CollectorSource = CollectorSource;
78
73
  type collector_CommandType = CommandType;
79
74
  type collector_SessionData = SessionData;
80
75
  type collector_Sources = Sources;
81
76
  declare namespace collector {
82
- export type { collector_CollectorSource as CollectorSource, collector_CommandType as CommandType, Config$4 as Config, Destinations$1 as Destinations, InitConfig$1 as InitConfig, Instance$2 as Instance, collector_SessionData as SessionData, collector_Sources as Sources };
77
+ export type { collector_CommandType as CommandType, Config$4 as Config, Destinations$1 as Destinations, InitConfig$1 as InitConfig, Instance$2 as Instance, collector_SessionData as SessionData, collector_Sources as Sources };
83
78
  }
84
79
 
85
80
  interface Contract$1 {
@@ -139,21 +134,21 @@ interface Instance$1<Settings = unknown, Mapping = unknown> {
139
134
  queue?: Events;
140
135
  dlq?: DLQ;
141
136
  type?: string;
142
- env?: Environment;
137
+ env?: Environment$1;
143
138
  init?: InitFn<Settings, Mapping>;
144
139
  push: PushFn<Settings, Mapping>;
145
140
  pushBatch?: PushBatchFn<Settings, Mapping>;
141
+ on?(event: Types, context?: unknown): void | Promise<void>;
146
142
  }
147
143
  interface Config$3<Settings = unknown, Mapping = unknown> {
148
144
  consent?: Consent;
149
145
  settings?: Settings;
150
146
  data?: Value | Values;
151
- env?: Environment;
147
+ env?: Environment$1;
152
148
  id?: string;
153
149
  init?: boolean;
154
150
  loadScript?: boolean;
155
151
  mapping?: Rules<Rule<Mapping>>;
156
- on?: Config$1;
157
152
  policy?: Policy;
158
153
  queue?: boolean;
159
154
  verbose?: boolean;
@@ -164,12 +159,13 @@ type PartialConfig<Settings = unknown, Mapping = unknown> = Config$3<Partial<Set
164
159
  interface Policy {
165
160
  [key: string]: Value;
166
161
  }
167
- type Init$1 = Partial<Omit<Instance$1, 'push'>> & Pick<Instance$1, 'push'>;
168
- type InitDestination<Settings = unknown, Mapping = unknown> = Omit<Instance$1<Settings, Mapping>, 'config'> & {
169
- config?: Config$3<Settings, Mapping>;
162
+ type Init$1<Settings = unknown, Mapping = unknown> = {
163
+ code: Instance$1<Settings, Mapping>;
164
+ config?: Partial<Config$3<Settings, Mapping>>;
165
+ env?: Partial<Environment$1>;
170
166
  };
171
167
  interface InitDestinations {
172
- [key: string]: InitDestination<any, any>;
168
+ [key: string]: Init$1<any, any>;
173
169
  }
174
170
  interface Destinations {
175
171
  [key: string]: Instance$1;
@@ -178,7 +174,7 @@ interface Context$1<Settings = unknown, Mapping = unknown> {
178
174
  collector: Instance$2;
179
175
  config: Config$3<Settings, Mapping>;
180
176
  data?: Data$1;
181
- env: Environment;
177
+ env: Environment$1;
182
178
  }
183
179
  interface PushContext<Settings = unknown, Mapping = unknown> extends Context$1<Settings, Mapping> {
184
180
  mapping?: Rule<Mapping>;
@@ -222,7 +218,7 @@ type Result$1 = {
222
218
  * their runtime environment requirements. Platform-specific extensions
223
219
  * should extend this interface.
224
220
  */
225
- interface Environment {
221
+ interface Environment$1 {
226
222
  /**
227
223
  * Generic global properties that destinations may require
228
224
  * Platform-specific implementations can extend this interface
@@ -233,8 +229,6 @@ interface Environment {
233
229
  type destination_Batch<Mapping> = Batch<Mapping>;
234
230
  type destination_DLQ = DLQ;
235
231
  type destination_Destinations = Destinations;
236
- type destination_Environment = Environment;
237
- type destination_InitDestination<Settings = unknown, Mapping = unknown> = InitDestination<Settings, Mapping>;
238
232
  type destination_InitDestinations = InitDestinations;
239
233
  type destination_InitFn<Settings, Mapping> = InitFn<Settings, Mapping>;
240
234
  type destination_PartialConfig<Settings = unknown, Mapping = unknown> = PartialConfig<Settings, Mapping>;
@@ -248,7 +242,7 @@ type destination_PushEvents<Mapping = unknown> = PushEvents<Mapping>;
248
242
  type destination_PushFn<Settings, Mapping> = PushFn<Settings, Mapping>;
249
243
  type destination_Ref = Ref;
250
244
  declare namespace destination {
251
- export type { destination_Batch as Batch, Config$3 as Config, Context$1 as Context, destination_DLQ as DLQ, Data$1 as Data, destination_Destinations as Destinations, destination_Environment as Environment, Init$1 as Init, destination_InitDestination as InitDestination, destination_InitDestinations as InitDestinations, destination_InitFn as InitFn, Instance$1 as Instance, destination_PartialConfig as PartialConfig, destination_Policy as Policy, destination_Push 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 };
245
+ export type { destination_Batch as Batch, Config$3 as Config, Context$1 as Context, destination_DLQ as DLQ, Data$1 as Data, destination_Destinations as Destinations, Environment$1 as Environment, Init$1 as Init, destination_InitDestinations as InitDestinations, destination_InitFn as InitFn, Instance$1 as Instance, destination_PartialConfig as PartialConfig, destination_Policy as Policy, destination_Push 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 };
252
246
  }
253
247
 
254
248
  interface EventFn<R = Promise<PushResult>> {
@@ -261,7 +255,7 @@ interface Fn$1<R = Promise<PushResult>, Config = unknown> extends EventFn<R>, Wa
261
255
  interface WalkerCommands<R = Promise<PushResult>, Config = unknown> {
262
256
  (event: 'walker config', config: Partial<Config>): R;
263
257
  (event: 'walker consent', consent: Consent): R;
264
- (event: 'walker destination', destination: Init$1 | Instance$1, config?: Config$3): R;
258
+ <S, M>(event: 'walker destination', destination: Init$1<S, M> | Instance$1<S, M>, config?: Config$3<S, M>): R;
265
259
  <K extends keyof Functions>(event: 'walker hook', name: K, hookFn: Functions[K]): R;
266
260
  (event: 'walker on', type: Types, rules: SingleOrArray<Options>): R;
267
261
  (event: 'walker user', user: User): R;
@@ -279,18 +273,14 @@ interface PushResult extends Result$1 {
279
273
  ok: boolean;
280
274
  }
281
275
  type Layer = Array<IArguments | DeepPartialEvent | unknown[]>;
282
- interface RegisterDestination<Destination, Config> {
283
- (event: 'walker destination', destination: Destination, config?: Config): Promise<PushResult>;
284
- }
285
276
 
286
277
  type elb_EventFn<R = Promise<PushResult>> = EventFn<R>;
287
278
  type elb_Layer = Layer;
288
279
  type elb_PushData<Config = unknown> = PushData<Config>;
289
280
  type elb_PushResult = PushResult;
290
- type elb_RegisterDestination<Destination, Config> = RegisterDestination<Destination, Config>;
291
281
  type elb_WalkerCommands<R = Promise<PushResult>, Config = unknown> = WalkerCommands<R, Config>;
292
282
  declare namespace elb {
293
- export type { Event$1 as Event, elb_EventFn as EventFn, Fn$1 as Fn, elb_Layer as Layer, elb_PushData as PushData, elb_PushResult as PushResult, elb_RegisterDestination as RegisterDestination, elb_WalkerCommands as WalkerCommands };
283
+ export type { Event$1 as Event, elb_EventFn as EventFn, Fn$1 as Fn, elb_Layer as Layer, elb_PushData as PushData, elb_PushResult as PushResult, elb_WalkerCommands as WalkerCommands };
294
284
  }
295
285
 
296
286
  /**
@@ -484,46 +474,78 @@ declare namespace schema {
484
474
  }
485
475
 
486
476
  interface Config {
487
- type: string;
488
477
  id?: string;
489
478
  disabled?: boolean;
490
479
  settings: AnyObject;
491
480
  onError?: AnyFunction;
492
481
  }
493
482
  type InitConfig = Partial<Config>;
494
- interface Init<T extends Config = Config, E = AnyFunction> {
495
- (collector: Instance$2, config: T): CreateSource<T, E> | Promise<CreateSource<T, E>>;
496
- }
497
- interface CreateSource<T extends Config = Config, E = AnyFunction> {
498
- source?: Instance<T>;
499
- elb?: E;
483
+ /**
484
+ * Environment interface for dependency injection into sources.
485
+ *
486
+ * Sources receive all their dependencies through this environment object,
487
+ * making them platform-agnostic and easily testable.
488
+ */
489
+ interface Environment {
490
+ elb: Fn$1;
491
+ [key: string]: unknown;
500
492
  }
493
+ /**
494
+ * Source instance returned by Source.Init function.
495
+ *
496
+ * Sources are stateless and contain no collector references.
497
+ * All communication with collector happens via env.elb function.
498
+ */
501
499
  interface Instance<T extends Config = Config> {
502
500
  type: string;
503
501
  config: T;
504
- collector: Instance$2;
502
+ push: Fn$1;
505
503
  destroy?(): void | Promise<void>;
504
+ on?(event: Types, context?: unknown): void | Promise<void>;
505
+ }
506
+ /**
507
+ * Source initialization function signature.
508
+ *
509
+ * Sources are functions that receive configuration and environment dependencies
510
+ * and return a stateless instance.
511
+ *
512
+ * @param config - Source configuration (settings, type, etc.)
513
+ * @param env - Environment with elb function and platform APIs (defaults to {})
514
+ * @returns Source instance or promise of instance
515
+ */
516
+ type Init<T extends Config = Config> = (config: Partial<T>, env?: Environment) => Instance<T> | Promise<Instance<T>>;
517
+ /**
518
+ * Source configuration interface for collector initialization.
519
+ * Similar to destinations, this defines the structure for source definitions.
520
+ */
521
+ type InitSource<T extends Config = Config> = {
522
+ code: Init<T>;
523
+ config?: T;
524
+ env?: Partial<Environment>;
525
+ };
526
+ /**
527
+ * Sources configuration for collector.
528
+ * Maps source IDs to their initialization configurations.
529
+ */
530
+ interface InitSources {
531
+ [sourceId: string]: InitSource<any>;
506
532
  }
507
533
 
508
534
  type source_Config = Config;
509
- type source_CreateSource<T extends Config = Config, E = AnyFunction> = CreateSource<T, E>;
510
- type source_Init<T extends Config = Config, E = AnyFunction> = Init<T, E>;
535
+ type source_Environment = Environment;
536
+ type source_Init<T extends Config = Config> = Init<T>;
511
537
  type source_InitConfig = InitConfig;
538
+ type source_InitSource<T extends Config = Config> = InitSource<T>;
539
+ type source_InitSources = InitSources;
512
540
  type source_Instance<T extends Config = Config> = Instance<T>;
513
541
  declare namespace source {
514
- export type { source_Config as Config, source_CreateSource as CreateSource, source_Init as Init, source_InitConfig as InitConfig, source_Instance as Instance };
542
+ export type { source_Config as Config, source_Environment as Environment, source_Init as Init, source_InitConfig as InitConfig, source_InitSource as InitSource, source_InitSources as InitSources, source_Instance as Instance };
515
543
  }
516
544
 
517
545
  type AnyObject<T = unknown> = Record<string, T>;
518
- type Elb = globalThis.WalkerOS.Elb;
546
+ type Elb = Fn$1;
519
547
  type AnyFunction = (...args: unknown[]) => unknown;
520
548
  type SingleOrArray<T> = T | Array<T>;
521
- declare global {
522
- namespace WalkerOS {
523
- interface Elb extends Fn$1 {
524
- }
525
- }
526
- }
527
549
  type Events = Array<Event>;
528
550
  type PartialEvent = Partial<Event>;
529
551
  type DeepPartialEvent = DeepPartial<Event>;
@@ -757,39 +779,6 @@ declare function getGrantedConsent(required: Consent | undefined, state?: Consen
757
779
  */
758
780
  declare function createDestination<Settings = unknown, Mapping = unknown>(baseDestination: Instance$1<Settings, Mapping>, config: Partial<Config$3<Settings, Mapping>>): Instance$1<Settings, Mapping>;
759
781
 
760
- /**
761
- * Creates a new source function by merging a base source with additional configuration.
762
- *
763
- * This utility enables elegant source configuration while avoiding config side-effects
764
- * that could occur when reusing source functions across multiple collector instances.
765
- *
766
- * @template T - The source config type extending Source.Config
767
- * @template E - The source elb function type
768
- * @param source - The base source function to extend
769
- * @param config - Additional configuration to merge with the source's config
770
- * @returns A new source function with merged configuration
771
- *
772
- * @example
773
- * ```typescript
774
- * import { createSource } from '@walkeros/core';
775
- * import { sourceBrowser } from '@walkeros/web-source-browser';
776
- *
777
- * const configuredSource = createSource(sourceBrowser, {
778
- * settings: {
779
- * scope: document.body,
780
- * session: true
781
- * }
782
- * });
783
- *
784
- * const { elb } = await createCollector({
785
- * sources: {
786
- * browser: configuredSource
787
- * }
788
- * });
789
- * ```
790
- */
791
- declare function createSource<T extends Config, E = unknown>(source: Init<T, E>, config: Partial<T>): Init<T, E>;
792
-
793
782
  /**
794
783
  * Creates a complete event with default values.
795
784
  * Used for testing and debugging.
@@ -1120,4 +1109,4 @@ declare function validateEvent(obj: unknown, customContracts?: Contracts): Event
1120
1109
  */
1121
1110
  declare function validateProperty(obj: AnyObject, key: string, value: unknown, schema: Property$1): Property | never;
1122
1111
 
1123
- 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, createSource, 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, onLog, parseUserAgent, requestToData, requestToParameter, setByPath, throttle, throwError, transformData, trim, tryCatch, tryCatchAsync, useHooks, validateEvent, validateProperty };
1112
+ 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, onLog, parseUserAgent, requestToData, requestToParameter, setByPath, throttle, throwError, transformData, trim, tryCatch, tryCatchAsync, useHooks, validateEvent, validateProperty };