@walkeros/core 0.1.1 → 0.2.0
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 +261 -136
- package/dist/index.d.ts +261 -136
- 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
|
@@ -4,24 +4,12 @@
|
|
|
4
4
|
interface Config$4 {
|
|
5
5
|
/** Whether to run collector automatically */
|
|
6
6
|
run?: boolean;
|
|
7
|
-
/** Initial consent state */
|
|
8
|
-
consent?: Consent;
|
|
9
|
-
/** Initial user data */
|
|
10
|
-
user?: User;
|
|
11
7
|
/** Version for event tagging */
|
|
12
8
|
tagging: number;
|
|
13
|
-
/** Initial global properties */
|
|
14
|
-
globals?: Properties;
|
|
15
9
|
/** Static global properties even on a new run */
|
|
16
10
|
globalsStatic: Properties;
|
|
17
11
|
/** Static session data even on a new run */
|
|
18
12
|
sessionStatic: Partial<SessionData>;
|
|
19
|
-
/** Source configurations */
|
|
20
|
-
sources?: InitSources;
|
|
21
|
-
/** Destination configurations */
|
|
22
|
-
destinations?: InitDestinations;
|
|
23
|
-
/** Initial custom properties */
|
|
24
|
-
custom?: Properties;
|
|
25
13
|
/** Enable verbose logging */
|
|
26
14
|
verbose: boolean;
|
|
27
15
|
/** Error handler */
|
|
@@ -29,7 +17,23 @@ interface Config$4 {
|
|
|
29
17
|
/** Log handler */
|
|
30
18
|
onLog?: Log;
|
|
31
19
|
}
|
|
32
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Initialization configuration that extends Config with initial state
|
|
22
|
+
*/
|
|
23
|
+
interface InitConfig extends Partial<Config$4> {
|
|
24
|
+
/** Initial consent state */
|
|
25
|
+
consent?: Consent;
|
|
26
|
+
/** Initial user data */
|
|
27
|
+
user?: User;
|
|
28
|
+
/** Initial global properties */
|
|
29
|
+
globals?: Properties;
|
|
30
|
+
/** Source configurations */
|
|
31
|
+
sources?: InitSources;
|
|
32
|
+
/** Destination configurations */
|
|
33
|
+
destinations?: InitDestinations;
|
|
34
|
+
/** Initial custom properties */
|
|
35
|
+
custom?: Properties;
|
|
36
|
+
}
|
|
33
37
|
interface SessionData extends Properties {
|
|
34
38
|
isStart: boolean;
|
|
35
39
|
storage: boolean;
|
|
@@ -71,10 +75,11 @@ interface Instance$2 {
|
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
type collector_CommandType = CommandType;
|
|
78
|
+
type collector_InitConfig = InitConfig;
|
|
74
79
|
type collector_SessionData = SessionData;
|
|
75
80
|
type collector_Sources = Sources;
|
|
76
81
|
declare namespace collector {
|
|
77
|
-
export type { collector_CommandType as CommandType, Config$4 as Config, Destinations$1 as Destinations,
|
|
82
|
+
export type { collector_CommandType as CommandType, Config$4 as Config, Destinations$1 as Destinations, collector_InitConfig as InitConfig, Instance$2 as Instance, collector_SessionData as SessionData, collector_Sources as Sources };
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
interface Contract$1 {
|
|
@@ -87,7 +92,7 @@ interface Globals {
|
|
|
87
92
|
[name: string]: Global;
|
|
88
93
|
}
|
|
89
94
|
interface Contexts {
|
|
90
|
-
[name: string]: Context$
|
|
95
|
+
[name: string]: Context$3;
|
|
91
96
|
}
|
|
92
97
|
interface Entities$1 {
|
|
93
98
|
[name: string]: Entity$1;
|
|
@@ -97,7 +102,7 @@ interface Properties$2 {
|
|
|
97
102
|
}
|
|
98
103
|
interface Global extends Property$2 {
|
|
99
104
|
}
|
|
100
|
-
interface Context$
|
|
105
|
+
interface Context$3 extends Property$2 {
|
|
101
106
|
}
|
|
102
107
|
interface Entity$1 {
|
|
103
108
|
data: Properties$2;
|
|
@@ -126,65 +131,106 @@ type data_Globals = Globals;
|
|
|
126
131
|
type data_PropertyValues = PropertyValues;
|
|
127
132
|
type data_Trigger = Trigger;
|
|
128
133
|
declare namespace data {
|
|
129
|
-
export type { data_Action as Action, data_Actions as Actions, Context$
|
|
134
|
+
export type { data_Action as Action, data_Actions as Actions, Context$3 as Context, data_Contexts as Contexts, Contract$1 as Contract, Entities$1 as Entities, Entity$1 as Entity, data_Global as Global, data_Globals as Globals, Properties$2 as Properties, Property$2 as Property, PropertyType$1 as PropertyType, data_PropertyValues as PropertyValues, data_Trigger as Trigger };
|
|
130
135
|
}
|
|
131
136
|
|
|
132
|
-
|
|
133
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Base environment requirements interface for walkerOS destinations
|
|
139
|
+
*
|
|
140
|
+
* This defines the core interface that destinations can use to declare
|
|
141
|
+
* their runtime environment requirements. Platform-specific extensions
|
|
142
|
+
* should extend this interface.
|
|
143
|
+
*/
|
|
144
|
+
interface BaseEnv$1 {
|
|
145
|
+
/**
|
|
146
|
+
* Generic global properties that destinations may require
|
|
147
|
+
* Platform-specific implementations can extend this interface
|
|
148
|
+
*/
|
|
149
|
+
[key: string]: unknown;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Type bundle for destination generics.
|
|
153
|
+
* Groups Settings, Mapping, and Env into a single type parameter.
|
|
154
|
+
*/
|
|
155
|
+
interface Types$2<S = unknown, M = unknown, E = BaseEnv$1> {
|
|
156
|
+
settings: S;
|
|
157
|
+
mapping: M;
|
|
158
|
+
env: E;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Generic constraint for Types - ensures T has required properties for indexed access
|
|
162
|
+
*/
|
|
163
|
+
type TypesGeneric$1 = {
|
|
164
|
+
settings: any;
|
|
165
|
+
mapping: any;
|
|
166
|
+
env: any;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Type extractors for consistent usage with Types bundle
|
|
170
|
+
*/
|
|
171
|
+
type Settings$1<T extends TypesGeneric$1 = Types$2> = T['settings'];
|
|
172
|
+
type Mapping$1<T extends TypesGeneric$1 = Types$2> = T['mapping'];
|
|
173
|
+
type Env$1<T extends TypesGeneric$1 = Types$2> = T['env'];
|
|
174
|
+
/**
|
|
175
|
+
* Inference helper: Extract Types from Instance
|
|
176
|
+
*/
|
|
177
|
+
type TypesOf$1<I> = I extends Instance$1<infer T> ? T : never;
|
|
178
|
+
interface Instance$1<T extends TypesGeneric$1 = Types$2> {
|
|
179
|
+
config: Config$3<T>;
|
|
134
180
|
queue?: Events;
|
|
135
181
|
dlq?: DLQ;
|
|
136
182
|
type?: string;
|
|
137
|
-
env?:
|
|
138
|
-
init?: InitFn<
|
|
139
|
-
push: PushFn<
|
|
140
|
-
pushBatch?: PushBatchFn<
|
|
141
|
-
on
|
|
183
|
+
env?: Env$1<T>;
|
|
184
|
+
init?: InitFn<T>;
|
|
185
|
+
push: PushFn<T>;
|
|
186
|
+
pushBatch?: PushBatchFn<T>;
|
|
187
|
+
on?: OnFn;
|
|
142
188
|
}
|
|
143
|
-
interface Config$3<
|
|
189
|
+
interface Config$3<T extends TypesGeneric$1 = Types$2> {
|
|
144
190
|
consent?: Consent;
|
|
145
|
-
settings?: Settings
|
|
191
|
+
settings?: Settings$1<T>;
|
|
146
192
|
data?: Value | Values;
|
|
147
|
-
env?:
|
|
193
|
+
env?: Env$1<T>;
|
|
148
194
|
id?: string;
|
|
149
195
|
init?: boolean;
|
|
150
196
|
loadScript?: boolean;
|
|
151
|
-
mapping?: Rules<Rule<Mapping
|
|
152
|
-
policy?: Policy;
|
|
197
|
+
mapping?: Rules<Rule<Mapping$1<T>>>;
|
|
198
|
+
policy?: Policy$1;
|
|
153
199
|
queue?: boolean;
|
|
154
200
|
verbose?: boolean;
|
|
155
201
|
onError?: Error;
|
|
156
202
|
onLog?: Log;
|
|
157
203
|
}
|
|
158
|
-
type PartialConfig<
|
|
159
|
-
interface Policy {
|
|
204
|
+
type PartialConfig$1<T extends TypesGeneric$1 = Types$2> = Config$3<Types$2<Partial<Settings$1<T>> | Settings$1<T>, Partial<Mapping$1<T>> | Mapping$1<T>, Env$1<T>>>;
|
|
205
|
+
interface Policy$1 {
|
|
160
206
|
[key: string]: Value;
|
|
161
207
|
}
|
|
162
|
-
type Init$1<
|
|
163
|
-
code: Instance$1<
|
|
164
|
-
config?: Partial<Config$3<
|
|
165
|
-
env?: Partial<
|
|
208
|
+
type Init$1<T extends TypesGeneric$1 = Types$2> = {
|
|
209
|
+
code: Instance$1<T>;
|
|
210
|
+
config?: Partial<Config$3<T>>;
|
|
211
|
+
env?: Partial<Env$1<T>>;
|
|
166
212
|
};
|
|
167
213
|
interface InitDestinations {
|
|
168
|
-
[key: string]: Init$1<any
|
|
214
|
+
[key: string]: Init$1<any>;
|
|
169
215
|
}
|
|
170
216
|
interface Destinations {
|
|
171
217
|
[key: string]: Instance$1;
|
|
172
218
|
}
|
|
173
|
-
interface Context$
|
|
219
|
+
interface Context$2<T extends TypesGeneric$1 = Types$2> {
|
|
174
220
|
collector: Instance$2;
|
|
175
|
-
config: Config$3<
|
|
221
|
+
config: Config$3<T>;
|
|
176
222
|
data?: Data$1;
|
|
177
|
-
env:
|
|
223
|
+
env: Env$1<T>;
|
|
178
224
|
}
|
|
179
|
-
interface PushContext<
|
|
180
|
-
mapping?: Rule<Mapping
|
|
225
|
+
interface PushContext<T extends TypesGeneric$1 = Types$2> extends Context$2<T> {
|
|
226
|
+
mapping?: Rule<Mapping$1<T>>;
|
|
181
227
|
}
|
|
182
|
-
interface PushBatchContext<
|
|
183
|
-
mapping?: Rule<Mapping
|
|
228
|
+
interface PushBatchContext<T extends TypesGeneric$1 = Types$2> extends Context$2<T> {
|
|
229
|
+
mapping?: Rule<Mapping$1<T>>;
|
|
184
230
|
}
|
|
185
|
-
type InitFn<
|
|
186
|
-
type PushFn<
|
|
187
|
-
type PushBatchFn<
|
|
231
|
+
type InitFn<T extends TypesGeneric$1 = Types$2> = (context: Context$2<T>) => PromiseOrValue<void | false | Config$3<T>>;
|
|
232
|
+
type PushFn<T extends TypesGeneric$1 = Types$2> = (event: Event, context: PushContext<T>) => PromiseOrValue<void>;
|
|
233
|
+
type PushBatchFn<T extends TypesGeneric$1 = Types$2> = (batch: Batch<Mapping$1<T>>, context: PushBatchContext<T>) => void;
|
|
188
234
|
type PushEvent<Mapping = unknown> = {
|
|
189
235
|
event: Event;
|
|
190
236
|
mapping?: Rule<Mapping>;
|
|
@@ -201,7 +247,7 @@ type Ref = {
|
|
|
201
247
|
id: string;
|
|
202
248
|
destination: Instance$1;
|
|
203
249
|
};
|
|
204
|
-
type Push = {
|
|
250
|
+
type Push$1 = {
|
|
205
251
|
queue?: Events;
|
|
206
252
|
error?: unknown;
|
|
207
253
|
};
|
|
@@ -211,38 +257,21 @@ type Result$1 = {
|
|
|
211
257
|
queued: Array<Ref>;
|
|
212
258
|
failed: Array<Ref>;
|
|
213
259
|
};
|
|
214
|
-
/**
|
|
215
|
-
* Base environment requirements interface for walkerOS destinations
|
|
216
|
-
*
|
|
217
|
-
* This defines the core interface that destinations can use to declare
|
|
218
|
-
* their runtime environment requirements. Platform-specific extensions
|
|
219
|
-
* should extend this interface.
|
|
220
|
-
*/
|
|
221
|
-
interface Environment$1 {
|
|
222
|
-
/**
|
|
223
|
-
* Generic global properties that destinations may require
|
|
224
|
-
* Platform-specific implementations can extend this interface
|
|
225
|
-
*/
|
|
226
|
-
[key: string]: unknown;
|
|
227
|
-
}
|
|
228
260
|
|
|
229
261
|
type destination_Batch<Mapping> = Batch<Mapping>;
|
|
230
262
|
type destination_DLQ = DLQ;
|
|
231
263
|
type destination_Destinations = Destinations;
|
|
232
264
|
type destination_InitDestinations = InitDestinations;
|
|
233
|
-
type destination_InitFn<
|
|
234
|
-
type
|
|
235
|
-
type
|
|
236
|
-
type
|
|
237
|
-
type destination_PushBatchContext<Settings = unknown, Mapping = unknown> = PushBatchContext<Settings, Mapping>;
|
|
238
|
-
type destination_PushBatchFn<Settings, Mapping> = PushBatchFn<Settings, Mapping>;
|
|
239
|
-
type destination_PushContext<Settings = unknown, Mapping = unknown> = PushContext<Settings, Mapping>;
|
|
265
|
+
type destination_InitFn<T extends TypesGeneric$1 = Types$2> = InitFn<T>;
|
|
266
|
+
type destination_PushBatchContext<T extends TypesGeneric$1 = Types$2> = PushBatchContext<T>;
|
|
267
|
+
type destination_PushBatchFn<T extends TypesGeneric$1 = Types$2> = PushBatchFn<T>;
|
|
268
|
+
type destination_PushContext<T extends TypesGeneric$1 = Types$2> = PushContext<T>;
|
|
240
269
|
type destination_PushEvent<Mapping = unknown> = PushEvent<Mapping>;
|
|
241
270
|
type destination_PushEvents<Mapping = unknown> = PushEvents<Mapping>;
|
|
242
|
-
type destination_PushFn<
|
|
271
|
+
type destination_PushFn<T extends TypesGeneric$1 = Types$2> = PushFn<T>;
|
|
243
272
|
type destination_Ref = Ref;
|
|
244
273
|
declare namespace destination {
|
|
245
|
-
export type { destination_Batch as Batch, Config$3 as Config, Context$
|
|
274
|
+
export type { BaseEnv$1 as BaseEnv, destination_Batch as Batch, Config$3 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_InitDestinations as InitDestinations, destination_InitFn as InitFn, 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 };
|
|
246
275
|
}
|
|
247
276
|
|
|
248
277
|
interface EventFn<R = Promise<PushResult>> {
|
|
@@ -255,9 +284,9 @@ interface Fn$1<R = Promise<PushResult>, Config = unknown> extends EventFn<R>, Wa
|
|
|
255
284
|
interface WalkerCommands<R = Promise<PushResult>, Config = unknown> {
|
|
256
285
|
(event: 'walker config', config: Partial<Config>): R;
|
|
257
286
|
(event: 'walker consent', consent: Consent): R;
|
|
258
|
-
(event: 'walker destination', destination: Init$1 | Instance$1
|
|
287
|
+
<T extends Types$2>(event: 'walker destination', destination: Init$1<T> | Instance$1<T>, config?: Config$3<T>): R;
|
|
259
288
|
<K extends keyof Functions>(event: 'walker hook', name: K, hookFn: Functions[K]): R;
|
|
260
|
-
(event: 'walker on', type: Types, rules: SingleOrArray<Options>): R;
|
|
289
|
+
(event: 'walker on', type: Types$1, rules: SingleOrArray<Options>): R;
|
|
261
290
|
(event: 'walker user', user: User): R;
|
|
262
291
|
(event: 'walker run', runState: {
|
|
263
292
|
consent?: Consent;
|
|
@@ -273,18 +302,14 @@ interface PushResult extends Result$1 {
|
|
|
273
302
|
ok: boolean;
|
|
274
303
|
}
|
|
275
304
|
type Layer = Array<IArguments | DeepPartialEvent | unknown[]>;
|
|
276
|
-
interface RegisterDestination<Destination, Config> {
|
|
277
|
-
(event: 'walker destination', destination: Destination, config?: Config): Promise<PushResult>;
|
|
278
|
-
}
|
|
279
305
|
|
|
280
306
|
type elb_EventFn<R = Promise<PushResult>> = EventFn<R>;
|
|
281
307
|
type elb_Layer = Layer;
|
|
282
308
|
type elb_PushData<Config = unknown> = PushData<Config>;
|
|
283
309
|
type elb_PushResult = PushResult;
|
|
284
|
-
type elb_RegisterDestination<Destination, Config> = RegisterDestination<Destination, Config>;
|
|
285
310
|
type elb_WalkerCommands<R = Promise<PushResult>, Config = unknown> = WalkerCommands<R, Config>;
|
|
286
311
|
declare namespace elb {
|
|
287
|
-
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,
|
|
312
|
+
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 };
|
|
288
313
|
}
|
|
289
314
|
|
|
290
315
|
/**
|
|
@@ -396,7 +421,19 @@ type Config$1 = {
|
|
|
396
421
|
run?: Array<RunConfig>;
|
|
397
422
|
session?: Array<SessionConfig>;
|
|
398
423
|
};
|
|
399
|
-
type Types = keyof Config$1;
|
|
424
|
+
type Types$1 = keyof Config$1;
|
|
425
|
+
interface EventContextMap {
|
|
426
|
+
consent: Consent;
|
|
427
|
+
session: SessionData;
|
|
428
|
+
ready: undefined;
|
|
429
|
+
run: undefined;
|
|
430
|
+
}
|
|
431
|
+
type EventContext<T extends Types$1> = EventContextMap[T];
|
|
432
|
+
type AnyEventContext = EventContextMap[keyof EventContextMap];
|
|
433
|
+
interface Context$1 {
|
|
434
|
+
consent?: Consent;
|
|
435
|
+
session?: unknown;
|
|
436
|
+
}
|
|
400
437
|
type Options = ConsentConfig | ReadyConfig | RunConfig | SessionConfig;
|
|
401
438
|
interface ConsentConfig {
|
|
402
439
|
[key: string]: ConsentFn;
|
|
@@ -415,10 +452,17 @@ interface OnConfig {
|
|
|
415
452
|
session?: SessionConfig[];
|
|
416
453
|
[key: string]: ConsentConfig[] | ReadyConfig[] | RunConfig[] | SessionConfig[] | undefined;
|
|
417
454
|
}
|
|
455
|
+
type OnFn = <T extends Types$1>(event: T, context: EventContextMap[T]) => PromiseOrValue<void>;
|
|
456
|
+
type OnFnRuntime = (event: Types$1, context: AnyEventContext) => PromiseOrValue<void>;
|
|
418
457
|
|
|
458
|
+
type on_AnyEventContext = AnyEventContext;
|
|
419
459
|
type on_ConsentConfig = ConsentConfig;
|
|
420
460
|
type on_ConsentFn = ConsentFn;
|
|
461
|
+
type on_EventContext<T extends Types$1> = EventContext<T>;
|
|
462
|
+
type on_EventContextMap = EventContextMap;
|
|
421
463
|
type on_OnConfig = OnConfig;
|
|
464
|
+
type on_OnFn = OnFn;
|
|
465
|
+
type on_OnFnRuntime = OnFnRuntime;
|
|
422
466
|
type on_Options = Options;
|
|
423
467
|
type on_ReadyConfig = ReadyConfig;
|
|
424
468
|
type on_ReadyFn = ReadyFn;
|
|
@@ -426,9 +470,8 @@ type on_RunConfig = RunConfig;
|
|
|
426
470
|
type on_RunFn = RunFn;
|
|
427
471
|
type on_SessionConfig = SessionConfig;
|
|
428
472
|
type on_SessionFn = SessionFn;
|
|
429
|
-
type on_Types = Types;
|
|
430
473
|
declare namespace on {
|
|
431
|
-
export type { Config$1 as Config, on_ConsentConfig as ConsentConfig, on_ConsentFn as ConsentFn, on_OnConfig as OnConfig, on_Options as Options, on_ReadyConfig as ReadyConfig, on_ReadyFn as ReadyFn, on_RunConfig as RunConfig, on_RunFn as RunFn, on_SessionConfig as SessionConfig, on_SessionFn as SessionFn,
|
|
474
|
+
export type { on_AnyEventContext as AnyEventContext, Config$1 as Config, on_ConsentConfig as ConsentConfig, on_ConsentFn as ConsentFn, Context$1 as Context, on_EventContext as EventContext, on_EventContextMap as EventContextMap, on_OnConfig as OnConfig, on_OnFn as OnFn, on_OnFnRuntime as OnFnRuntime, on_Options as Options, on_ReadyConfig as ReadyConfig, on_ReadyFn as ReadyFn, on_RunConfig as RunConfig, on_RunFn as RunFn, on_SessionConfig as SessionConfig, on_SessionFn as SessionFn, Types$1 as Types };
|
|
432
475
|
}
|
|
433
476
|
|
|
434
477
|
interface Context {
|
|
@@ -477,55 +520,76 @@ declare namespace schema {
|
|
|
477
520
|
export type { schema_Contract as Contract, schema_Contracts as Contracts, Properties$1 as Properties, Property$1 as Property };
|
|
478
521
|
}
|
|
479
522
|
|
|
480
|
-
interface Config {
|
|
481
|
-
id?: string;
|
|
482
|
-
disabled?: boolean;
|
|
483
|
-
settings: AnyObject;
|
|
484
|
-
onError?: AnyFunction;
|
|
485
|
-
}
|
|
486
|
-
type InitConfig = Partial<Config>;
|
|
487
523
|
/**
|
|
488
|
-
*
|
|
524
|
+
* Base Env interface for dependency injection into sources.
|
|
489
525
|
*
|
|
490
526
|
* Sources receive all their dependencies through this environment object,
|
|
491
527
|
* making them platform-agnostic and easily testable.
|
|
492
528
|
*/
|
|
493
|
-
interface
|
|
529
|
+
interface BaseEnv {
|
|
494
530
|
elb: Fn$1;
|
|
495
531
|
[key: string]: unknown;
|
|
496
532
|
}
|
|
497
533
|
/**
|
|
498
|
-
*
|
|
534
|
+
* Type bundle for source generics.
|
|
535
|
+
* Groups Settings, Mapping, Push, and Env into a single type parameter.
|
|
499
536
|
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
537
|
+
* @template S - Settings configuration type
|
|
538
|
+
* @template M - Mapping configuration type
|
|
539
|
+
* @template P - Push function signature (flexible to support HTTP handlers, etc.)
|
|
540
|
+
* @template E - Environment dependencies type
|
|
502
541
|
*/
|
|
503
|
-
interface
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
push:
|
|
507
|
-
|
|
508
|
-
on?(event: Types, context?: unknown): void | Promise<void>;
|
|
542
|
+
interface Types<S = unknown, M = unknown, P = Fn$1, E = BaseEnv> {
|
|
543
|
+
settings: S;
|
|
544
|
+
mapping: M;
|
|
545
|
+
push: P;
|
|
546
|
+
env: E;
|
|
509
547
|
}
|
|
510
548
|
/**
|
|
511
|
-
*
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
549
|
+
* Generic constraint for Types - ensures T has required properties for indexed access
|
|
550
|
+
*/
|
|
551
|
+
type TypesGeneric = {
|
|
552
|
+
settings: any;
|
|
553
|
+
mapping: any;
|
|
554
|
+
push: any;
|
|
555
|
+
env: any;
|
|
556
|
+
};
|
|
557
|
+
/**
|
|
558
|
+
* Type extractors for consistent usage with Types bundle
|
|
519
559
|
*/
|
|
520
|
-
type
|
|
560
|
+
type Settings<T extends TypesGeneric = Types> = T['settings'];
|
|
561
|
+
type Mapping<T extends TypesGeneric = Types> = T['mapping'];
|
|
562
|
+
type Push<T extends TypesGeneric = Types> = T['push'];
|
|
563
|
+
type Env<T extends TypesGeneric = Types> = T['env'];
|
|
521
564
|
/**
|
|
522
|
-
*
|
|
523
|
-
* Similar to destinations, this defines the structure for source definitions.
|
|
565
|
+
* Inference helper: Extract Types from Instance
|
|
524
566
|
*/
|
|
525
|
-
type
|
|
567
|
+
type TypesOf<I> = I extends Instance<infer T> ? T : never;
|
|
568
|
+
interface Config<T extends TypesGeneric = Types> {
|
|
569
|
+
settings?: Settings<T>;
|
|
570
|
+
env?: Env<T>;
|
|
571
|
+
id?: string;
|
|
572
|
+
onError?: Error;
|
|
573
|
+
disabled?: boolean;
|
|
574
|
+
primary?: boolean;
|
|
575
|
+
}
|
|
576
|
+
type PartialConfig<T extends TypesGeneric = Types> = Config<Types<Partial<Settings<T>> | Settings<T>, Partial<Mapping<T>> | Mapping<T>, Push<T>, Env<T>>>;
|
|
577
|
+
interface Policy {
|
|
578
|
+
[key: string]: Value;
|
|
579
|
+
}
|
|
580
|
+
interface Instance<T extends TypesGeneric = Types> {
|
|
581
|
+
type: string;
|
|
582
|
+
config: Config<T>;
|
|
583
|
+
push: Push<T>;
|
|
584
|
+
destroy?(): void | Promise<void>;
|
|
585
|
+
on?(event: Types$1, context?: unknown): void | Promise<void>;
|
|
586
|
+
}
|
|
587
|
+
type Init<T extends TypesGeneric = Types> = (config: Partial<Config<T>>, env: Env<T>) => Instance<T> | Promise<Instance<T>>;
|
|
588
|
+
type InitSource<T extends TypesGeneric = Types> = {
|
|
526
589
|
code: Init<T>;
|
|
527
|
-
config?: T
|
|
528
|
-
env?: Partial<
|
|
590
|
+
config?: Partial<Config<T>>;
|
|
591
|
+
env?: Partial<Env<T>>;
|
|
592
|
+
primary?: boolean;
|
|
529
593
|
};
|
|
530
594
|
/**
|
|
531
595
|
* Sources configuration for collector.
|
|
@@ -535,27 +599,29 @@ interface InitSources {
|
|
|
535
599
|
[sourceId: string]: InitSource<any>;
|
|
536
600
|
}
|
|
537
601
|
|
|
538
|
-
type
|
|
539
|
-
type
|
|
540
|
-
type
|
|
541
|
-
type
|
|
542
|
-
type source_InitSource<T extends
|
|
602
|
+
type source_BaseEnv = BaseEnv;
|
|
603
|
+
type source_Config<T extends TypesGeneric = Types> = Config<T>;
|
|
604
|
+
type source_Env<T extends TypesGeneric = Types> = Env<T>;
|
|
605
|
+
type source_Init<T extends TypesGeneric = Types> = Init<T>;
|
|
606
|
+
type source_InitSource<T extends TypesGeneric = Types> = InitSource<T>;
|
|
543
607
|
type source_InitSources = InitSources;
|
|
544
|
-
type source_Instance<T extends
|
|
608
|
+
type source_Instance<T extends TypesGeneric = Types> = Instance<T>;
|
|
609
|
+
type source_Mapping<T extends TypesGeneric = Types> = Mapping<T>;
|
|
610
|
+
type source_PartialConfig<T extends TypesGeneric = Types> = PartialConfig<T>;
|
|
611
|
+
type source_Policy = Policy;
|
|
612
|
+
type source_Push<T extends TypesGeneric = Types> = Push<T>;
|
|
613
|
+
type source_Settings<T extends TypesGeneric = Types> = Settings<T>;
|
|
614
|
+
type source_Types<S = unknown, M = unknown, P = Fn$1, E = BaseEnv> = Types<S, M, P, E>;
|
|
615
|
+
type source_TypesGeneric = TypesGeneric;
|
|
616
|
+
type source_TypesOf<I> = TypesOf<I>;
|
|
545
617
|
declare namespace source {
|
|
546
|
-
export type {
|
|
618
|
+
export type { source_BaseEnv as BaseEnv, source_Config as Config, source_Env as Env, source_Init as Init, source_InitSource as InitSource, source_InitSources as InitSources, source_Instance as Instance, source_Mapping as Mapping, source_PartialConfig as PartialConfig, source_Policy as Policy, source_Push as Push, source_Settings as Settings, source_Types as Types, source_TypesGeneric as TypesGeneric, source_TypesOf as TypesOf };
|
|
547
619
|
}
|
|
548
620
|
|
|
549
621
|
type AnyObject<T = unknown> = Record<string, T>;
|
|
550
|
-
type Elb =
|
|
622
|
+
type Elb = Fn$1;
|
|
551
623
|
type AnyFunction = (...args: unknown[]) => unknown;
|
|
552
624
|
type SingleOrArray<T> = T | Array<T>;
|
|
553
|
-
declare global {
|
|
554
|
-
namespace WalkerOS {
|
|
555
|
-
interface Elb extends Fn$1 {
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
625
|
type Events = Array<Event>;
|
|
560
626
|
type PartialEvent = Partial<Event>;
|
|
561
627
|
type DeepPartialEvent = DeepPartial<Event>;
|
|
@@ -768,26 +834,19 @@ declare function getGrantedConsent(required: Consent | undefined, state?: Consen
|
|
|
768
834
|
* This utility enables elegant destination configuration while avoiding config side-effects
|
|
769
835
|
* that could occur when reusing destination objects across multiple collector instances.
|
|
770
836
|
*
|
|
771
|
-
* @template Settings - The destination settings type
|
|
772
|
-
* @template Mapping - The destination mapping type
|
|
773
837
|
* @param baseDestination - The base destination to extend
|
|
774
838
|
* @param config - Additional configuration to merge with the base destination's config
|
|
775
839
|
* @returns A new destination instance with merged configuration
|
|
776
840
|
*
|
|
777
841
|
* @example
|
|
778
842
|
* ```typescript
|
|
779
|
-
* //
|
|
780
|
-
* elb('walker destination', destinationGtag, {
|
|
781
|
-
* settings: { ga4: { measurementId: 'G-123' } }
|
|
782
|
-
* });
|
|
783
|
-
*
|
|
784
|
-
* // You can use:
|
|
843
|
+
* // Types are inferred automatically from destinationGtag
|
|
785
844
|
* elb('walker destination', createDestination(destinationGtag, {
|
|
786
845
|
* settings: { ga4: { measurementId: 'G-123' } }
|
|
787
846
|
* }));
|
|
788
847
|
* ```
|
|
789
848
|
*/
|
|
790
|
-
declare function createDestination<
|
|
849
|
+
declare function createDestination<I extends Instance$1>(baseDestination: I, config: Partial<Config$3<TypesOf$1<I>>>): I;
|
|
791
850
|
|
|
792
851
|
/**
|
|
793
852
|
* Creates a complete event with default values.
|
|
@@ -939,6 +998,72 @@ declare function getMappingEvent(event: PartialEvent, mapping?: Rules): Promise<
|
|
|
939
998
|
*/
|
|
940
999
|
declare function getMappingValue(value: DeepPartialEvent | unknown | undefined, data?: Data, options?: Options$1): Promise<Property | undefined>;
|
|
941
1000
|
|
|
1001
|
+
/**
|
|
1002
|
+
* Environment mocking utilities for walkerOS destinations
|
|
1003
|
+
*
|
|
1004
|
+
* Provides standardized tools for intercepting function calls in environment objects,
|
|
1005
|
+
* enabling consistent testing patterns across all destinations.
|
|
1006
|
+
*/
|
|
1007
|
+
type InterceptorFn = (path: string[], args: unknown[], original?: Function) => unknown;
|
|
1008
|
+
/**
|
|
1009
|
+
* Creates a proxied environment that intercepts function calls
|
|
1010
|
+
*
|
|
1011
|
+
* Uses Proxy to wrap environment objects and capture all function calls,
|
|
1012
|
+
* allowing for call recording, mocking, or simulation.
|
|
1013
|
+
*
|
|
1014
|
+
* @param env - The environment object to wrap
|
|
1015
|
+
* @param interceptor - Function called for each intercepted call
|
|
1016
|
+
* @returns Proxied environment with interceptor applied
|
|
1017
|
+
*
|
|
1018
|
+
* @example
|
|
1019
|
+
* ```typescript
|
|
1020
|
+
* const calls: Array<{ path: string[]; args: unknown[] }> = [];
|
|
1021
|
+
*
|
|
1022
|
+
* const testEnv = mockEnv(env.push, (path, args) => {
|
|
1023
|
+
* calls.push({ path, args });
|
|
1024
|
+
* });
|
|
1025
|
+
*
|
|
1026
|
+
* // Use testEnv with destination
|
|
1027
|
+
* await destination.push(event, { env: testEnv });
|
|
1028
|
+
*
|
|
1029
|
+
* // Analyze captured calls
|
|
1030
|
+
* expect(calls).toContainEqual({
|
|
1031
|
+
* path: ['window', 'gtag'],
|
|
1032
|
+
* args: ['event', 'purchase', { value: 99.99 }]
|
|
1033
|
+
* });
|
|
1034
|
+
* ```
|
|
1035
|
+
*/
|
|
1036
|
+
declare function mockEnv<T extends object>(env: T, interceptor: InterceptorFn): T;
|
|
1037
|
+
/**
|
|
1038
|
+
* Traverses environment object and replaces values using a replacer function
|
|
1039
|
+
*
|
|
1040
|
+
* Alternative to mockEnv for environments where Proxy is not suitable.
|
|
1041
|
+
* Performs deep traversal and allows value transformation at each level.
|
|
1042
|
+
*
|
|
1043
|
+
* @param env - The environment object to traverse
|
|
1044
|
+
* @param replacer - Function to transform values during traversal
|
|
1045
|
+
* @returns New environment object with transformed values
|
|
1046
|
+
*
|
|
1047
|
+
* @example
|
|
1048
|
+
* ```typescript
|
|
1049
|
+
* const recordedCalls: APICall[] = [];
|
|
1050
|
+
*
|
|
1051
|
+
* const recordingEnv = traverseEnv(originalEnv, (value, path) => {
|
|
1052
|
+
* if (typeof value === 'function') {
|
|
1053
|
+
* return (...args: unknown[]) => {
|
|
1054
|
+
* recordedCalls.push({
|
|
1055
|
+
* path: path.join('.'),
|
|
1056
|
+
* args: structuredClone(args)
|
|
1057
|
+
* });
|
|
1058
|
+
* return value(...args);
|
|
1059
|
+
* };
|
|
1060
|
+
* }
|
|
1061
|
+
* return value;
|
|
1062
|
+
* });
|
|
1063
|
+
* ```
|
|
1064
|
+
*/
|
|
1065
|
+
declare function traverseEnv<T extends object>(env: T, replacer: (value: unknown, path: string[]) => unknown): T;
|
|
1066
|
+
|
|
942
1067
|
/**
|
|
943
1068
|
* Logs a message to the console if verbose logging is enabled.
|
|
944
1069
|
*
|
|
@@ -1119,4 +1244,4 @@ declare function validateEvent(obj: unknown, customContracts?: Contracts): Event
|
|
|
1119
1244
|
*/
|
|
1120
1245
|
declare function validateProperty(obj: AnyObject, key: string, value: unknown, schema: Property$1): Property | never;
|
|
1121
1246
|
|
|
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 };
|
|
1247
|
+
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, requestToData, requestToParameter, setByPath, throttle, throwError, transformData, traverseEnv, trim, tryCatch, tryCatchAsync, useHooks, validateEvent, validateProperty };
|