@walkeros/core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +65 -66
- package/dist/index.d.ts +65 -66
- 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.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]:
|
|
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 {
|
|
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 =
|
|
168
|
-
|
|
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]:
|
|
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,
|
|
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>> {
|
|
@@ -484,34 +478,72 @@ declare namespace schema {
|
|
|
484
478
|
}
|
|
485
479
|
|
|
486
480
|
interface Config {
|
|
487
|
-
type: string;
|
|
488
481
|
id?: string;
|
|
489
482
|
disabled?: boolean;
|
|
490
483
|
settings: AnyObject;
|
|
491
484
|
onError?: AnyFunction;
|
|
492
485
|
}
|
|
493
486
|
type InitConfig = Partial<Config>;
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Environment interface for dependency injection into sources.
|
|
489
|
+
*
|
|
490
|
+
* Sources receive all their dependencies through this environment object,
|
|
491
|
+
* making them platform-agnostic and easily testable.
|
|
492
|
+
*/
|
|
493
|
+
interface Environment {
|
|
494
|
+
elb: Fn$1;
|
|
495
|
+
[key: string]: unknown;
|
|
500
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* Source instance returned by Source.Init function.
|
|
499
|
+
*
|
|
500
|
+
* Sources are stateless and contain no collector references.
|
|
501
|
+
* All communication with collector happens via env.elb function.
|
|
502
|
+
*/
|
|
501
503
|
interface Instance<T extends Config = Config> {
|
|
502
504
|
type: string;
|
|
503
505
|
config: T;
|
|
504
|
-
|
|
506
|
+
push: Fn$1;
|
|
505
507
|
destroy?(): void | Promise<void>;
|
|
508
|
+
on?(event: Types, context?: unknown): void | Promise<void>;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Source initialization function signature.
|
|
512
|
+
*
|
|
513
|
+
* Sources are functions that receive configuration and environment dependencies
|
|
514
|
+
* and return a stateless instance.
|
|
515
|
+
*
|
|
516
|
+
* @param config - Source configuration (settings, type, etc.)
|
|
517
|
+
* @param env - Environment with elb function and platform APIs (defaults to {})
|
|
518
|
+
* @returns Source instance or promise of instance
|
|
519
|
+
*/
|
|
520
|
+
type Init<T extends Config = Config> = (config: Partial<T>, env?: Environment) => Instance<T> | Promise<Instance<T>>;
|
|
521
|
+
/**
|
|
522
|
+
* Source configuration interface for collector initialization.
|
|
523
|
+
* Similar to destinations, this defines the structure for source definitions.
|
|
524
|
+
*/
|
|
525
|
+
type InitSource<T extends Config = Config> = {
|
|
526
|
+
code: Init<T>;
|
|
527
|
+
config?: T;
|
|
528
|
+
env?: Partial<Environment>;
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* Sources configuration for collector.
|
|
532
|
+
* Maps source IDs to their initialization configurations.
|
|
533
|
+
*/
|
|
534
|
+
interface InitSources {
|
|
535
|
+
[sourceId: string]: InitSource<any>;
|
|
506
536
|
}
|
|
507
537
|
|
|
508
538
|
type source_Config = Config;
|
|
509
|
-
type
|
|
510
|
-
type source_Init<T extends Config = Config
|
|
539
|
+
type source_Environment = Environment;
|
|
540
|
+
type source_Init<T extends Config = Config> = Init<T>;
|
|
511
541
|
type source_InitConfig = InitConfig;
|
|
542
|
+
type source_InitSource<T extends Config = Config> = InitSource<T>;
|
|
543
|
+
type source_InitSources = InitSources;
|
|
512
544
|
type source_Instance<T extends Config = Config> = Instance<T>;
|
|
513
545
|
declare namespace source {
|
|
514
|
-
export type { source_Config as Config,
|
|
546
|
+
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
547
|
}
|
|
516
548
|
|
|
517
549
|
type AnyObject<T = unknown> = Record<string, T>;
|
|
@@ -757,39 +789,6 @@ declare function getGrantedConsent(required: Consent | undefined, state?: Consen
|
|
|
757
789
|
*/
|
|
758
790
|
declare function createDestination<Settings = unknown, Mapping = unknown>(baseDestination: Instance$1<Settings, Mapping>, config: Partial<Config$3<Settings, Mapping>>): Instance$1<Settings, Mapping>;
|
|
759
791
|
|
|
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
792
|
/**
|
|
794
793
|
* Creates a complete event with default values.
|
|
795
794
|
* Used for testing and debugging.
|
|
@@ -1120,4 +1119,4 @@ declare function validateEvent(obj: unknown, customContracts?: Contracts): Event
|
|
|
1120
1119
|
*/
|
|
1121
1120
|
declare function validateProperty(obj: AnyObject, key: string, value: unknown, schema: Property$1): Property | never;
|
|
1122
1121
|
|
|
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,
|
|
1122
|
+
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]:
|
|
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 {
|
|
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 =
|
|
168
|
-
|
|
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]:
|
|
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,
|
|
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>> {
|
|
@@ -484,34 +478,72 @@ declare namespace schema {
|
|
|
484
478
|
}
|
|
485
479
|
|
|
486
480
|
interface Config {
|
|
487
|
-
type: string;
|
|
488
481
|
id?: string;
|
|
489
482
|
disabled?: boolean;
|
|
490
483
|
settings: AnyObject;
|
|
491
484
|
onError?: AnyFunction;
|
|
492
485
|
}
|
|
493
486
|
type InitConfig = Partial<Config>;
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Environment interface for dependency injection into sources.
|
|
489
|
+
*
|
|
490
|
+
* Sources receive all their dependencies through this environment object,
|
|
491
|
+
* making them platform-agnostic and easily testable.
|
|
492
|
+
*/
|
|
493
|
+
interface Environment {
|
|
494
|
+
elb: Fn$1;
|
|
495
|
+
[key: string]: unknown;
|
|
500
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* Source instance returned by Source.Init function.
|
|
499
|
+
*
|
|
500
|
+
* Sources are stateless and contain no collector references.
|
|
501
|
+
* All communication with collector happens via env.elb function.
|
|
502
|
+
*/
|
|
501
503
|
interface Instance<T extends Config = Config> {
|
|
502
504
|
type: string;
|
|
503
505
|
config: T;
|
|
504
|
-
|
|
506
|
+
push: Fn$1;
|
|
505
507
|
destroy?(): void | Promise<void>;
|
|
508
|
+
on?(event: Types, context?: unknown): void | Promise<void>;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Source initialization function signature.
|
|
512
|
+
*
|
|
513
|
+
* Sources are functions that receive configuration and environment dependencies
|
|
514
|
+
* and return a stateless instance.
|
|
515
|
+
*
|
|
516
|
+
* @param config - Source configuration (settings, type, etc.)
|
|
517
|
+
* @param env - Environment with elb function and platform APIs (defaults to {})
|
|
518
|
+
* @returns Source instance or promise of instance
|
|
519
|
+
*/
|
|
520
|
+
type Init<T extends Config = Config> = (config: Partial<T>, env?: Environment) => Instance<T> | Promise<Instance<T>>;
|
|
521
|
+
/**
|
|
522
|
+
* Source configuration interface for collector initialization.
|
|
523
|
+
* Similar to destinations, this defines the structure for source definitions.
|
|
524
|
+
*/
|
|
525
|
+
type InitSource<T extends Config = Config> = {
|
|
526
|
+
code: Init<T>;
|
|
527
|
+
config?: T;
|
|
528
|
+
env?: Partial<Environment>;
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* Sources configuration for collector.
|
|
532
|
+
* Maps source IDs to their initialization configurations.
|
|
533
|
+
*/
|
|
534
|
+
interface InitSources {
|
|
535
|
+
[sourceId: string]: InitSource<any>;
|
|
506
536
|
}
|
|
507
537
|
|
|
508
538
|
type source_Config = Config;
|
|
509
|
-
type
|
|
510
|
-
type source_Init<T extends Config = Config
|
|
539
|
+
type source_Environment = Environment;
|
|
540
|
+
type source_Init<T extends Config = Config> = Init<T>;
|
|
511
541
|
type source_InitConfig = InitConfig;
|
|
542
|
+
type source_InitSource<T extends Config = Config> = InitSource<T>;
|
|
543
|
+
type source_InitSources = InitSources;
|
|
512
544
|
type source_Instance<T extends Config = Config> = Instance<T>;
|
|
513
545
|
declare namespace source {
|
|
514
|
-
export type { source_Config as Config,
|
|
546
|
+
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
547
|
}
|
|
516
548
|
|
|
517
549
|
type AnyObject<T = unknown> = Record<string, T>;
|
|
@@ -757,39 +789,6 @@ declare function getGrantedConsent(required: Consent | undefined, state?: Consen
|
|
|
757
789
|
*/
|
|
758
790
|
declare function createDestination<Settings = unknown, Mapping = unknown>(baseDestination: Instance$1<Settings, Mapping>, config: Partial<Config$3<Settings, Mapping>>): Instance$1<Settings, Mapping>;
|
|
759
791
|
|
|
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
792
|
/**
|
|
794
793
|
* Creates a complete event with default values.
|
|
795
794
|
* Used for testing and debugging.
|
|
@@ -1120,4 +1119,4 @@ declare function validateEvent(obj: unknown, customContracts?: Contracts): Event
|
|
|
1120
1119
|
*/
|
|
1121
1120
|
declare function validateProperty(obj: AnyObject, key: string, value: unknown, schema: Property$1): Property | never;
|
|
1122
1121
|
|
|
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,
|
|
1122
|
+
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.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,s=(e={"package.json"(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.1.0",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/core"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","web analytics","product analytics","core","types","utils"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return t||(0,e[o(e)[0]])((t={exports:{}}).exports,t),t.exports}),a={};((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})(a,{Collector:()=>c,Const:()=>x,Data:()=>u,Destination:()=>l,Elb:()=>d,Flow:()=>p,Handler:()=>g,Hooks:()=>m,Mapping:()=>f,On:()=>y,Request:()=>h,Schema:()=>b,Source:()=>w,WalkerOS:()=>v,anonymizeIP:()=>k,assign:()=>S,castToProperty:()=>Y,castValue:()=>L,clone:()=>V,createDestination:()=>R,createEvent:()=>K,createSource:()=>z,debounce:()=>G,filterValues:()=>Q,getBrowser:()=>ge,getBrowserVersion:()=>me,getByPath:()=>_,getDeviceType:()=>he,getEvent:()=>U,getGrantedConsent:()=>B,getHeaders:()=>ce,getId:()=>W,getMappingEvent:()=>te,getMappingValue:()=>ne,getMarketingParameters:()=>F,getOS:()=>fe,getOSVersion:()=>ye,isArguments:()=>j,isArray:()=>E,isBoolean:()=>P,isCommand:()=>T,isDefined:()=>A,isElementOrDocument:()=>M,isFunction:()=>D,isNumber:()=>C,isObject:()=>$,isPropertyType:()=>J,isSameType:()=>I,isString:()=>N,onLog:()=>oe,parseUserAgent:()=>pe,requestToData:()=>ie,requestToParameter:()=>se,setByPath:()=>H,throttle:()=>X,throwError:()=>ue,transformData:()=>ae,trim:()=>le,tryCatch:()=>Z,tryCatchAsync:()=>ee,useHooks:()=>de,validateEvent:()=>be,validateProperty:()=>we}),module.exports=(e=>((e,t,s,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of o(t))i.call(e,c)||c===s||n(e,c,{get:()=>t[c],enumerable:!(a=r(t,c))||a.enumerable});return e})(n({},"__esModule",{value:!0}),e))(a);var c={},u={},l={},d={},p={},g={},m={},f={},y={},h={},b={},w={},v={},x={Utils:{Storage:{Local:"local",Session:"session",Cookie:"cookie"}}};function k(e){return/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e)?e.replace(/\.\d+$/,".0"):""}var O={merge:!0,shallow:!0,extend:!0};function S(e,t={},n={}){n={...O,...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 j(e){return"[object Arguments]"===Object.prototype.toString.call(e)}function E(e){return Array.isArray(e)}function P(e){return"boolean"==typeof e}function T(e){return"walker"===e}function A(e){return void 0!==e}function M(e){return e===document||e instanceof Element}function D(e){return"function"==typeof e}function C(e){return"number"==typeof e&&!Number.isNaN(e)}function $(e){return"object"==typeof e&&null!==e&&!E(e)&&"[object Object]"===Object.prototype.toString.call(e)}function I(e,t){return typeof e==typeof t}function N(e){return"string"==typeof e}function V(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]=V(e[r],t));return n}if("[object Array]"===n){const n=[];return t.set(e,n),e.forEach(e=>{n.push(V(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 _(e,t="",n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const t=r[e];if("*"===t&&E(o)){const t=r.slice(e+1).join("."),i=[];for(const e of o){const r=_(e,t,n);i.push(r)}return i}if(o=o instanceof Object?o[t]:void 0,!o)break}return A(o)?o:n}function H(e,t,n){const r=V(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 L(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}function B(e,t={},n={}){const r={...t,...n},o={};let i=void 0===e;return Object.keys(r).forEach(t=>{r[t]&&(o[t]=!0,e&&e[t]&&(i=!0))}),!!i&&o}function R(e,t){const n={...e};return n.config=S(e.config,t,{shallow:!0,merge:!0,extend:!0}),e.config.settings&&t.settings&&(n.config.settings=S(e.config.settings,t.settings,{shallow:!0,merge:!0,extend:!0})),e.config.mapping&&t.mapping&&(n.config.mapping=S(e.config.mapping,t.mapping,{shallow:!0,merge:!0,extend:!0})),n}function z(e,t){return async(n,r)=>{const o=S(r,t,{shallow:!0,merge:!0,extend:!0});return r.settings&&t.settings&&(o.settings=S(r.settings,t.settings,{shallow:!0,merge:!0,extend:!0})),e(n,o)}}var{version:q}=s();function K(e={}){const t=e.timestamp||(new Date).setHours(0,13,37,0),n=e.group||"gr0up",r=e.count||1,o=S({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"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${t}-${n}-${r}`,trigger:"test",entity:"entity",action:"action",timestamp:t,timing:3.14,group:n,count:r,version:{source:q,tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.name){const[t,n]=e.name.split(" ")??[];t&&n&&(o.entity=t,o.action=n)}return o}function U(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 K({...{"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.elbwalker.com/",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 W(e=6){let t="";for(let n=36;t.length<e;)t+=(Math.random()*n|0).toString(n);return t}function F(e,t={}){const n="clickId",r={},o={utm_campaign:"campaign",utm_content:"content",utm_medium:"medium",utm_source:"source",utm_term:"term",dclid:n,fbclid:n,gclid:n,msclkid:n,ttclid:n,twclid:n,igshid:n,sclid:n};return Object.entries(S(o,t)).forEach(([t,o])=>{const i=e.searchParams.get(t);i&&(o===n&&(o=t,r[n]=t),r[o]=i)}),r}function G(e,t=1e3,n=!1){let r,o=null,i=!1;return(...s)=>new Promise(a=>{const c=n&&!i;o&&clearTimeout(o),o=setTimeout(()=>{o=null,n&&!i||(r=e(...s),a(r))},t),c&&(i=!0,r=e(...s),a(r))})}function X(e,t=1e3){let n=null;return function(...r){if(null===n)return n=setTimeout(()=>{n=null},t),e(...r)}}function J(e){return P(e)||N(e)||C(e)||!A(e)||E(e)&&e.every(J)||$(e)&&Object.values(e).every(J)}function Q(e){return P(e)||N(e)||C(e)?e:j(e)?Q(Array.from(e)):E(e)?e.map(e=>Q(e)).filter(e=>void 0!==e):$(e)?Object.entries(e).reduce((e,[t,n])=>{const r=Q(n);return void 0!==r&&(e[t]=r),e},{}):void 0}function Y(e){return J(e)?e:void 0}function Z(e,t,n){return function(...r){try{return e(...r)}catch(e){if(!t)return;return t(e)}finally{n?.()}}}function ee(e,t,n){return async function(...r){try{return await e(...r)}catch(e){if(!t)return;return await t(e)}finally{await(n?.())}}}async function te(e,t){const[n,r]=(e.name||"").split(" ");if(!t||!n||!r)return{};let o,i="",s=n,a=r;const c=t=>{if(t)return(t=E(t)?t:[t]).find(t=>!t.condition||t.condition(e))};t[s]||(s="*");const u=t[s];return u&&(u[a]||(a="*"),o=c(u[a])),o||(s="*",a="*",o=c(t[s]?.[a])),o&&(i=`${s} ${a}`),{eventMapping:o,mappingKey:i}}async function ne(e,t={},n={}){if(!A(e))return;const r=$(e)&&e.consent||n.consent||n.collector?.consent,o=E(t)?t:[t];for(const t of o){const o=await ee(re)(e,t,{...n,consent:r});if(A(o))return o}}async function re(e,t,n={}){const{collector:r,consent:o}=n;return(E(t)?t:[t]).reduce(async(t,i)=>{const s=await t;if(s)return s;const a=N(i)?{key:i}:i;if(!Object.keys(a).length)return;const{condition:c,consent:u,fn:l,key:d,loop:p,map:g,set:m,validate:f,value:y}=a;if(c&&!await ee(c)(e,i,r))return;if(u&&!B(u,o))return y;let h=A(y)?y:e;if(l&&(h=await ee(l)(e,i,n)),d&&(h=_(e,d,y)),p){const[t,r]=p,o="this"===t?[e]:await ne(e,t,n);E(o)&&(h=(await Promise.all(o.map(e=>ne(e,r,n)))).filter(A))}else g?h=await Object.entries(g).reduce(async(t,[r,o])=>{const i=await t,s=await ne(e,o,n);return A(s)&&(i[r]=s),i},Promise.resolve({})):m&&(h=await Promise.all(m.map(t=>re(e,t,n))));f&&!await ee(f)(h)&&(h=void 0);const b=Y(h);return A(b)?b:Y(y)},Promise.resolve(void 0))}function oe(e,t=!1){t&&console.dir(e,{depth:4})}function ie(e){const t=String(e),n=t.split("?")[1]||t;return Z(()=>{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(E(o)){const s=parseInt(t,10);i?o[s]=L(e):(o[s]=o[s]||(isNaN(parseInt(r[n+1],10))?{}:[]),o=o[s])}else $(o)&&(i?o[t]=L(e):(o[t]=o[t]||(isNaN(parseInt(r[n+1],10))?{}:[]),o=o[t]))})}),t})()}function se(e){if(!e)return"";const t=[],n=encodeURIComponent;function r(e,o){null!=o&&(E(o)?o.forEach((t,n)=>r(`${e}[${n}]`,t)):$(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 ae(e){return void 0===e||I(e,"")?e:JSON.stringify(e)}function ce(e={}){return S({"Content-Type":"application/json; charset=utf-8"},e)}function ue(e){throw new Error(String(e))}function le(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function de(e,t,n){return function(...r){let o;const i="post"+t,s=n["pre"+t],a=n[i];return o=s?s({fn:e},...r):e(...r),a&&(o=a({fn:e,result:o},...r)),o}}function pe(e){return e?{userAgent:e,browser:ge(e),browserVersion:me(e),os:fe(e),osVersion:ye(e),deviceType:he(e)}:{}}function ge(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 me(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 fe(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 ye(e){const t=e.match(/(?:Windows NT|Mac OS X|Android|iPhone OS) ([0-9._]+)/);return t?t[1].replace(/_/g,"."):void 0}function he(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 be(e,t=[]){let n,r,o;I(e,{})||ue("Invalid object"),I(e.name,"")?(n=e.name,[r,o]=n.split(" "),r&&o||ue("Invalid event name")):I(e.entity,"")&&I(e.action,"")?(r=e.entity,o=e.action,n=`${r} ${o}`):ue("Missing or invalid name, entity, or action");const i={name:n,data:{},context:{},custom:{},globals:{},user:{},nested:[],consent:{},id:"",trigger:"",entity:r,action:o,timestamp:0,timing:0,group:"",count:0,version:{source:"",tagging:0},source:{type:"",id:"",previous_id:""}};return[{"*":{"*":{name:{maxLength:255},user:{allowedKeys:["id","device","session"]},consent:{allowedValues:[!0,!1]},timestamp:{min:0},timing:{min:0},count:{min:0},version:{allowedKeys:["source","tagging"]},source:{allowedKeys:["type","id","previous_id"]}}}}].concat(t).reduce((e,t)=>["*",r].reduce((e,n)=>["*",o].reduce((e,r)=>{const o=t[n]?.[r];return o?e.concat([o]):e},e),e),[]).reduce((t,n)=>{const r=Object.keys(n).filter(e=>{const t=n[e];return!0===t?.required});return[...Object.keys(e),...r].reduce((t,r)=>{const o=n[r];let i=e[r];return o&&(i=Z(we,e=>{ue(String(e))})(t,r,i,o)),I(i,t[r])&&(t[r]=i),t},t)},i)}function we(e,t,n,r){if(r.validate&&(n=Z(r.validate,e=>{ue(String(e))})(n,t,e)),r.required&&void 0===n&&ue("Missing required property"),I(n,""))r.maxLength&&n.length>r.maxLength&&(r.strict&&ue("Value exceeds maxLength"),n=n.substring(0,r.maxLength));else if(I(n,1))I(r.min,1)&&n<r.min?(r.strict&&ue("Value below min"),n=r.min):I(r.max,1)&&n>r.max&&(r.strict&&ue("Value exceeds max"),n=r.max);else if(I(n,{})){if(r.schema){const e=r.schema;Object.keys(e).reduce((t,n)=>{const r=e[n];let o=t[n];return r&&(r.type&&typeof o!==r.type&&ue(`Type doesn't match (${n})`),o=Z(we,e=>{ue(String(e))})(t,n,o,r)),o},n)}for(const e of Object.keys(n))r.allowedKeys&&!r.allowedKeys.includes(e)&&(r.strict&&ue("Key not allowed"),delete n[e])}return n}//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";var e,t,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,s=(e={"package.json"(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.1.1",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/core"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","web analytics","product analytics","core","types","utils"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return t||(0,e[o(e)[0]])((t={exports:{}}).exports,t),t.exports}),a={};((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})(a,{Collector:()=>c,Const:()=>k,Data:()=>u,Destination:()=>l,Elb:()=>p,Flow:()=>d,Handler:()=>g,Hooks:()=>m,Mapping:()=>f,On:()=>y,Request:()=>h,Schema:()=>b,Source:()=>w,WalkerOS:()=>v,anonymizeIP:()=>x,assign:()=>j,castToProperty:()=>Q,castValue:()=>L,clone:()=>V,createDestination:()=>R,createEvent:()=>q,debounce:()=>F,filterValues:()=>J,getBrowser:()=>de,getBrowserVersion:()=>ge,getByPath:()=>_,getDeviceType:()=>ye,getEvent:()=>K,getGrantedConsent:()=>B,getHeaders:()=>ae,getId:()=>U,getMappingEvent:()=>ee,getMappingValue:()=>te,getMarketingParameters:()=>W,getOS:()=>me,getOSVersion:()=>fe,isArguments:()=>S,isArray:()=>E,isBoolean:()=>P,isCommand:()=>T,isDefined:()=>A,isElementOrDocument:()=>M,isFunction:()=>D,isNumber:()=>C,isObject:()=>$,isPropertyType:()=>X,isSameType:()=>I,isString:()=>N,onLog:()=>re,parseUserAgent:()=>pe,requestToData:()=>oe,requestToParameter:()=>ie,setByPath:()=>H,throttle:()=>G,throwError:()=>ce,transformData:()=>se,trim:()=>ue,tryCatch:()=>Y,tryCatchAsync:()=>Z,useHooks:()=>le,validateEvent:()=>he,validateProperty:()=>be}),module.exports=(e=>((e,t,s,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of o(t))i.call(e,c)||c===s||n(e,c,{get:()=>t[c],enumerable:!(a=r(t,c))||a.enumerable});return e})(n({},"__esModule",{value:!0}),e))(a);var c={},u={},l={},p={},d={},g={},m={},f={},y={},h={},b={},w={},v={},k={Utils:{Storage:{Local:"local",Session:"session",Cookie:"cookie"}}};function x(e){return/^(?:\d{1,3}\.){3}\d{1,3}$/.test(e)?e.replace(/\.\d+$/,".0"):""}var O={merge:!0,shallow:!0,extend:!0};function j(e,t={},n={}){n={...O,...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 S(e){return"[object Arguments]"===Object.prototype.toString.call(e)}function E(e){return Array.isArray(e)}function P(e){return"boolean"==typeof e}function T(e){return"walker"===e}function A(e){return void 0!==e}function M(e){return e===document||e instanceof Element}function D(e){return"function"==typeof e}function C(e){return"number"==typeof e&&!Number.isNaN(e)}function $(e){return"object"==typeof e&&null!==e&&!E(e)&&"[object Object]"===Object.prototype.toString.call(e)}function I(e,t){return typeof e==typeof t}function N(e){return"string"==typeof e}function V(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]=V(e[r],t));return n}if("[object Array]"===n){const n=[];return t.set(e,n),e.forEach(e=>{n.push(V(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 _(e,t="",n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const t=r[e];if("*"===t&&E(o)){const t=r.slice(e+1).join("."),i=[];for(const e of o){const r=_(e,t,n);i.push(r)}return i}if(o=o instanceof Object?o[t]:void 0,!o)break}return A(o)?o:n}function H(e,t,n){const r=V(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 L(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}function B(e,t={},n={}){const r={...t,...n},o={};let i=void 0===e;return Object.keys(r).forEach(t=>{r[t]&&(o[t]=!0,e&&e[t]&&(i=!0))}),!!i&&o}function R(e,t){const n={...e};return n.config=j(e.config,t,{shallow:!0,merge:!0,extend:!0}),e.config.settings&&t.settings&&(n.config.settings=j(e.config.settings,t.settings,{shallow:!0,merge:!0,extend:!0})),e.config.mapping&&t.mapping&&(n.config.mapping=j(e.config.mapping,t.mapping,{shallow:!0,merge:!0,extend:!0})),n}var{version:z}=s();function q(e={}){const t=e.timestamp||(new Date).setHours(0,13,37,0),n=e.group||"gr0up",r=e.count||1,o=j({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"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${t}-${n}-${r}`,trigger:"test",entity:"entity",action:"action",timestamp:t,timing:3.14,group:n,count:r,version:{source:z,tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.name){const[t,n]=e.name.split(" ")??[];t&&n&&(o.entity=t,o.action=n)}return o}function K(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 q({...{"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.elbwalker.com/",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 U(e=6){let t="";for(let n=36;t.length<e;)t+=(Math.random()*n|0).toString(n);return t}function W(e,t={}){const n="clickId",r={},o={utm_campaign:"campaign",utm_content:"content",utm_medium:"medium",utm_source:"source",utm_term:"term",dclid:n,fbclid:n,gclid:n,msclkid:n,ttclid:n,twclid:n,igshid:n,sclid:n};return Object.entries(j(o,t)).forEach(([t,o])=>{const i=e.searchParams.get(t);i&&(o===n&&(o=t,r[n]=t),r[o]=i)}),r}function F(e,t=1e3,n=!1){let r,o=null,i=!1;return(...s)=>new Promise(a=>{const c=n&&!i;o&&clearTimeout(o),o=setTimeout(()=>{o=null,n&&!i||(r=e(...s),a(r))},t),c&&(i=!0,r=e(...s),a(r))})}function G(e,t=1e3){let n=null;return function(...r){if(null===n)return n=setTimeout(()=>{n=null},t),e(...r)}}function X(e){return P(e)||N(e)||C(e)||!A(e)||E(e)&&e.every(X)||$(e)&&Object.values(e).every(X)}function J(e){return P(e)||N(e)||C(e)?e:S(e)?J(Array.from(e)):E(e)?e.map(e=>J(e)).filter(e=>void 0!==e):$(e)?Object.entries(e).reduce((e,[t,n])=>{const r=J(n);return void 0!==r&&(e[t]=r),e},{}):void 0}function Q(e){return X(e)?e:void 0}function Y(e,t,n){return function(...r){try{return e(...r)}catch(e){if(!t)return;return t(e)}finally{n?.()}}}function Z(e,t,n){return async function(...r){try{return await e(...r)}catch(e){if(!t)return;return await t(e)}finally{await(n?.())}}}async function ee(e,t){const[n,r]=(e.name||"").split(" ");if(!t||!n||!r)return{};let o,i="",s=n,a=r;const c=t=>{if(t)return(t=E(t)?t:[t]).find(t=>!t.condition||t.condition(e))};t[s]||(s="*");const u=t[s];return u&&(u[a]||(a="*"),o=c(u[a])),o||(s="*",a="*",o=c(t[s]?.[a])),o&&(i=`${s} ${a}`),{eventMapping:o,mappingKey:i}}async function te(e,t={},n={}){if(!A(e))return;const r=$(e)&&e.consent||n.consent||n.collector?.consent,o=E(t)?t:[t];for(const t of o){const o=await Z(ne)(e,t,{...n,consent:r});if(A(o))return o}}async function ne(e,t,n={}){const{collector:r,consent:o}=n;return(E(t)?t:[t]).reduce(async(t,i)=>{const s=await t;if(s)return s;const a=N(i)?{key:i}:i;if(!Object.keys(a).length)return;const{condition:c,consent:u,fn:l,key:p,loop:d,map:g,set:m,validate:f,value:y}=a;if(c&&!await Z(c)(e,i,r))return;if(u&&!B(u,o))return y;let h=A(y)?y:e;if(l&&(h=await Z(l)(e,i,n)),p&&(h=_(e,p,y)),d){const[t,r]=d,o="this"===t?[e]:await te(e,t,n);E(o)&&(h=(await Promise.all(o.map(e=>te(e,r,n)))).filter(A))}else g?h=await Object.entries(g).reduce(async(t,[r,o])=>{const i=await t,s=await te(e,o,n);return A(s)&&(i[r]=s),i},Promise.resolve({})):m&&(h=await Promise.all(m.map(t=>ne(e,t,n))));f&&!await Z(f)(h)&&(h=void 0);const b=Q(h);return A(b)?b:Q(y)},Promise.resolve(void 0))}function re(e,t=!1){t&&console.dir(e,{depth:4})}function oe(e){const t=String(e),n=t.split("?")[1]||t;return Y(()=>{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(E(o)){const s=parseInt(t,10);i?o[s]=L(e):(o[s]=o[s]||(isNaN(parseInt(r[n+1],10))?{}:[]),o=o[s])}else $(o)&&(i?o[t]=L(e):(o[t]=o[t]||(isNaN(parseInt(r[n+1],10))?{}:[]),o=o[t]))})}),t})()}function ie(e){if(!e)return"";const t=[],n=encodeURIComponent;function r(e,o){null!=o&&(E(o)?o.forEach((t,n)=>r(`${e}[${n}]`,t)):$(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 se(e){return void 0===e||I(e,"")?e:JSON.stringify(e)}function ae(e={}){return j({"Content-Type":"application/json; charset=utf-8"},e)}function ce(e){throw new Error(String(e))}function ue(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function le(e,t,n){return function(...r){let o;const i="post"+t,s=n["pre"+t],a=n[i];return o=s?s({fn:e},...r):e(...r),a&&(o=a({fn:e,result:o},...r)),o}}function pe(e){return e?{userAgent:e,browser:de(e),browserVersion:ge(e),os:me(e),osVersion:fe(e),deviceType:ye(e)}:{}}function de(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 ge(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 me(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 fe(e){const t=e.match(/(?:Windows NT|Mac OS X|Android|iPhone OS) ([0-9._]+)/);return t?t[1].replace(/_/g,"."):void 0}function ye(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 he(e,t=[]){let n,r,o;I(e,{})||ce("Invalid object"),I(e.name,"")?(n=e.name,[r,o]=n.split(" "),r&&o||ce("Invalid event name")):I(e.entity,"")&&I(e.action,"")?(r=e.entity,o=e.action,n=`${r} ${o}`):ce("Missing or invalid name, entity, or action");const i={name:n,data:{},context:{},custom:{},globals:{},user:{},nested:[],consent:{},id:"",trigger:"",entity:r,action:o,timestamp:0,timing:0,group:"",count:0,version:{source:"",tagging:0},source:{type:"",id:"",previous_id:""}};return[{"*":{"*":{name:{maxLength:255},user:{allowedKeys:["id","device","session"]},consent:{allowedValues:[!0,!1]},timestamp:{min:0},timing:{min:0},count:{min:0},version:{allowedKeys:["source","tagging"]},source:{allowedKeys:["type","id","previous_id"]}}}}].concat(t).reduce((e,t)=>["*",r].reduce((e,n)=>["*",o].reduce((e,r)=>{const o=t[n]?.[r];return o?e.concat([o]):e},e),e),[]).reduce((t,n)=>{const r=Object.keys(n).filter(e=>{const t=n[e];return!0===t?.required});return[...Object.keys(e),...r].reduce((t,r)=>{const o=n[r];let i=e[r];return o&&(i=Y(be,e=>{ce(String(e))})(t,r,i,o)),I(i,t[r])&&(t[r]=i),t},t)},i)}function be(e,t,n,r){if(r.validate&&(n=Y(r.validate,e=>{ce(String(e))})(n,t,e)),r.required&&void 0===n&&ce("Missing required property"),I(n,""))r.maxLength&&n.length>r.maxLength&&(r.strict&&ce("Value exceeds maxLength"),n=n.substring(0,r.maxLength));else if(I(n,1))I(r.min,1)&&n<r.min?(r.strict&&ce("Value below min"),n=r.min):I(r.max,1)&&n>r.max&&(r.strict&&ce("Value exceeds max"),n=r.max);else if(I(n,{})){if(r.schema){const e=r.schema;Object.keys(e).reduce((t,n)=>{const r=e[n];let o=t[n];return r&&(r.type&&typeof o!==r.type&&ce(`Type doesn't match (${n})`),o=Y(be,e=>{ce(String(e))})(t,n,o,r)),o},n)}for(const e of Object.keys(n))r.allowedKeys&&!r.allowedKeys.includes(e)&&(r.strict&&ce("Key not allowed"),delete n[e])}return n}//# sourceMappingURL=index.js.map
|