@walkeros/collector 0.4.2 → 0.5.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/README.md +29 -18
- package/dist/__tests__/auto-run.test.d.ts +2 -0
- package/dist/__tests__/auto-run.test.d.ts.map +1 -0
- package/dist/__tests__/auto-run.test.js +102 -0
- package/dist/__tests__/auto-run.test.js.map +1 -0
- package/dist/__tests__/consent.test.d.ts +2 -0
- package/dist/__tests__/consent.test.d.ts.map +1 -0
- package/dist/__tests__/consent.test.js +21 -0
- package/dist/__tests__/consent.test.js.map +1 -0
- package/dist/__tests__/create-flow.test.d.ts +2 -0
- package/dist/__tests__/create-flow.test.d.ts.map +1 -0
- package/dist/__tests__/create-flow.test.js +69 -0
- package/dist/__tests__/create-flow.test.js.map +1 -0
- package/dist/__tests__/destination-code.test.d.ts +2 -0
- package/dist/__tests__/destination-code.test.d.ts.map +1 -0
- package/dist/__tests__/destination-code.test.js +323 -0
- package/dist/__tests__/destination-code.test.js.map +1 -0
- package/dist/__tests__/destination.test.d.ts +2 -0
- package/dist/__tests__/destination.test.d.ts.map +1 -0
- package/dist/__tests__/destination.test.js +320 -0
- package/dist/__tests__/destination.test.js.map +1 -0
- package/dist/__tests__/handle.test.d.ts +2 -0
- package/dist/__tests__/handle.test.d.ts.map +1 -0
- package/dist/__tests__/handle.test.js +78 -0
- package/dist/__tests__/handle.test.js.map +1 -0
- package/dist/__tests__/mapping.test.d.ts +2 -0
- package/dist/__tests__/mapping.test.d.ts.map +1 -0
- package/dist/__tests__/mapping.test.js +310 -0
- package/dist/__tests__/mapping.test.js.map +1 -0
- package/dist/__tests__/source.test.d.ts +2 -0
- package/dist/__tests__/source.test.d.ts.map +1 -0
- package/dist/__tests__/source.test.js +306 -0
- package/dist/__tests__/source.test.js.map +1 -0
- package/dist/__tests__/start-flow.test.d.ts +2 -0
- package/dist/__tests__/start-flow.test.d.ts.map +1 -0
- package/dist/__tests__/start-flow.test.js +167 -0
- package/dist/__tests__/start-flow.test.js.map +1 -0
- package/dist/__tests__/walker-entity.test.d.ts +2 -0
- package/dist/__tests__/walker-entity.test.d.ts.map +1 -0
- package/dist/__tests__/walker-entity.test.js +52 -0
- package/dist/__tests__/walker-entity.test.js.map +1 -0
- package/dist/collector.d.ts +3 -0
- package/dist/collector.d.ts.map +1 -0
- package/dist/collector.js +60 -0
- package/dist/collector.js.map +1 -0
- package/dist/command.d.ts +12 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +20 -0
- package/dist/command.js.map +1 -0
- package/dist/consent.d.ts +10 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.js +30 -0
- package/dist/consent.js.map +1 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +35 -0
- package/dist/constants.js.map +1 -0
- package/dist/destination-code.d.ts +4 -0
- package/dist/destination-code.d.ts.map +1 -0
- package/dist/destination-code.js +60 -0
- package/dist/destination-code.js.map +1 -0
- package/dist/destination.d.ts +61 -0
- package/dist/destination.d.ts.map +1 -0
- package/dist/destination.js +314 -0
- package/dist/destination.js.map +1 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/elb.d.ts +11 -0
- package/dist/elb.d.ts.map +1 -0
- package/dist/elb.js +60 -0
- package/dist/elb.js.map +1 -0
- package/dist/flow.d.ts +4 -0
- package/dist/flow.d.ts.map +1 -0
- package/dist/flow.js +44 -0
- package/dist/flow.js.map +1 -0
- package/dist/handle.d.ts +29 -0
- package/dist/handle.d.ts.map +1 -0
- package/dist/handle.js +161 -0
- package/dist/handle.js.map +1 -0
- package/dist/index.d.mts +46 -2
- package/dist/index.d.ts +46 -2
- package/dist/index.d.ts.map +1 -0
- 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/dist/on.d.ts +19 -0
- package/dist/on.d.ts.map +1 -0
- package/dist/on.js +127 -0
- package/dist/on.js.map +1 -0
- package/dist/push.d.ts +11 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +43 -0
- package/dist/push.js.map +1 -0
- package/dist/schemas.d.ts +4 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +35 -0
- package/dist/schemas.js.map +1 -0
- package/dist/source.d.ts +10 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +47 -0
- package/dist/source.js.map +1 -0
- package/dist/types/code.d.ts +22 -0
- package/dist/types/code.d.ts.map +1 -0
- package/dist/types/code.js +2 -0
- package/dist/types/code.js.map +1 -0
- package/dist/types/collector.d.ts +19 -0
- package/dist/types/collector.d.ts.map +1 -0
- package/dist/types/collector.js +2 -0
- package/dist/types/collector.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +2 -2
package/dist/handle.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Const } from './constants';
|
|
2
|
+
import { addDestination, pushToDestinations } from './destination';
|
|
3
|
+
import { assign, getId, isFunction, isString } from '@walkeros/core';
|
|
4
|
+
import { isObject } from '@walkeros/core';
|
|
5
|
+
import { setConsent } from './consent';
|
|
6
|
+
import { on, onApply } from './on';
|
|
7
|
+
/**
|
|
8
|
+
* Handles common commands.
|
|
9
|
+
*
|
|
10
|
+
* @param collector The walkerOS collector instance.
|
|
11
|
+
* @param action The action to handle.
|
|
12
|
+
* @param data The data to handle.
|
|
13
|
+
* @param options The options to handle.
|
|
14
|
+
* @returns A promise that resolves with the push result or undefined.
|
|
15
|
+
*/
|
|
16
|
+
export async function commonHandleCommand(collector, action, data, options) {
|
|
17
|
+
let result;
|
|
18
|
+
switch (action) {
|
|
19
|
+
case Const.Commands.Config:
|
|
20
|
+
if (isObject(data)) {
|
|
21
|
+
assign(collector.config, data, {
|
|
22
|
+
shallow: false,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
case Const.Commands.Consent:
|
|
27
|
+
if (isObject(data)) {
|
|
28
|
+
result = await setConsent(collector, data);
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
case Const.Commands.Custom:
|
|
32
|
+
if (isObject(data)) {
|
|
33
|
+
collector.custom = assign(collector.custom, data);
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
case Const.Commands.Destination:
|
|
37
|
+
if (isObject(data) && isFunction(data.push)) {
|
|
38
|
+
result = await addDestination(collector, { code: data }, options);
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case Const.Commands.Globals:
|
|
42
|
+
if (isObject(data)) {
|
|
43
|
+
collector.globals = assign(collector.globals, data);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case Const.Commands.On:
|
|
47
|
+
if (isString(data)) {
|
|
48
|
+
on(collector, data, options);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case Const.Commands.Ready:
|
|
52
|
+
onApply(collector, 'ready');
|
|
53
|
+
break;
|
|
54
|
+
case Const.Commands.Run:
|
|
55
|
+
result = await runCollector(collector, data);
|
|
56
|
+
break;
|
|
57
|
+
case Const.Commands.Session:
|
|
58
|
+
onApply(collector, 'session');
|
|
59
|
+
break;
|
|
60
|
+
case Const.Commands.User:
|
|
61
|
+
if (isObject(data)) {
|
|
62
|
+
assign(collector.user, data, { shallow: false });
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
return (result || {
|
|
67
|
+
ok: true,
|
|
68
|
+
successful: [],
|
|
69
|
+
queued: [],
|
|
70
|
+
failed: [],
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a full event from a partial event.
|
|
75
|
+
*
|
|
76
|
+
* @param collector The walkerOS collector instance.
|
|
77
|
+
* @param partialEvent The partial event to transform.
|
|
78
|
+
* @returns The full event.
|
|
79
|
+
*/
|
|
80
|
+
export function createEvent(collector, partialEvent) {
|
|
81
|
+
if (!partialEvent.name)
|
|
82
|
+
throw new Error('Event name is required');
|
|
83
|
+
const [entityValue, actionValue] = partialEvent.name.split(' ');
|
|
84
|
+
if (!entityValue || !actionValue)
|
|
85
|
+
throw new Error('Event name is invalid');
|
|
86
|
+
++collector.count;
|
|
87
|
+
const { timestamp = Date.now(), group = collector.group, count = collector.count, } = partialEvent;
|
|
88
|
+
const { name = `${entityValue} ${actionValue}`, data = {}, context = {}, globals = collector.globals, custom = {}, user = collector.user, nested = [], consent = collector.consent, id = `${timestamp}-${group}-${count}`, trigger = '', entity = entityValue, action = actionValue, timing = 0, version = {
|
|
89
|
+
source: collector.version,
|
|
90
|
+
tagging: collector.config.tagging || 0,
|
|
91
|
+
}, source = { type: 'collector', id: '', previous_id: '' }, } = partialEvent;
|
|
92
|
+
return {
|
|
93
|
+
name,
|
|
94
|
+
data,
|
|
95
|
+
context,
|
|
96
|
+
globals,
|
|
97
|
+
custom,
|
|
98
|
+
user,
|
|
99
|
+
nested,
|
|
100
|
+
consent,
|
|
101
|
+
id,
|
|
102
|
+
trigger,
|
|
103
|
+
entity,
|
|
104
|
+
action,
|
|
105
|
+
timestamp,
|
|
106
|
+
timing,
|
|
107
|
+
group,
|
|
108
|
+
count,
|
|
109
|
+
version,
|
|
110
|
+
source,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Runs the collector by setting it to allowed state and processing queued events.
|
|
115
|
+
*
|
|
116
|
+
* @param collector The walkerOS collector instance.
|
|
117
|
+
* @param state Optional state to merge with the collector (user, globals, consent, custom).
|
|
118
|
+
* @returns A promise that resolves with the push result.
|
|
119
|
+
*/
|
|
120
|
+
export async function runCollector(collector, state) {
|
|
121
|
+
// Set the collector to allowed state
|
|
122
|
+
collector.allowed = true;
|
|
123
|
+
// Reset count and generate new group ID
|
|
124
|
+
collector.count = 0;
|
|
125
|
+
collector.group = getId();
|
|
126
|
+
// Update timing for this run
|
|
127
|
+
collector.timing = Date.now();
|
|
128
|
+
// Update collector state if provided
|
|
129
|
+
if (state) {
|
|
130
|
+
// Update consent if provided
|
|
131
|
+
if (state.consent) {
|
|
132
|
+
collector.consent = assign(collector.consent, state.consent);
|
|
133
|
+
}
|
|
134
|
+
// Update user if provided
|
|
135
|
+
if (state.user) {
|
|
136
|
+
collector.user = assign(collector.user, state.user);
|
|
137
|
+
}
|
|
138
|
+
// Update globals if provided
|
|
139
|
+
if (state.globals) {
|
|
140
|
+
collector.globals = assign(collector.config.globalsStatic || {}, state.globals);
|
|
141
|
+
}
|
|
142
|
+
// Update custom if provided
|
|
143
|
+
if (state.custom) {
|
|
144
|
+
collector.custom = assign(collector.custom, state.custom);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Reset destination queues
|
|
148
|
+
Object.values(collector.destinations).forEach((destination) => {
|
|
149
|
+
destination.queue = [];
|
|
150
|
+
});
|
|
151
|
+
// Reset collector queue for this run
|
|
152
|
+
collector.queue = [];
|
|
153
|
+
// Increase round counter
|
|
154
|
+
collector.round++;
|
|
155
|
+
// Process any queued events now that the collector is allowed
|
|
156
|
+
const result = await pushToDestinations(collector);
|
|
157
|
+
// Call the predefined run events
|
|
158
|
+
onApply(collector, 'run');
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC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KAAK,EAAE,CAAC;IAElB,8DAA8D;IAC9D,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAEnD,iCAAiC;IACjC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAE1B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalkerOS, Collector, Elb, Destination, On, Source } from '@walkeros/core';
|
|
1
|
+
import { WalkerOS, Collector, Elb, Mapping, Destination, On, Source } from '@walkeros/core';
|
|
2
2
|
|
|
3
3
|
interface RunState {
|
|
4
4
|
consent?: WalkerOS.Consent;
|
|
@@ -18,6 +18,43 @@ interface StartFlow<ElbPush extends WalkerOS.Elb = WalkerOS.Elb> {
|
|
|
18
18
|
elb: ElbPush;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
interface Settings {
|
|
22
|
+
init?: string;
|
|
23
|
+
on?: string;
|
|
24
|
+
push?: string;
|
|
25
|
+
pushBatch?: string;
|
|
26
|
+
}
|
|
27
|
+
interface CodeMapping extends Mapping.Rule<CodeMapping> {
|
|
28
|
+
push?: string;
|
|
29
|
+
pushBatch?: string;
|
|
30
|
+
}
|
|
31
|
+
type Types = Destination.Types<Settings, CodeMapping>;
|
|
32
|
+
type Config = Destination.Config<Types>;
|
|
33
|
+
type Context = Destination.Context<Types>;
|
|
34
|
+
type InitContext = Destination.InitContext<Types>;
|
|
35
|
+
type PushContext = Destination.PushContext<Types>;
|
|
36
|
+
type PushBatchContext = Destination.PushBatchContext<Types>;
|
|
37
|
+
type InitFn = (context: InitContext) => void;
|
|
38
|
+
type OnFn = (type: On.Types, context: Context) => void;
|
|
39
|
+
type PushFn = (event: WalkerOS.Event, context: PushContext) => void;
|
|
40
|
+
type PushBatchFn = (batch: Destination.Batch<CodeMapping>, context: PushBatchContext) => void;
|
|
41
|
+
|
|
42
|
+
type code_CodeMapping = CodeMapping;
|
|
43
|
+
type code_Config = Config;
|
|
44
|
+
type code_Context = Context;
|
|
45
|
+
type code_InitContext = InitContext;
|
|
46
|
+
type code_InitFn = InitFn;
|
|
47
|
+
type code_OnFn = OnFn;
|
|
48
|
+
type code_PushBatchContext = PushBatchContext;
|
|
49
|
+
type code_PushBatchFn = PushBatchFn;
|
|
50
|
+
type code_PushContext = PushContext;
|
|
51
|
+
type code_PushFn = PushFn;
|
|
52
|
+
type code_Settings = Settings;
|
|
53
|
+
type code_Types = Types;
|
|
54
|
+
declare namespace code {
|
|
55
|
+
export type { code_CodeMapping as CodeMapping, code_Config as Config, code_Context as Context, code_InitContext as InitContext, code_InitFn as InitFn, code_OnFn as OnFn, code_PushBatchContext as PushBatchContext, code_PushBatchFn as PushBatchFn, code_PushContext as PushContext, code_PushFn as PushFn, code_Settings as Settings, code_Types as Types };
|
|
56
|
+
}
|
|
57
|
+
|
|
21
58
|
declare const Commands: Record<CommandTypes, Collector.CommandType>;
|
|
22
59
|
declare const Const: {
|
|
23
60
|
Commands: Record<CommandTypes, string>;
|
|
@@ -103,6 +140,13 @@ declare function createPushResult(partialResult?: Partial<Elb.PushResult>): Elb.
|
|
|
103
140
|
* @returns The initialized destinations.
|
|
104
141
|
*/
|
|
105
142
|
declare function initDestinations(_collector: Collector.Instance, destinations?: Destination.InitDestinations): Promise<Collector.Destinations>;
|
|
143
|
+
/**
|
|
144
|
+
* Merges destination environment with config environment
|
|
145
|
+
* Config env takes precedence over destination env for overrides
|
|
146
|
+
*/
|
|
147
|
+
declare function mergeEnvironments(destinationEnv?: Destination.Env, configEnv?: Destination.Env): Destination.Env;
|
|
148
|
+
|
|
149
|
+
declare const destinationCode: Destination.Instance;
|
|
106
150
|
|
|
107
151
|
/**
|
|
108
152
|
* Handles common commands.
|
|
@@ -158,4 +202,4 @@ declare function onApply(collector: Collector.Instance, type: On.Types, options?
|
|
|
158
202
|
*/
|
|
159
203
|
declare function initSources(collector: Collector.Instance, sources?: Source.InitSources): Promise<Collector.Sources>;
|
|
160
204
|
|
|
161
|
-
export { type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type RunState, type StartFlow, type StorageType, addDestination, commonHandleCommand, createEvent, createPush, createPushResult, destinationInit, destinationPush, initDestinations, initSources, on, onApply, pushToDestinations, runCollector, setConsent, startFlow };
|
|
205
|
+
export { code as Code, type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type RunState, type StartFlow, type StorageType, addDestination, commonHandleCommand, createEvent, createPush, createPushResult, destinationCode, destinationInit, destinationPush, initDestinations, initSources, mergeEnvironments, on, onApply, pushToDestinations, runCollector, setConsent, startFlow };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalkerOS, Collector, Elb, Destination, On, Source } from '@walkeros/core';
|
|
1
|
+
import { WalkerOS, Collector, Elb, Mapping, Destination, On, Source } from '@walkeros/core';
|
|
2
2
|
|
|
3
3
|
interface RunState {
|
|
4
4
|
consent?: WalkerOS.Consent;
|
|
@@ -18,6 +18,43 @@ interface StartFlow<ElbPush extends WalkerOS.Elb = WalkerOS.Elb> {
|
|
|
18
18
|
elb: ElbPush;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
interface Settings {
|
|
22
|
+
init?: string;
|
|
23
|
+
on?: string;
|
|
24
|
+
push?: string;
|
|
25
|
+
pushBatch?: string;
|
|
26
|
+
}
|
|
27
|
+
interface CodeMapping extends Mapping.Rule<CodeMapping> {
|
|
28
|
+
push?: string;
|
|
29
|
+
pushBatch?: string;
|
|
30
|
+
}
|
|
31
|
+
type Types = Destination.Types<Settings, CodeMapping>;
|
|
32
|
+
type Config = Destination.Config<Types>;
|
|
33
|
+
type Context = Destination.Context<Types>;
|
|
34
|
+
type InitContext = Destination.InitContext<Types>;
|
|
35
|
+
type PushContext = Destination.PushContext<Types>;
|
|
36
|
+
type PushBatchContext = Destination.PushBatchContext<Types>;
|
|
37
|
+
type InitFn = (context: InitContext) => void;
|
|
38
|
+
type OnFn = (type: On.Types, context: Context) => void;
|
|
39
|
+
type PushFn = (event: WalkerOS.Event, context: PushContext) => void;
|
|
40
|
+
type PushBatchFn = (batch: Destination.Batch<CodeMapping>, context: PushBatchContext) => void;
|
|
41
|
+
|
|
42
|
+
type code_CodeMapping = CodeMapping;
|
|
43
|
+
type code_Config = Config;
|
|
44
|
+
type code_Context = Context;
|
|
45
|
+
type code_InitContext = InitContext;
|
|
46
|
+
type code_InitFn = InitFn;
|
|
47
|
+
type code_OnFn = OnFn;
|
|
48
|
+
type code_PushBatchContext = PushBatchContext;
|
|
49
|
+
type code_PushBatchFn = PushBatchFn;
|
|
50
|
+
type code_PushContext = PushContext;
|
|
51
|
+
type code_PushFn = PushFn;
|
|
52
|
+
type code_Settings = Settings;
|
|
53
|
+
type code_Types = Types;
|
|
54
|
+
declare namespace code {
|
|
55
|
+
export type { code_CodeMapping as CodeMapping, code_Config as Config, code_Context as Context, code_InitContext as InitContext, code_InitFn as InitFn, code_OnFn as OnFn, code_PushBatchContext as PushBatchContext, code_PushBatchFn as PushBatchFn, code_PushContext as PushContext, code_PushFn as PushFn, code_Settings as Settings, code_Types as Types };
|
|
56
|
+
}
|
|
57
|
+
|
|
21
58
|
declare const Commands: Record<CommandTypes, Collector.CommandType>;
|
|
22
59
|
declare const Const: {
|
|
23
60
|
Commands: Record<CommandTypes, string>;
|
|
@@ -103,6 +140,13 @@ declare function createPushResult(partialResult?: Partial<Elb.PushResult>): Elb.
|
|
|
103
140
|
* @returns The initialized destinations.
|
|
104
141
|
*/
|
|
105
142
|
declare function initDestinations(_collector: Collector.Instance, destinations?: Destination.InitDestinations): Promise<Collector.Destinations>;
|
|
143
|
+
/**
|
|
144
|
+
* Merges destination environment with config environment
|
|
145
|
+
* Config env takes precedence over destination env for overrides
|
|
146
|
+
*/
|
|
147
|
+
declare function mergeEnvironments(destinationEnv?: Destination.Env, configEnv?: Destination.Env): Destination.Env;
|
|
148
|
+
|
|
149
|
+
declare const destinationCode: Destination.Instance;
|
|
106
150
|
|
|
107
151
|
/**
|
|
108
152
|
* Handles common commands.
|
|
@@ -158,4 +202,4 @@ declare function onApply(collector: Collector.Instance, type: On.Types, options?
|
|
|
158
202
|
*/
|
|
159
203
|
declare function initSources(collector: Collector.Instance, sources?: Source.InitSources): Promise<Collector.Sources>;
|
|
160
204
|
|
|
161
|
-
export { type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type RunState, type StartFlow, type StorageType, addDestination, commonHandleCommand, createEvent, createPush, createPushResult, destinationInit, destinationPush, initDestinations, initSources, on, onApply, pushToDestinations, runCollector, setConsent, startFlow };
|
|
205
|
+
export { code as Code, type CommandTypes, Commands, Const, type CreateCollector, type HandleCommandFn, type RunState, type StartFlow, type StorageType, addDestination, commonHandleCommand, createEvent, createPush, createPushResult, destinationCode, destinationInit, destinationPush, initDestinations, initSources, mergeEnvironments, on, onApply, pushToDestinations, runCollector, setConsent, startFlow };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AAExB,cAAc,aAAa,CAAC;AAE5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,n=Object.defineProperty,o=Object.getOwnPropertyDescriptor,t=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,a={};((e,o)=>{for(var t in o)n(e,t,{get:o[t],enumerable:!0})})(a,{Commands:()=>i,Const:()=>c,addDestination:()=>l,commonHandleCommand:()=>O,createEvent:()=>E,createPush:()=>P,createPushResult:()=>m,destinationInit:()=>d,destinationPush:()=>f,initDestinations:()=>p,initSources:()=>H,on:()=>k,onApply:()=>w,pushToDestinations:()=>g,runCollector:()=>A,setConsent:()=>v,startFlow:()=>F}),module.exports=(e=a,((e,a,i,c)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of t(a))s.call(e,r)||r===i||n(e,r,{get:()=>a[r],enumerable:!(c=o(a,r))||c.enumerable});return e})(n({},"__esModule",{value:!0}),e));var i={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},c={Commands:i,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},r=require("@walkeros/core"),u=require("@walkeros/core");async function l(e,n,o){const{code:t,config:s={},env:a={}}=n,i=o||s||{init:!1},c={...t,config:i,env:h(t.env,a)};let r=c.config.id;if(!r)do{r=(0,u.getId)(4)}while(e.destinations[r]);return e.destinations[r]=c,!1!==c.config.queue&&(c.queue=[...e.queue]),g(e,void 0,{[r]:c})}async function g(e,n,o){const{allowed:t,consent:s,globals:a,user:i}=e;if(!t)return m({ok:!1});n&&e.queue.push(n),o||(o=e.destinations);const c=await Promise.all(Object.entries(o||{}).map(async([o,t])=>{let c=(t.queue||[]).map(e=>({...e,consent:s}));if(t.queue=[],n){const e=(0,u.clone)(n);c.push(e)}if(!c.length)return{id:o,destination:t,skipped:!0};const r=[],l=c.filter(e=>{const n=(0,u.getGrantedConsent)(t.config.consent,s,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(t.queue.concat(l),!r.length)return{id:o,destination:t,queue:c};if(!await(0,u.tryCatchAsync)(d)(e,t))return{id:o,destination:t,queue:c};let g=!1;return t.dlq||(t.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,u.assign)(a,n.globals),n.user=(0,u.assign)(i,n.user),await(0,u.tryCatchAsync)(f,o=>{const s=t.type||"unknown";return e.logger.scope(s).error("Push failed",{error:o,event:n.name}),g=!0,t.dlq.push([n,o]),!1})(e,t,n),n))),{id:o,destination:t,error:g}})),r=[],l=[],g=[];for(const e of c){if(e.skipped)continue;const n=e.destination,o={id:e.id,destination:n};e.error?g.push(o):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),l.push(o)):r.push(o)}return m({ok:!g.length,event:n,successful:r,queued:l,failed:g})}async function d(e,n){if(n.init&&!n.config.init){const o=n.type||"unknown",t=e.logger.scope(o),s={collector:e,config:n.config,env:h(n.env,n.config.env),logger:t},a=await(0,u.useHooks)(n.init,"DestinationInit",e.hooks)(s);if(!1===a)return a;n.config={...a||n.config,init:!0}}return!0}async function f(e,n,o){const{config:t}=n,s=await(0,u.processEventMapping)(o,t,e);if(s.ignore)return!1;const a=n.type||"unknown",i=e.logger.scope(a),c={collector:e,config:t,data:s.data,mapping:s.mapping,env:h(n.env,t.env),logger:i},r=s.mapping;if(r?.batch&&n.pushBatch){const o=r.batched||{key:s.mappingKey||"",events:[],data:[]};o.events.push(s.event),(0,u.isDefined)(s.data)&&o.data.push(s.data),r.batchFn=r.batchFn||(0,u.debounce)((e,n)=>{const a=e.type||"unknown",i=n.logger.scope(a),c={collector:n,config:t,data:s.data,mapping:r,env:h(e.env,t.env),logger:i};(0,u.useHooks)(e.pushBatch,"DestinationPushBatch",n.hooks)(o,c),o.events=[],o.data=[]},r.batch),r.batched=o,r.batchFn?.(n,e)}else await(0,u.useHooks)(n.push,"DestinationPush",e.hooks)(s.event,c);return!0}function m(e){return(0,u.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function p(e,n={}){const o={};for(const[e,t]of Object.entries(n)){const{code:n,config:s={},env:a={}}=t,i={...n.config,...s},c=h(n.env,a);o[e]={...n,config:i,env:c}}return o}function h(e,n){return e||n?n?e&&(0,u.isObject)(e)&&(0,u.isObject)(n)?{...e,...n}:n:e:{}}var b=require("@walkeros/core"),y=require("@walkeros/core");function k(e,n,o){const t=e.on,s=t[n]||[],a=(0,b.isArray)(o)?o:[o];a.forEach(e=>{s.push(e)}),t[n]=s,w(e,n,a)}function w(e,n,o,t){let s,a=o||[];switch(o||(a=e.on[n]||[]),n){case c.Commands.Consent:s=t||e.consent;break;case c.Commands.Session:s=e.session;break;case c.Commands.Ready:case c.Commands.Run:default:s=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,y.tryCatch)(e.on)(n,s)}),Object.values(e.destinations).forEach(e=>{if(e.on){const o=e.on;(0,y.tryCatch)(o)(n,s)}}),a.length)switch(n){case c.Commands.Consent:!function(e,n,o){const t=o||e.consent;n.forEach(n=>{Object.keys(t).filter(e=>e in n).forEach(o=>{(0,y.tryCatch)(n[o])(e,t)})})}(e,a,t);break;case c.Commands.Ready:case c.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,y.tryCatch)(n)(e)})}(e,a);break;case c.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,y.tryCatch)(n)(e,e.session)})}(e,a)}}async function v(e,n){const{consent:o}=e;let t=!1;const s={};return Object.entries(n).forEach(([e,n])=>{const o=!!n;s[e]=o,t=t||o}),e.consent=(0,r.assign)(o,s),w(e,"consent",void 0,s),t?g(e):m({ok:!0})}var C=require("@walkeros/core"),q=require("@walkeros/core"),j=require("@walkeros/core");async function O(e,n,o,t){let s;switch(n){case c.Commands.Config:(0,j.isObject)(o)&&(0,q.assign)(e.config,o,{shallow:!1});break;case c.Commands.Consent:(0,j.isObject)(o)&&(s=await v(e,o));break;case c.Commands.Custom:(0,j.isObject)(o)&&(e.custom=(0,q.assign)(e.custom,o));break;case c.Commands.Destination:(0,j.isObject)(o)&&(0,q.isFunction)(o.push)&&(s=await l(e,{code:o},t));break;case c.Commands.Globals:(0,j.isObject)(o)&&(e.globals=(0,q.assign)(e.globals,o));break;case c.Commands.On:(0,q.isString)(o)&&k(e,o,t);break;case c.Commands.Ready:w(e,"ready");break;case c.Commands.Run:s=await A(e,o);break;case c.Commands.Session:w(e,"session");break;case c.Commands.User:(0,j.isObject)(o)&&(0,q.assign)(e.user,o,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function E(e,n){if(!n.name)throw new Error("Event name is required");const[o,t]=n.name.split(" ");if(!o||!t)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:i=e.count}=n,{name:c=`${o} ${t}`,data:r={},context:u={},globals:l=e.globals,custom:g={},user:d=e.user,nested:f=[],consent:m=e.consent,id:p=`${s}-${a}-${i}`,trigger:h="",entity:b=o,action:y=t,timing:k=0,version:w={source:e.version,tagging:e.config.tagging||0},source:v={type:"collector",id:"",previous_id:""}}=n;return{name:c,data:r,context:u,globals:l,custom:g,user:d,nested:f,consent:m,id:p,trigger:h,entity:b,action:y,timestamp:s,timing:k,group:a,count:i,version:w,source:v}}async function A(e,n){e.allowed=!0,e.count=0,e.group=(0,q.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,q.assign)(e.consent,n.consent)),n.user&&(e.user=(0,q.assign)(e.user,n.user)),n.globals&&(e.globals=(0,q.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,q.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const o=await g(e);return w(e,"run"),o}var D=require("@walkeros/core");function P(e,n){return(0,D.useHooks)(async(o,t={})=>await(0,D.tryCatchAsync)(async()=>{let s=o;if(t.mapping){const n=await(0,D.processEventMapping)(s,t.mapping,e);if(n.ignore)return m({ok:!0});if(t.mapping.consent){if(!(0,D.getGrantedConsent)(t.mapping.consent,e.consent,n.event.consent))return m({ok:!0})}s=n.event}const a=n(s),i=E(e,a);return await g(e,i)},()=>m({ok:!1}))(),"Push",e.hooks)}var S=require("@walkeros/core");async function R(e){const n=(0,C.assign)({globalsStatic:{},sessionStatic:{},tagging:0,run:!0},e,{merge:!1,extend:!1}),o={level:e.logger?.level,handler:e.logger?.handler},t=(0,C.createLogger)(o),s={...n.globalsStatic,...e.globals},a={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},logger:t,on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.4.2",sources:{},push:void 0,command:void 0};return a.push=P(a,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.command=function(e,n){return(0,S.useHooks)(async(o,t,s)=>await(0,S.tryCatchAsync)(async()=>await n(e,o,t,s),()=>m({ok:!1}))(),"Command",e.hooks)}(a,O),a.destinations=await p(0,e.destinations||{}),a}var x=require("@walkeros/core");async function H(e,n={}){const o={};for(const[t,s]of Object.entries(n)){const{code:n,config:a={},env:i={},primary:c}=s,r=(n,o={})=>e.push(n,{...o,mapping:a}),u=e.logger.scope("source").scope(t),l={push:r,command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:u,...i},g=await(0,x.tryCatchAsync)(n)(a,l);if(!g)continue;const d=g.type||"unknown",f=e.logger.scope(d).scope(t);l.logger=f,c&&(g.config={...g.config,primary:c}),o[t]=g}return o}async function F(e){e=e||{};const n=await R(e),o=(t=n,{type:"elb",config:{},push:async(e,n,o,s,a,i)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return t.command(s,n,o)}let c;if("string"==typeof e)c={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(c.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};c=e,n&&"object"==typeof n&&!Array.isArray(n)&&(c.data={...c.data||{},...n})}return s&&"object"==typeof s&&(c.context=s),a&&Array.isArray(a)&&(c.nested=a),i&&"object"==typeof i&&(c.custom=i),t.push(c)}});var t;n.sources.elb=o;const s=await H(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:i,globals:c,custom:r}=e;a&&await n.command("consent",a),i&&await n.command("user",i),c&&Object.assign(n.globals,c),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=o.push;const l=Object.values(n.sources).filter(e=>"elb"!==e.type),g=l.find(e=>e.config.primary);return g?u=g.push:l.length>0&&(u=l[0].push),{collector:n,elb:u}}//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";var e,n=Object.defineProperty,o=Object.getOwnPropertyDescriptor,t=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,a={};((e,o)=>{for(var t in o)n(e,t,{get:o[t],enumerable:!0})})(a,{Code:()=>i,Commands:()=>c,Const:()=>r,addDestination:()=>f,commonHandleCommand:()=>D,createEvent:()=>P,createPush:()=>F,createPushResult:()=>b,destinationCode:()=>l,destinationInit:()=>m,destinationPush:()=>h,initDestinations:()=>y,initSources:()=>I,mergeEnvironments:()=>v,on:()=>C,onApply:()=>q,pushToDestinations:()=>p,runCollector:()=>x,setConsent:()=>j,startFlow:()=>$}),module.exports=(e=a,((e,a,i,c)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let r of t(a))s.call(e,r)||r===i||n(e,r,{get:()=>a[r],enumerable:!(c=o(a,r))||c.enumerable});return e})(n({},"__esModule",{value:!0}),e));var i={},c={Action:"action",Actions:"actions",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},r={Commands:c,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},u=require("@walkeros/core"),g=require("@walkeros/core"),l={type:"code",config:{},init(e){const{config:n,logger:o}=e,t=n.settings?.init;if(t)try{new Function("context",t)(e)}catch(e){o.error("Code destination init error:",e)}},push(e,n){const{mapping:o,config:t,logger:s}=n,a=o?.push??t.settings?.push;if(a)try{new Function("event","context",a)(e,n)}catch(e){s.error("Code destination push error:",e)}},pushBatch(e,n){const{mapping:o,config:t,logger:s}=n,a=o?.pushBatch??t.settings?.pushBatch;if(a)try{new Function("batch","context",a)(e,n)}catch(e){s.error("Code destination pushBatch error:",e)}},on(e,n){const{config:o,logger:t}=n,s=o.settings?.on;if(s)try{new Function("type","context",s)(e,n)}catch(e){t.error("Code destination on error:",e)}}};function d(e){return!0===e?l:e}async function f(e,n,o){const{code:t,config:s={},env:a={}}=n,i=o||s||{init:!1},c=d(t),r={...c,config:i,env:v(c.env,a)};let u=r.config.id;if(!u)do{u=(0,g.getId)(4)}while(e.destinations[u]);return e.destinations[u]=r,!1!==r.config.queue&&(r.queue=[...e.queue]),p(e,void 0,{[u]:r})}async function p(e,n,o){const{allowed:t,consent:s,globals:a,user:i}=e;if(!t)return b({ok:!1});n&&e.queue.push(n),o||(o=e.destinations);const c=await Promise.all(Object.entries(o||{}).map(async([o,t])=>{let c=(t.queue||[]).map(e=>({...e,consent:s}));if(t.queue=[],n){const e=(0,g.clone)(n);c.push(e)}if(!c.length)return{id:o,destination:t,skipped:!0};const r=[],u=c.filter(e=>{const n=(0,g.getGrantedConsent)(t.config.consent,s,e.consent);return!n||(e.consent=n,r.push(e),!1)});if(t.queue.concat(u),!r.length)return{id:o,destination:t,queue:c};if(!await(0,g.tryCatchAsync)(m)(e,t))return{id:o,destination:t,queue:c};let l=!1;return t.dlq||(t.dlq=[]),await Promise.all(r.map(async n=>(n.globals=(0,g.assign)(a,n.globals),n.user=(0,g.assign)(i,n.user),await(0,g.tryCatchAsync)(h,o=>{const s=t.type||"unknown";return e.logger.scope(s).error("Push failed",{error:o,event:n.name}),l=!0,t.dlq.push([n,o]),!1})(e,t,n),n))),{id:o,destination:t,error:l}})),r=[],u=[],l=[];for(const e of c){if(e.skipped)continue;const n=e.destination,o={id:e.id,destination:n};e.error?l.push(o):e.queue&&e.queue.length?(n.queue=(n.queue||[]).concat(e.queue),u.push(o)):r.push(o)}return b({ok:!l.length,event:n,successful:r,queued:u,failed:l})}async function m(e,n){if(n.init&&!n.config.init){const o=n.type||"unknown",t=e.logger.scope(o),s={collector:e,config:n.config,env:v(n.env,n.config.env),logger:t};t.debug("init");const a=await(0,g.useHooks)(n.init,"DestinationInit",e.hooks)(s);if(!1===a)return a;n.config={...a||n.config,init:!0},t.debug("init done")}return!0}async function h(e,n,o){const{config:t}=n,s=await(0,g.processEventMapping)(o,t,e);if(s.ignore)return!1;const a=n.type||"unknown",i=e.logger.scope(a),c={collector:e,config:t,data:s.data,mapping:s.mapping,env:v(n.env,t.env),logger:i},r=s.mapping;if(r?.batch&&n.pushBatch){const o=r.batched||{key:s.mappingKey||"",events:[],data:[]};o.events.push(s.event),(0,g.isDefined)(s.data)&&o.data.push(s.data),r.batchFn=r.batchFn||(0,g.debounce)((e,n)=>{const a=e.type||"unknown",i=n.logger.scope(a),c={collector:n,config:t,data:s.data,mapping:r,env:v(e.env,t.env),logger:i};i.debug("push batch",{events:o.events.length}),(0,g.useHooks)(e.pushBatch,"DestinationPushBatch",n.hooks)(o,c),i.debug("push batch done"),o.events=[],o.data=[]},r.batch),r.batched=o,r.batchFn?.(n,e)}else i.debug("push",{event:s.event.name}),await(0,g.useHooks)(n.push,"DestinationPush",e.hooks)(s.event,c),i.debug("push done");return!0}function b(e){return(0,g.assign)({ok:!e?.failed?.length,successful:[],queued:[],failed:[]},e)}async function y(e,n={}){const o={};for(const[e,t]of Object.entries(n)){const{code:n,config:s={},env:a={}}=t,i=d(n),c={...i.config,...s},r=v(i.env,a);o[e]={...i,config:c,env:r}}return o}function v(e,n){return e||n?n?e&&(0,g.isObject)(e)&&(0,g.isObject)(n)?{...e,...n}:n:e:{}}var w=require("@walkeros/core"),k=require("@walkeros/core");function C(e,n,o){const t=e.on,s=t[n]||[],a=(0,w.isArray)(o)?o:[o];a.forEach(e=>{s.push(e)}),t[n]=s,q(e,n,a)}function q(e,n,o,t){let s,a=o||[];switch(o||(a=e.on[n]||[]),n){case r.Commands.Consent:s=t||e.consent;break;case r.Commands.Session:s=e.session;break;case r.Commands.Ready:case r.Commands.Run:default:s=void 0}if(Object.values(e.sources).forEach(e=>{e.on&&(0,k.tryCatch)(e.on)(n,s)}),Object.values(e.destinations).forEach(o=>{if(o.on){const t=o.type||"unknown",a=e.logger.scope(t).scope("on").scope(n),i={collector:e,config:o.config,data:s,env:v(o.env,o.config.env),logger:a};(0,k.tryCatch)(o.on)(n,i)}}),a.length)switch(n){case r.Commands.Consent:!function(e,n,o){const t=o||e.consent;n.forEach(n=>{Object.keys(t).filter(e=>e in n).forEach(o=>{(0,k.tryCatch)(n[o])(e,t)})})}(e,a,t);break;case r.Commands.Ready:case r.Commands.Run:!function(e,n){e.allowed&&n.forEach(n=>{(0,k.tryCatch)(n)(e)})}(e,a);break;case r.Commands.Session:!function(e,n){if(!e.session)return;n.forEach(n=>{(0,k.tryCatch)(n)(e,e.session)})}(e,a)}}async function j(e,n){const{consent:o}=e;let t=!1;const s={};return Object.entries(n).forEach(([e,n])=>{const o=!!n;s[e]=o,t=t||o}),e.consent=(0,u.assign)(o,s),q(e,"consent",void 0,s),t?p(e):b({ok:!0})}var O=require("@walkeros/core"),E=require("@walkeros/core"),A=require("@walkeros/core");async function D(e,n,o,t){let s;switch(n){case r.Commands.Config:(0,A.isObject)(o)&&(0,E.assign)(e.config,o,{shallow:!1});break;case r.Commands.Consent:(0,A.isObject)(o)&&(s=await j(e,o));break;case r.Commands.Custom:(0,A.isObject)(o)&&(e.custom=(0,E.assign)(e.custom,o));break;case r.Commands.Destination:(0,A.isObject)(o)&&(0,E.isFunction)(o.push)&&(s=await f(e,{code:o},t));break;case r.Commands.Globals:(0,A.isObject)(o)&&(e.globals=(0,E.assign)(e.globals,o));break;case r.Commands.On:(0,E.isString)(o)&&C(e,o,t);break;case r.Commands.Ready:q(e,"ready");break;case r.Commands.Run:s=await x(e,o);break;case r.Commands.Session:q(e,"session");break;case r.Commands.User:(0,A.isObject)(o)&&(0,E.assign)(e.user,o,{shallow:!1})}return s||{ok:!0,successful:[],queued:[],failed:[]}}function P(e,n){if(!n.name)throw new Error("Event name is required");const[o,t]=n.name.split(" ");if(!o||!t)throw new Error("Event name is invalid");++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:i=e.count}=n,{name:c=`${o} ${t}`,data:r={},context:u={},globals:g=e.globals,custom:l={},user:d=e.user,nested:f=[],consent:p=e.consent,id:m=`${s}-${a}-${i}`,trigger:h="",entity:b=o,action:y=t,timing:v=0,version:w={source:e.version,tagging:e.config.tagging||0},source:k={type:"collector",id:"",previous_id:""}}=n;return{name:c,data:r,context:u,globals:g,custom:l,user:d,nested:f,consent:p,id:m,trigger:h,entity:b,action:y,timestamp:s,timing:v,group:a,count:i,version:w,source:k}}async function x(e,n){e.allowed=!0,e.count=0,e.group=(0,E.getId)(),e.timing=Date.now(),n&&(n.consent&&(e.consent=(0,E.assign)(e.consent,n.consent)),n.user&&(e.user=(0,E.assign)(e.user,n.user)),n.globals&&(e.globals=(0,E.assign)(e.config.globalsStatic||{},n.globals)),n.custom&&(e.custom=(0,E.assign)(e.custom,n.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.queue=[],e.round++;const o=await p(e);return q(e,"run"),o}var S=require("@walkeros/core");function F(e,n){return(0,S.useHooks)(async(o,t={})=>await(0,S.tryCatchAsync)(async()=>{let s=o;if(t.mapping){const n=await(0,S.processEventMapping)(s,t.mapping,e);if(n.ignore)return b({ok:!0});if(t.mapping.consent){if(!(0,S.getGrantedConsent)(t.mapping.consent,e.consent,n.event.consent))return b({ok:!0})}s=n.event}const a=n(s),i=P(e,a);return await p(e,i)},()=>b({ok:!1}))(),"Push",e.hooks)}var R=require("@walkeros/core");async function B(e){const n=(0,O.assign)({globalsStatic:{},sessionStatic:{},tagging:0,run:!0},e,{merge:!1,extend:!1}),o={level:e.logger?.level,handler:e.logger?.handler},t=(0,O.createLogger)(o),s={...n.globalsStatic,...e.globals},a={allowed:!1,config:n,consent:e.consent||{},count:0,custom:e.custom||{},destinations:{},globals:s,group:"",hooks:{},logger:t,on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:e.user||{},version:"0.5.0",sources:{},push:void 0,command:void 0};return a.push=F(a,e=>({timing:Math.round((Date.now()-a.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),a.command=function(e,n){return(0,R.useHooks)(async(o,t,s)=>await(0,R.tryCatchAsync)(async()=>await n(e,o,t,s),()=>b({ok:!1}))(),"Command",e.hooks)}(a,D),a.destinations=await y(0,e.destinations||{}),a}var H=require("@walkeros/core");async function I(e,n={}){const o={};for(const[t,s]of Object.entries(n)){const{code:n,config:a={},env:i={},primary:c}=s,r=(n,o={})=>e.push(n,{...o,mapping:a}),u=e.logger.scope("source").scope(t),g={push:r,command:e.command,sources:e.sources,elb:e.sources.elb.push,logger:u,...i},l=await(0,H.tryCatchAsync)(n)(a,g);if(!l)continue;const d=l.type||"unknown",f=e.logger.scope(d).scope(t);g.logger=f,c&&(l.config={...l.config,primary:c}),o[t]=l}return o}async function $(e){e=e||{};const n=await B(e),o=(t=n,{type:"elb",config:{},push:async(e,n,o,s,a,i)=>{if("string"==typeof e&&e.startsWith("walker ")){const s=e.replace("walker ","");return t.command(s,n,o)}let c;if("string"==typeof e)c={name:e},n&&"object"==typeof n&&!Array.isArray(n)&&(c.data=n);else{if(!e||"object"!=typeof e)return{ok:!1,successful:[],queued:[],failed:[]};c=e,n&&"object"==typeof n&&!Array.isArray(n)&&(c.data={...c.data||{},...n})}return s&&"object"==typeof s&&(c.context=s),a&&Array.isArray(a)&&(c.nested=a),i&&"object"==typeof i&&(c.custom=i),t.push(c)}});var t;n.sources.elb=o;const s=await I(n,e.sources||{});Object.assign(n.sources,s);const{consent:a,user:i,globals:c,custom:r}=e;a&&await n.command("consent",a),i&&await n.command("user",i),c&&Object.assign(n.globals,c),r&&Object.assign(n.custom,r),n.config.run&&await n.command("run");let u=o.push;const g=Object.values(n.sources).filter(e=>"elb"!==e.type),l=g.find(e=>e.config.primary);return l?u=l.push:g.length>0&&(u=g[0].push),{collector:n,elb:u}}//# sourceMappingURL=index.js.map
|