@walkeros/collector 0.4.0 → 0.4.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.
Files changed (97) hide show
  1. package/dist/__tests__/auto-run.test.d.ts +2 -0
  2. package/dist/__tests__/auto-run.test.d.ts.map +1 -0
  3. package/dist/__tests__/auto-run.test.js +105 -0
  4. package/dist/__tests__/auto-run.test.js.map +1 -0
  5. package/dist/__tests__/consent.test.d.ts +2 -0
  6. package/dist/__tests__/consent.test.d.ts.map +1 -0
  7. package/dist/__tests__/consent.test.js +21 -0
  8. package/dist/__tests__/consent.test.js.map +1 -0
  9. package/dist/__tests__/create-flow.test.d.ts +2 -0
  10. package/dist/__tests__/create-flow.test.d.ts.map +1 -0
  11. package/dist/__tests__/create-flow.test.js +69 -0
  12. package/dist/__tests__/create-flow.test.js.map +1 -0
  13. package/dist/__tests__/destination.test.d.ts +2 -0
  14. package/dist/__tests__/destination.test.d.ts.map +1 -0
  15. package/dist/__tests__/destination.test.js +242 -0
  16. package/dist/__tests__/destination.test.js.map +1 -0
  17. package/dist/__tests__/handle.test.d.ts +2 -0
  18. package/dist/__tests__/handle.test.d.ts.map +1 -0
  19. package/dist/__tests__/handle.test.js +78 -0
  20. package/dist/__tests__/handle.test.js.map +1 -0
  21. package/dist/__tests__/mapping.test.d.ts +2 -0
  22. package/dist/__tests__/mapping.test.d.ts.map +1 -0
  23. package/dist/__tests__/mapping.test.js +310 -0
  24. package/dist/__tests__/mapping.test.js.map +1 -0
  25. package/dist/__tests__/source.test.d.ts +2 -0
  26. package/dist/__tests__/source.test.d.ts.map +1 -0
  27. package/dist/__tests__/source.test.js +306 -0
  28. package/dist/__tests__/source.test.js.map +1 -0
  29. package/dist/__tests__/start-flow.test.d.ts +2 -0
  30. package/dist/__tests__/start-flow.test.d.ts.map +1 -0
  31. package/dist/__tests__/start-flow.test.js +167 -0
  32. package/dist/__tests__/start-flow.test.js.map +1 -0
  33. package/dist/__tests__/walker-entity.test.d.ts +2 -0
  34. package/dist/__tests__/walker-entity.test.d.ts.map +1 -0
  35. package/dist/__tests__/walker-entity.test.js +52 -0
  36. package/dist/__tests__/walker-entity.test.js.map +1 -0
  37. package/dist/collector.d.ts +3 -0
  38. package/dist/collector.d.ts.map +1 -0
  39. package/dist/collector.js +59 -0
  40. package/dist/collector.js.map +1 -0
  41. package/dist/command.d.ts +12 -0
  42. package/dist/command.d.ts.map +1 -0
  43. package/dist/command.js +20 -0
  44. package/dist/command.js.map +1 -0
  45. package/dist/consent.d.ts +10 -0
  46. package/dist/consent.d.ts.map +1 -0
  47. package/dist/consent.js +30 -0
  48. package/dist/consent.js.map +1 -0
  49. package/dist/constants.d.ts +13 -0
  50. package/dist/constants.d.ts.map +1 -0
  51. package/dist/constants.js +35 -0
  52. package/dist/constants.js.map +1 -0
  53. package/dist/destination.d.ts +56 -0
  54. package/dist/destination.d.ts.map +1 -0
  55. package/dist/destination.js +289 -0
  56. package/dist/destination.js.map +1 -0
  57. package/dist/dev.d.ts.map +1 -0
  58. package/dist/elb.d.ts +11 -0
  59. package/dist/elb.d.ts.map +1 -0
  60. package/dist/elb.js +60 -0
  61. package/dist/elb.js.map +1 -0
  62. package/dist/flow.d.ts +4 -0
  63. package/dist/flow.d.ts.map +1 -0
  64. package/dist/flow.js +44 -0
  65. package/dist/flow.js.map +1 -0
  66. package/dist/handle.d.ts +29 -0
  67. package/dist/handle.d.ts.map +1 -0
  68. package/dist/handle.js +161 -0
  69. package/dist/handle.js.map +1 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +1 -1
  72. package/dist/index.mjs +1 -1
  73. package/dist/on.d.ts +19 -0
  74. package/dist/on.d.ts.map +1 -0
  75. package/dist/on.js +116 -0
  76. package/dist/on.js.map +1 -0
  77. package/dist/push.d.ts +11 -0
  78. package/dist/push.d.ts.map +1 -0
  79. package/dist/push.js +43 -0
  80. package/dist/push.js.map +1 -0
  81. package/dist/schemas.d.ts +6 -0
  82. package/dist/schemas.d.ts.map +1 -0
  83. package/dist/schemas.js +37 -0
  84. package/dist/schemas.js.map +1 -0
  85. package/dist/source.d.ts +10 -0
  86. package/dist/source.d.ts.map +1 -0
  87. package/dist/source.js +40 -0
  88. package/dist/source.js.map +1 -0
  89. package/dist/types/collector.d.ts +19 -0
  90. package/dist/types/collector.d.ts.map +1 -0
  91. package/dist/types/collector.js +2 -0
  92. package/dist/types/collector.js.map +1 -0
  93. package/dist/types/index.d.ts +2 -0
  94. package/dist/types/index.d.ts.map +1 -0
  95. package/dist/types/index.js +2 -0
  96. package/dist/types/index.js.map +1 -0
  97. package/package.json +2 -2
@@ -0,0 +1,289 @@
1
+ import { assign, clone, debounce, getId, getGrantedConsent, isDefined, isObject, processEventMapping, tryCatchAsync, useHooks, } from '@walkeros/core';
2
+ /**
3
+ * Adds a new destination to the collector.
4
+ *
5
+ * @param collector - The walkerOS collector instance.
6
+ * @param data - The destination's init data.
7
+ * @param options - The destination's config.
8
+ * @returns The result of the push operation.
9
+ */
10
+ export async function addDestination(collector, data, options) {
11
+ const { code, config: dataConfig = {}, env = {} } = data;
12
+ const config = options || dataConfig || { init: false };
13
+ const destination = {
14
+ ...code,
15
+ config,
16
+ env: mergeEnvironments(code.env, env),
17
+ };
18
+ let id = destination.config.id; // Use given id
19
+ if (!id) {
20
+ // Generate a new id if none was given
21
+ do {
22
+ id = getId(4);
23
+ } while (collector.destinations[id]);
24
+ }
25
+ // Add the destination
26
+ collector.destinations[id] = destination;
27
+ // Process previous events if not disabled
28
+ if (destination.config.queue !== false)
29
+ destination.queue = [...collector.queue];
30
+ return pushToDestinations(collector, undefined, { [id]: destination });
31
+ }
32
+ /**
33
+ * Pushes an event to all or a subset of destinations.
34
+ *
35
+ * @param collector - The walkerOS collector instance.
36
+ * @param event - The event to push.
37
+ * @param destinations - The destinations to push to.
38
+ * @returns The result of the push operation.
39
+ */
40
+ export async function pushToDestinations(collector, event, destinations) {
41
+ const { allowed, consent, globals, user } = collector;
42
+ // Check if collector is allowed to push
43
+ if (!allowed)
44
+ return createPushResult({ ok: false });
45
+ // Add event to the collector queue
46
+ if (event)
47
+ collector.queue.push(event);
48
+ // Use given destinations or use internal destinations
49
+ if (!destinations)
50
+ destinations = collector.destinations;
51
+ const results = await Promise.all(
52
+ // Process all destinations in parallel
53
+ Object.entries(destinations || {}).map(async ([id, destination]) => {
54
+ // Create a queue of events to be processed
55
+ let currentQueue = (destination.queue || []).map((event) => ({
56
+ ...event,
57
+ consent,
58
+ }));
59
+ // Reset original queue while processing to enable async processing
60
+ destination.queue = [];
61
+ // Add event to queue stack
62
+ if (event) {
63
+ // Clone the event to avoid mutating the original event
64
+ const currentEvent = clone(event);
65
+ // Note: Policy is now applied in processEventMapping() within destinationPush()
66
+ // Add event to queue stack
67
+ currentQueue.push(currentEvent);
68
+ }
69
+ // Nothing to do here if the queue is empty
70
+ if (!currentQueue.length)
71
+ return { id, destination, skipped: true };
72
+ const allowedEvents = [];
73
+ const skippedEvents = currentQueue.filter((queuedEvent) => {
74
+ const grantedConsent = getGrantedConsent(destination.config.consent, // Required
75
+ consent, // Current collector state
76
+ queuedEvent.consent);
77
+ if (grantedConsent) {
78
+ queuedEvent.consent = grantedConsent; // Save granted consent states only
79
+ allowedEvents.push(queuedEvent); // Add to allowed queue
80
+ return false; // Remove from destination queue
81
+ }
82
+ return true; // Keep denied events in the queue
83
+ });
84
+ // Add skipped events back to the queue
85
+ destination.queue.concat(skippedEvents);
86
+ // Execution shall not pass if no events are allowed
87
+ if (!allowedEvents.length) {
88
+ return { id, destination, queue: currentQueue }; // Don't push if not allowed
89
+ }
90
+ // Initialize the destination if needed
91
+ const isInitialized = await tryCatchAsync(destinationInit)(collector, destination);
92
+ if (!isInitialized)
93
+ return { id, destination, queue: currentQueue };
94
+ // Process the destinations event queue
95
+ let error = false;
96
+ if (!destination.dlq)
97
+ destination.dlq = [];
98
+ // Process allowed events and store failed ones in the dead letter queue (DLQ)
99
+ await Promise.all(allowedEvents.map(async (event) => {
100
+ // Merge event with collector state, prioritizing event properties
101
+ event.globals = assign(globals, event.globals);
102
+ event.user = assign(user, event.user);
103
+ await tryCatchAsync(destinationPush, (err) => {
104
+ // Call custom error handling if available
105
+ if (collector.config.onError)
106
+ collector.config.onError(err, collector);
107
+ error = true; // oh no
108
+ // Add failed event to destinations DLQ
109
+ destination.dlq.push([event, err]);
110
+ return false;
111
+ })(collector, destination, event);
112
+ return event;
113
+ }));
114
+ return { id, destination, error };
115
+ }));
116
+ const successful = [];
117
+ const queued = [];
118
+ const failed = [];
119
+ for (const result of results) {
120
+ if (result.skipped)
121
+ continue;
122
+ const destination = result.destination;
123
+ const ref = { id: result.id, destination };
124
+ if (result.error) {
125
+ failed.push(ref);
126
+ }
127
+ else if (result.queue && result.queue.length) {
128
+ // Merge queue with existing queue
129
+ destination.queue = (destination.queue || []).concat(result.queue);
130
+ queued.push(ref);
131
+ }
132
+ else {
133
+ successful.push(ref);
134
+ }
135
+ }
136
+ return createPushResult({
137
+ ok: !failed.length,
138
+ event,
139
+ successful,
140
+ queued,
141
+ failed,
142
+ });
143
+ }
144
+ /**
145
+ * Initializes a destination.
146
+ *
147
+ * @template Destination
148
+ * @param collector - The walkerOS collector instance.
149
+ * @param destination - The destination to initialize.
150
+ * @returns Whether the destination was initialized successfully.
151
+ */
152
+ export async function destinationInit(collector, destination) {
153
+ // Check if the destination was initialized properly or try to do so
154
+ if (destination.init && !destination.config.init) {
155
+ const context = {
156
+ collector,
157
+ config: destination.config,
158
+ env: mergeEnvironments(destination.env, destination.config.env),
159
+ };
160
+ const configResult = await useHooks(destination.init, 'DestinationInit', collector.hooks)(context);
161
+ // Actively check for errors (when false)
162
+ if (configResult === false)
163
+ return configResult; // don't push if init is false
164
+ // Update the destination config if it was returned
165
+ destination.config = {
166
+ ...(configResult || destination.config),
167
+ init: true, // Remember that the destination was initialized
168
+ };
169
+ }
170
+ return true; // Destination is ready to push
171
+ }
172
+ /**
173
+ * Pushes an event to a single destination.
174
+ * Handles mapping, batching, and consent checks.
175
+ *
176
+ * @template Destination
177
+ * @param collector - The walkerOS collector instance.
178
+ * @param destination - The destination to push to.
179
+ * @param event - The event to push.
180
+ * @returns Whether the event was pushed successfully.
181
+ */
182
+ export async function destinationPush(collector, destination, event) {
183
+ const { config } = destination;
184
+ const processed = await processEventMapping(event, config, collector);
185
+ if (processed.ignore)
186
+ return false;
187
+ const context = {
188
+ collector,
189
+ config,
190
+ data: processed.data,
191
+ mapping: processed.mapping,
192
+ env: mergeEnvironments(destination.env, config.env),
193
+ };
194
+ const eventMapping = processed.mapping;
195
+ if (eventMapping?.batch && destination.pushBatch) {
196
+ const batched = eventMapping.batched || {
197
+ key: processed.mappingKey || '',
198
+ events: [],
199
+ data: [],
200
+ };
201
+ batched.events.push(processed.event);
202
+ if (isDefined(processed.data))
203
+ batched.data.push(processed.data);
204
+ eventMapping.batchFn =
205
+ eventMapping.batchFn ||
206
+ debounce((destination, collector) => {
207
+ const batchContext = {
208
+ collector,
209
+ config,
210
+ data: processed.data,
211
+ mapping: eventMapping,
212
+ env: mergeEnvironments(destination.env, config.env),
213
+ };
214
+ useHooks(destination.pushBatch, 'DestinationPushBatch', collector.hooks)(batched, batchContext);
215
+ batched.events = [];
216
+ batched.data = [];
217
+ }, eventMapping.batch);
218
+ eventMapping.batched = batched;
219
+ eventMapping.batchFn?.(destination, collector);
220
+ }
221
+ else {
222
+ // It's time to go to the destination's side now
223
+ await useHooks(destination.push, 'DestinationPush', collector.hooks)(processed.event, context);
224
+ }
225
+ return true;
226
+ }
227
+ /**
228
+ * Creates a standardized result object for push operations.
229
+ *
230
+ * @param partialResult - A partial result to merge with the default result.
231
+ * @returns The push result.
232
+ */
233
+ export function createPushResult(partialResult) {
234
+ return assign({
235
+ ok: !partialResult?.failed?.length,
236
+ successful: [],
237
+ queued: [],
238
+ failed: [],
239
+ }, partialResult);
240
+ }
241
+ /**
242
+ * Initializes a map of destinations using ONLY the unified code/config/env pattern.
243
+ * Does NOT call destination.init() - that happens later during push with proper consent checks.
244
+ *
245
+ * @param destinations - The destinations to initialize.
246
+ * @param collector - The collector instance for destination init context.
247
+ * @returns The initialized destinations.
248
+ */
249
+ export async function initDestinations(_collector, destinations = {}) {
250
+ const result = {};
251
+ for (const [name, destinationDef] of Object.entries(destinations)) {
252
+ const { code, config = {}, env = {} } = destinationDef;
253
+ // Merge config: destination default + provided config
254
+ const mergedConfig = {
255
+ ...code.config,
256
+ ...config,
257
+ };
258
+ // Merge environment: destination default + provided env
259
+ const mergedEnv = mergeEnvironments(code.env, env);
260
+ // Create destination instance by spreading code and overriding config/env
261
+ result[name] = {
262
+ ...code,
263
+ config: mergedConfig,
264
+ env: mergedEnv,
265
+ };
266
+ }
267
+ return result;
268
+ }
269
+ /**
270
+ * Merges destination environment with config environment
271
+ * Config env takes precedence over destination env for overrides
272
+ */
273
+ function mergeEnvironments(destinationEnv, configEnv) {
274
+ // If neither environment exists, return empty object
275
+ if (!destinationEnv && !configEnv)
276
+ return {};
277
+ // If only one exists, return it
278
+ if (!configEnv)
279
+ return destinationEnv;
280
+ if (!destinationEnv)
281
+ return configEnv;
282
+ // Both exist - merge objects with configEnv taking precedence
283
+ if (isObject(destinationEnv) && isObject(configEnv)) {
284
+ return { ...destinationEnv, ...configEnv };
285
+ }
286
+ // If they're not both objects, config env overrides destination env
287
+ return configEnv;
288
+ }
289
+ //# sourceMappingURL=destination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"destination.js","sourceRoot":"","sources":["../src/destination.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,KAAK,EACL,QAAQ,EACR,KAAK,EACL,iBAAiB,EACjB,SAAS,EACT,QAAQ,EACR,mBAAmB,EACnB,aAAa,EACb,QAAQ,GACT,MAAM,gBAAgB,CAAC;AAExB;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,SAA6B,EAC7B,IAAsB,EACtB,OAA4B;IAE5B,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UA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ChC,SAA2B;IAE3B,qDAAqD;IACrD,IAAI,CAAC,cAAc,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAE7C,gCAAgC;IAChC,IAAI,CAAC,SAAS;QAAE,OAAO,cAAe,CAAC;IACvC,IAAI,CAAC,cAAc;QAAE,OAAO,SAAS,CAAC;IAEtC,8DAA8D;IAC9D,IAAI,QAAQ,CAAC,cAAc,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,OAAO,EAAE,GAAG,cAAc,EAAE,GAAG,SAAS,EAAE,CAAC;IAC7C,CAAC;IAED,oEAAoE;IACpE,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
package/dist/elb.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { Collector, Source } from '@walkeros/core';
2
+ /**
3
+ * Creates the default ELB source.
4
+ * Routes between collector.push and collector.command based on input.
5
+ * Provides backward-compatible flexible argument interface.
6
+ *
7
+ * @param collector - The walkerOS collector instance
8
+ * @returns ELB source instance
9
+ */
10
+ export declare function createElbSource(collector: Collector.Instance): Source.Instance;
11
+ //# sourceMappingURL=elb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elb.d.ts","sourceRoot":"","sources":["../src/elb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAiB,MAAM,gBAAgB,CAAC;AAEvE;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,SAAS,CAAC,QAAQ,GAC5B,MAAM,CAAC,QAAQ,CA8DjB"}
package/dist/elb.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Creates the default ELB source.
3
+ * Routes between collector.push and collector.command based on input.
4
+ * Provides backward-compatible flexible argument interface.
5
+ *
6
+ * @param collector - The walkerOS collector instance
7
+ * @returns ELB source instance
8
+ */
9
+ export function createElbSource(collector) {
10
+ return {
11
+ type: 'elb',
12
+ config: {},
13
+ // The push function is the elb() interface users interact with
14
+ push: async (eventOrCommand, data, options, context, nested, custom) => {
15
+ // Detect walker commands
16
+ if (typeof eventOrCommand === 'string' &&
17
+ eventOrCommand.startsWith('walker ')) {
18
+ const command = eventOrCommand.replace('walker ', '');
19
+ return collector.command(command, data, options);
20
+ }
21
+ // Build event object
22
+ let event;
23
+ if (typeof eventOrCommand === 'string') {
24
+ // Convert string to object: elb('page view', { title: 'Home' })
25
+ event = { name: eventOrCommand };
26
+ if (data && typeof data === 'object' && !Array.isArray(data)) {
27
+ event.data = data;
28
+ }
29
+ }
30
+ else if (eventOrCommand && typeof eventOrCommand === 'object') {
31
+ // Use object directly: elb({ name: 'page view', data: {...} })
32
+ event = eventOrCommand;
33
+ // Merge additional data if provided
34
+ if (data && typeof data === 'object' && !Array.isArray(data)) {
35
+ event.data = {
36
+ ...(event.data || {}),
37
+ ...data,
38
+ };
39
+ }
40
+ }
41
+ else {
42
+ // Invalid input
43
+ return { ok: false, successful: [], queued: [], failed: [] };
44
+ }
45
+ // Add optional properties if provided
46
+ if (context && typeof context === 'object') {
47
+ event.context = context;
48
+ }
49
+ if (nested && Array.isArray(nested)) {
50
+ event.nested = nested;
51
+ }
52
+ if (custom && typeof custom === 'object') {
53
+ event.custom = custom;
54
+ }
55
+ // Call collector.push with event object
56
+ return collector.push(event);
57
+ },
58
+ };
59
+ }
60
+ //# sourceMappingURL=elb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elb.js","sourceRoot":"","sources":["../src/elb.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,SAA6B;IAE7B,OAAO;QACL,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,EAAE;QAEV,+DAA+D;QAC/D,IAAI,EAAE,KAAK,EACT,cAAwB,EACxB,IAAc,EACd,OAAiB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C,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC3C,KAAK,CAAC,OAAO,GAAG,OAAqC,CAAC;YACxD,CAAC;YACD,IAAI,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACpC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;YACxB,CAAC;YACD,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACzC,KAAK,CAAC,MAAM,GAAG,MAA6B,CAAC;YAC/C,CAAC;YAED,wCAAwC;YACxC,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/flow.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Collector, Elb } from '@walkeros/core';
2
+ import type { StartFlow } from './types';
3
+ export declare function startFlow<ElbPush extends Elb.Fn = Elb.Fn>(initConfig?: Collector.InitConfig): Promise<StartFlow<ElbPush>>;
4
+ //# sourceMappingURL=flow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../src/flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKzC,wBAAsB,SAAS,CAAC,OAAO,SAAS,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,EAC7D,UAAU,CAAC,EAAE,SAAS,CAAC,UAAU,GAChC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAkD7B"}
package/dist/flow.js ADDED
@@ -0,0 +1,44 @@
1
+ import { collector } from './collector';
2
+ import { createElbSource } from './elb';
3
+ import { initSources } from './source';
4
+ export async function startFlow(initConfig) {
5
+ initConfig = initConfig || {};
6
+ const instance = await collector(initConfig);
7
+ // Create and register ELB source first
8
+ const elbSource = createElbSource(instance);
9
+ instance.sources.elb = elbSource;
10
+ // Now initialize other sources with ELB source available
11
+ const additionalSources = await initSources(instance, initConfig.sources || {});
12
+ Object.assign(instance.sources, additionalSources);
13
+ const { consent, user, globals, custom } = initConfig;
14
+ if (consent)
15
+ await instance.command('consent', consent);
16
+ if (user)
17
+ await instance.command('user', user);
18
+ if (globals)
19
+ Object.assign(instance.globals, globals);
20
+ if (custom)
21
+ Object.assign(instance.custom, custom);
22
+ if (instance.config.run)
23
+ await instance.command('run');
24
+ // Determine the primary elb:
25
+ // 1. Use explicitly marked primary source
26
+ // 2. Use first non-elb source if any exist
27
+ // 3. Fallback to ELB source
28
+ let primaryElb = elbSource.push;
29
+ const sources = Object.values(instance.sources).filter((source) => source.type !== 'elb');
30
+ // First, check for explicitly marked primary source
31
+ const markedPrimary = sources.find((source) => source.config.primary);
32
+ if (markedPrimary) {
33
+ primaryElb = markedPrimary.push;
34
+ }
35
+ else if (sources.length > 0) {
36
+ // Use first source as default
37
+ primaryElb = sources[0].push;
38
+ }
39
+ return {
40
+ collector: instance,
41
+ elb: primaryElb,
42
+ };
43
+ }
44
+ //# sourceMappingURL=flow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow.js","sourceRoot":"","sources":["../src/flow.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,UAAiC;IAEjC,UAAU,GAAG,UAAU,IAAI,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,UAAU,CAAC,CAAC;IAE7C,uCAAuC;IACvC,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,QAAQ,CAAC,OAAO,CAAC,G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CAAC;IAC5C,CAAC;SAAM,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9B,8BAA8B;QAC9B,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,IAAc,CAAC;IACzC,CAAC;IAED,OAAO;QACL,SAAS,EAAE,QAAQ;QACnB,GAAG,EAAE,UAAqB;KAC3B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { Collector, WalkerOS, Elb } from '@walkeros/core';
2
+ import type { RunState } from './types/collector';
3
+ /**
4
+ * Handles common commands.
5
+ *
6
+ * @param collector The walkerOS collector instance.
7
+ * @param action The action to handle.
8
+ * @param data The data to handle.
9
+ * @param options The options to handle.
10
+ * @returns A promise that resolves with the push result or undefined.
11
+ */
12
+ export declare function commonHandleCommand(collector: Collector.Instance, action: string, data?: unknown, options?: unknown): Promise<Elb.PushResult>;
13
+ /**
14
+ * Creates a full event from a partial event.
15
+ *
16
+ * @param collector The walkerOS collector instance.
17
+ * @param partialEvent The partial event to transform.
18
+ * @returns The full event.
19
+ */
20
+ export declare function createEvent(collector: Collector.Instance, partialEvent: WalkerOS.PartialEvent): WalkerOS.Event;
21
+ /**
22
+ * Runs the collector by setting it to allowed state and processing queued events.
23
+ *
24
+ * @param collector The walkerOS collector instance.
25
+ * @param state Optional state to merge with the collector (user, globals, consent, custom).
26
+ * @returns A promise that resolves with the push result.
27
+ */
28
+ export declare function runCollector(collector: Collector.Instance, state?: RunState): Promise<Elb.PushResult>;
29
+ //# sourceMappingURL=handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAe,GAAG,EAAM,MAAM,gBAAgB,CAAC;AAOhF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,SAAS,CAAC,QAAQ,EAC7B,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAkFzB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,SAAS,CAAC,QAAQ,EAC7B,YAAY,EAAE,QAAQ,CAAC,YAAY,GAClC,QAAQ,CAAC,KAAK,CAuDhB;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,SAAS,CAAC,QAAQ,EAC7B,KAAK,CAAC,EAAE,QAAQ,GACf,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAuDzB"}
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;AACvC,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,MA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