@walkeros/cli 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2145,16 +2145,16 @@ import { Level as Level2 } from "@walkeros/core";
2145
2145
 
2146
2146
  // ../collector/dist/index.mjs
2147
2147
  import { assign as o } from "@walkeros/core";
2148
- import { assign as r, createLogger as i } from "@walkeros/core";
2148
+ import { assign as i, createLogger as r } from "@walkeros/core";
2149
2149
  import { assign as a, clone as c, debounce as u, getId as f, getGrantedConsent as l, isDefined as d, isFunction as g, isObject as m, processEventMapping as p, tryCatchAsync as h, useHooks as w } from "@walkeros/core";
2150
2150
  import { isArray as y } from "@walkeros/core";
2151
2151
  import { tryCatch as b, tryCatchAsync as v } from "@walkeros/core";
2152
2152
  import { getMappingValue as k, tryCatchAsync as C } from "@walkeros/core";
2153
2153
  import { isObject as O, tryCatchAsync as q, useHooks as j } from "@walkeros/core";
2154
- import { assign as M, getId as Q, isFunction as V, isString as K } from "@walkeros/core";
2155
- import { isObject as X } from "@walkeros/core";
2156
- import { getGrantedConsent as tn, processEventMapping as on, tryCatchAsync as sn, useHooks as rn } from "@walkeros/core";
2157
- import { useHooks as cn, tryCatchAsync as un } from "@walkeros/core";
2154
+ import { assign as M, getId as Q, isFunction as V, isString as _ } from "@walkeros/core";
2155
+ import { isObject as K } from "@walkeros/core";
2156
+ import { getGrantedConsent as en, processEventMapping as tn, tryCatchAsync as on, useHooks as sn } from "@walkeros/core";
2157
+ import { useHooks as an, tryCatchAsync as cn } from "@walkeros/core";
2158
2158
  var e = { 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", Shutdown: "shutdown", User: "user", Walker: "walker" };
2159
2159
  var t = { Commands: e, Utils: { Storage: { Cookie: "cookie", Local: "local", Session: "session" } } };
2160
2160
  function s(n, e2) {
@@ -2166,18 +2166,15 @@ function s(n, e2) {
2166
2166
  }), n.consent = o(n.consent, s2), { update: s2, runQueue: t2 };
2167
2167
  }
2168
2168
  function D(n) {
2169
- return null != n && false !== n && "object" == typeof n && true === n.__branch;
2170
- }
2171
- function A(n) {
2172
2169
  const e2 = {};
2173
2170
  for (const [t2, o2] of Object.entries(n)) o2.config?.next ? e2[t2] = { next: o2.config.next } : e2[t2] = {};
2174
2171
  return e2;
2175
2172
  }
2176
- function E(n, e2) {
2173
+ function A(n, e2) {
2177
2174
  const t2 = n.config || {}, o2 = n[e2];
2178
2175
  return void 0 !== o2 ? { config: { ...t2, [e2]: o2 }, chainValue: o2 } : { config: t2, chainValue: void 0 };
2179
2176
  }
2180
- function P(n, e2 = {}) {
2177
+ function E(n, e2 = {}) {
2181
2178
  if (!n) return [];
2182
2179
  if (Array.isArray(n)) return n;
2183
2180
  const t2 = [], o2 = /* @__PURE__ */ new Set();
@@ -2193,57 +2190,60 @@ function P(n, e2 = {}) {
2193
2190
  }
2194
2191
  return t2;
2195
2192
  }
2196
- async function x(n, e2, t2) {
2193
+ async function P(n, e2, t2) {
2197
2194
  if (e2.init && !e2.config.init) {
2198
- const o2 = e2.type || "unknown", s2 = n.logger.scope(`transformer:${o2}`), r2 = { collector: n, logger: s2, id: t2, config: e2.config, env: R(e2.config.env) };
2195
+ const o2 = e2.type || "unknown", s2 = n.logger.scope(`transformer:${o2}`), i2 = { collector: n, logger: s2, id: t2, config: e2.config, env: $(e2.config.env) };
2199
2196
  s2.debug("init");
2200
- const i2 = await j(e2.init, "TransformerInit", n.hooks)(r2);
2201
- if (false === i2) return false;
2202
- e2.config = { ...i2 || e2.config, init: true }, s2.debug("init done");
2197
+ const r2 = await j(e2.init, "TransformerInit", n.hooks)(i2);
2198
+ if (false === r2) return false;
2199
+ e2.config = { ...r2 || e2.config, init: true }, s2.debug("init done");
2203
2200
  }
2204
2201
  return true;
2205
2202
  }
2206
- async function S(n, e2, t2, o2, s2, r2) {
2207
- const i2 = e2.type || "unknown", a2 = n.logger.scope(`transformer:${i2}`), c2 = { collector: n, logger: a2, id: t2, ingest: s2, config: e2.config, env: { ...R(e2.config.env), ...r2 ? { respond: r2 } : {} } };
2203
+ async function x(n, e2, t2, o2, s2, i2) {
2204
+ const r2 = e2.type || "unknown", a2 = n.logger.scope(`transformer:${r2}`), c2 = { collector: n, logger: a2, id: t2, ingest: s2, config: e2.config, env: { ...$(e2.config.env), ...i2 ? { respond: i2 } : {} } };
2208
2205
  a2.debug("push", { event: o2.name });
2209
2206
  const u2 = await j(e2.push, "TransformerPush", n.hooks)(o2, c2);
2210
2207
  return a2.debug("push done"), u2;
2211
2208
  }
2212
- async function $(n, e2, t2, o2, s2, r2) {
2213
- let i2 = o2;
2209
+ async function S(n, e2, t2, o2, s2, i2) {
2210
+ let r2 = o2, a2 = i2;
2214
2211
  for (const o3 of t2) {
2215
2212
  const t3 = e2[o3];
2216
2213
  if (!t3) {
2217
2214
  n.logger.warn(`Transformer not found: ${o3}`);
2218
2215
  continue;
2219
2216
  }
2220
- if (!await q(x)(n, t3, o3)) return n.logger.error(`Transformer init failed: ${o3}`), null;
2221
- const a2 = await q(S, (e3) => (n.logger.scope(`transformer:${t3.type || "unknown"}`).error("Push failed", { error: e3 }), false))(n, t3, o3, i2, s2, r2);
2222
- if (false === a2) return null;
2223
- if (D(a2)) {
2224
- const t4 = P(a2.next, A(e2));
2225
- return t4.length > 0 ? $(n, e2, t4, a2.event, s2, r2) : (n.logger.warn(`Branch target not found: ${JSON.stringify(a2.next)}`), null);
2217
+ if (!await q(P)(n, t3, o3)) return n.logger.error(`Transformer init failed: ${o3}`), null;
2218
+ const i3 = await q(x, (e3) => (n.logger.scope(`transformer:${t3.type || "unknown"}`).error("Push failed", { error: e3 }), false))(n, t3, o3, r2, s2, a2);
2219
+ if (false === i3) return null;
2220
+ if (i3 && "object" == typeof i3) {
2221
+ const { event: t4, respond: o4, next: c2 } = i3;
2222
+ if (o4 && (a2 = o4), c2) {
2223
+ const o5 = E(c2, D(e2));
2224
+ return o5.length > 0 ? S(n, e2, o5, t4 || r2, s2, a2) : (n.logger.warn(`Branch target not found: ${JSON.stringify(c2)}`), null);
2225
+ }
2226
+ t4 && (r2 = t4);
2226
2227
  }
2227
- void 0 !== a2 && (i2 = a2);
2228
2228
  }
2229
- return i2;
2229
+ return r2;
2230
2230
  }
2231
- function R(n) {
2231
+ function $(n) {
2232
2232
  return n && O(n) ? n : {};
2233
2233
  }
2234
- async function T(n, e2, t2) {
2235
- const { code: o2, config: s2 = {}, env: r2 = {}, primary: i2, next: a2 } = t2;
2234
+ async function R(n, e2, t2) {
2235
+ const { code: o2, config: s2 = {}, env: i2 = {}, primary: r2, next: a2 } = t2;
2236
2236
  let c2, u2;
2237
- const f2 = P(a2, A(n.transformers)), l2 = n.logger.scope("source").scope(e2), d2 = { push: (t3, o3 = {}) => n.push(t3, { ...o3, id: e2, ingest: c2, respond: u2, mapping: s2, preChain: f2 }), command: n.command, sources: n.sources, elb: n.sources.elb.push, logger: l2, ...r2 }, g2 = { collector: n, logger: l2, id: e2, config: s2, env: d2, setIngest: async (e3) => {
2237
+ const f2 = E(a2, D(n.transformers)), l2 = n.logger.scope("source").scope(e2), d2 = { push: (t3, o3 = {}) => n.push(t3, { ...o3, id: e2, ingest: c2, respond: u2, mapping: s2, preChain: f2 }), command: n.command, sources: n.sources, elb: n.sources.elb.push, logger: l2, ...i2 }, g2 = { collector: n, logger: l2, id: e2, config: s2, env: d2, setIngest: async (e3) => {
2238
2238
  c2 = s2.ingest ? await k(e3, s2.ingest, { collector: n }) : void 0;
2239
2239
  }, setRespond: (n2) => {
2240
2240
  u2 = n2;
2241
2241
  } }, m2 = await C(o2)(g2);
2242
2242
  if (!m2) return;
2243
2243
  const p2 = m2.type || "unknown", h2 = n.logger.scope(p2).scope(e2);
2244
- return d2.logger = h2, i2 && (m2.config = { ...m2.config, primary: i2 }), m2;
2244
+ return d2.logger = h2, r2 && (m2.config = { ...m2.config, primary: r2 }), m2;
2245
2245
  }
2246
- async function I(n, e2 = {}) {
2246
+ async function T(n, e2 = {}) {
2247
2247
  const t2 = {};
2248
2248
  for (const [o2, s2] of Object.entries(e2)) {
2249
2249
  const { config: e3 = {} } = s2;
@@ -2251,81 +2251,81 @@ async function I(n, e2 = {}) {
2251
2251
  n.pending.sources[o2] = s2;
2252
2252
  continue;
2253
2253
  }
2254
- const r2 = await T(n, o2, s2);
2255
- r2 && (t2[o2] = r2);
2254
+ const i2 = await R(n, o2, s2);
2255
+ i2 && (t2[o2] = i2);
2256
2256
  }
2257
2257
  return t2;
2258
2258
  }
2259
- async function B(n, e2, t2) {
2260
- const o2 = n.on, s2 = o2[e2] || [], r2 = y(t2) ? t2 : [t2];
2261
- r2.forEach((n2) => {
2259
+ async function I(n, e2, t2) {
2260
+ const o2 = n.on, s2 = o2[e2] || [], i2 = y(t2) ? t2 : [t2];
2261
+ i2.forEach((n2) => {
2262
2262
  s2.push(n2);
2263
- }), o2[e2] = s2, await H(n, e2, r2);
2263
+ }), o2[e2] = s2, await G(n, e2, i2);
2264
2264
  }
2265
- function G(n, e2, t2, o2, s2) {
2265
+ function B(n, e2, t2, o2, s2) {
2266
2266
  if (!e2.on) return;
2267
- const r2 = e2.type || "unknown", i2 = n.logger.scope(r2).scope("on").scope(o2), a2 = { collector: n, logger: i2, id: t2, config: e2.config, data: s2, env: L(e2.env, e2.config.env) };
2267
+ const i2 = e2.type || "unknown", r2 = n.logger.scope(i2).scope("on").scope(o2), a2 = { collector: n, logger: r2, id: t2, config: e2.config, data: s2, env: L(e2.env, e2.config.env) };
2268
2268
  b(e2.on)(o2, a2);
2269
2269
  }
2270
- async function H(n, e2, o2, s2) {
2271
- let r2, i2 = o2 || [];
2272
- switch (o2 || (i2 = n.on[e2] || []), e2) {
2270
+ async function G(n, e2, o2, s2) {
2271
+ let i2, r2 = o2 || [];
2272
+ switch (o2 || (r2 = n.on[e2] || []), e2) {
2273
2273
  case t.Commands.Consent:
2274
- r2 = s2 || n.consent;
2274
+ i2 = s2 || n.consent;
2275
2275
  break;
2276
2276
  case t.Commands.Session:
2277
- r2 = n.session;
2277
+ i2 = n.session;
2278
2278
  break;
2279
2279
  case t.Commands.User:
2280
- r2 = s2 || n.user;
2280
+ i2 = s2 || n.user;
2281
2281
  break;
2282
2282
  case t.Commands.Custom:
2283
- r2 = s2 || n.custom;
2283
+ i2 = s2 || n.custom;
2284
2284
  break;
2285
2285
  case t.Commands.Globals:
2286
- r2 = s2 || n.globals;
2286
+ i2 = s2 || n.globals;
2287
2287
  break;
2288
2288
  case t.Commands.Config:
2289
- r2 = s2 || n.config;
2289
+ i2 = s2 || n.config;
2290
2290
  break;
2291
2291
  case t.Commands.Ready:
2292
2292
  case t.Commands.Run:
2293
2293
  default:
2294
- r2 = void 0;
2294
+ i2 = void 0;
2295
2295
  }
2296
2296
  let a2 = false;
2297
2297
  for (const t2 of Object.values(n.sources)) if (t2.on) {
2298
- false === await v(t2.on)(e2, r2) && (a2 = true);
2298
+ false === await v(t2.on)(e2, i2) && (a2 = true);
2299
2299
  }
2300
2300
  if (Object.entries(n.destinations).forEach(([t2, o3]) => {
2301
2301
  if (o3.on) {
2302
- if (!o3.config.init) return o3.queueOn = o3.queueOn || [], void o3.queueOn.push({ type: e2, data: r2 });
2303
- G(n, o3, t2, e2, r2);
2302
+ if (!o3.config.init) return o3.queueOn = o3.queueOn || [], void o3.queueOn.push({ type: e2, data: i2 });
2303
+ B(n, o3, t2, e2, i2);
2304
2304
  }
2305
2305
  }), (Object.keys(n.pending.sources).length > 0 || Object.keys(n.pending.destinations).length > 0) && await (async function(n2, e3) {
2306
2306
  for (const [t2, o3] of Object.entries(n2.pending.sources)) {
2307
2307
  if (!n2.pending.sources[t2] || n2.sources[t2]) continue;
2308
2308
  const s3 = o3.config?.require;
2309
2309
  if (!s3) continue;
2310
- const r3 = s3.indexOf(e3);
2311
- if (-1 === r3) continue;
2312
- if (s3.splice(r3, 1), s3.length > 0) continue;
2310
+ const i3 = s3.indexOf(e3);
2311
+ if (-1 === i3) continue;
2312
+ if (s3.splice(i3, 1), s3.length > 0) continue;
2313
2313
  delete n2.pending.sources[t2];
2314
- const i3 = await T(n2, t2, o3);
2315
- i3 && (n2.sources[t2] = i3);
2314
+ const r3 = await R(n2, t2, o3);
2315
+ r3 && (n2.sources[t2] = r3);
2316
2316
  }
2317
2317
  for (const [t2, o3] of Object.entries(n2.pending.destinations)) {
2318
2318
  if (!n2.pending.destinations[t2] || n2.destinations[t2]) continue;
2319
2319
  const s3 = o3.config?.require;
2320
2320
  if (!s3) continue;
2321
- const r3 = s3.indexOf(e3);
2322
- if (-1 === r3) continue;
2323
- if (s3.splice(r3, 1), s3.length > 0) continue;
2321
+ const i3 = s3.indexOf(e3);
2322
+ if (-1 === i3) continue;
2323
+ if (s3.splice(i3, 1), s3.length > 0) continue;
2324
2324
  delete n2.pending.destinations[t2];
2325
- const i3 = W(o3);
2326
- false !== i3.config.queue && (i3.queuePush = [...n2.queue]), n2.destinations[t2] = i3;
2325
+ const r3 = W(o3);
2326
+ false !== r3.config.queue && (r3.queuePush = [...n2.queue]), n2.destinations[t2] = r3;
2327
2327
  }
2328
- })(n, e2), !i2.length) return !a2;
2328
+ })(n, e2), !r2.length) return !a2;
2329
2329
  switch (e2) {
2330
2330
  case t.Commands.Consent:
2331
2331
  !(function(n2, e3, t2) {
@@ -2335,7 +2335,7 @@ async function H(n, e2, o2, s2) {
2335
2335
  b(e4[t3])(n2, o3);
2336
2336
  });
2337
2337
  });
2338
- })(n, i2, s2);
2338
+ })(n, r2, s2);
2339
2339
  break;
2340
2340
  case t.Commands.Ready:
2341
2341
  case t.Commands.Run:
@@ -2343,7 +2343,7 @@ async function H(n, e2, o2, s2) {
2343
2343
  n2.allowed && e3.forEach((e4) => {
2344
2344
  b(e4)(n2);
2345
2345
  });
2346
- })(n, i2);
2346
+ })(n, r2);
2347
2347
  break;
2348
2348
  case t.Commands.Session:
2349
2349
  !(function(n2, e3) {
@@ -2351,31 +2351,31 @@ async function H(n, e2, o2, s2) {
2351
2351
  e3.forEach((e4) => {
2352
2352
  b(e4)(n2, n2.session);
2353
2353
  });
2354
- })(n, i2);
2354
+ })(n, r2);
2355
2355
  break;
2356
2356
  default:
2357
- i2.forEach((e3) => {
2358
- "function" == typeof e3 && b(e3)(n, r2);
2357
+ r2.forEach((e3) => {
2358
+ "function" == typeof e3 && b(e3)(n, i2);
2359
2359
  });
2360
2360
  }
2361
2361
  return !a2;
2362
2362
  }
2363
- async function U(n, e2, t2) {
2364
- const { code: o2, config: s2 = {}, env: r2 = {}, before: i2 } = e2;
2363
+ async function H(n, e2, t2) {
2364
+ const { code: o2, config: s2 = {}, env: i2 = {}, before: r2 } = e2;
2365
2365
  if (!g(o2.push)) return N({ ok: false, failed: { invalid: { type: "invalid", error: "Destination code must have a push method" } } });
2366
- const a2 = t2 || s2 || { init: false }, c2 = i2 ? { ...a2, before: i2 } : a2, u2 = { ...o2, config: c2, env: L(o2.env, r2) };
2366
+ const a2 = t2 || s2 || { init: false }, c2 = r2 ? { ...a2, before: r2 } : a2, u2 = { ...o2, config: c2, env: L(o2.env, i2) };
2367
2367
  let l2 = u2.config.id;
2368
2368
  if (!l2) do {
2369
2369
  l2 = f(4);
2370
2370
  } while (n.destinations[l2]);
2371
- return n.destinations[l2] = u2, false !== u2.config.queue && (u2.queuePush = [...n.queue]), _(n, void 0, {}, { [l2]: u2 });
2371
+ return n.destinations[l2] = u2, false !== u2.config.queue && (u2.queuePush = [...n.queue]), U(n, void 0, {}, { [l2]: u2 });
2372
2372
  }
2373
- async function _(n, e2, t2 = {}, o2) {
2374
- const { allowed: s2, consent: r2, globals: i2, user: u2 } = n;
2373
+ async function U(n, e2, t2 = {}, o2) {
2374
+ const { allowed: s2, consent: i2, globals: r2, user: u2 } = n;
2375
2375
  if (!s2) return N({ ok: false });
2376
2376
  e2 && (n.queue.push(e2), n.status.in++), o2 || (o2 = n.destinations);
2377
2377
  const f2 = await Promise.all(Object.entries(o2 || {}).map(async ([o3, s3]) => {
2378
- let f3 = (s3.queuePush || []).map((n2) => ({ ...n2, consent: r2 }));
2378
+ let f3 = (s3.queuePush || []).map((n2) => ({ ...n2, consent: i2 }));
2379
2379
  if (s3.queuePush = [], e2) {
2380
2380
  const n2 = c(e2);
2381
2381
  f3.push(n2);
@@ -2386,7 +2386,7 @@ async function _(n, e2, t2 = {}, o2) {
2386
2386
  return { id: o3, destination: s3, skipped: !e3 };
2387
2387
  }
2388
2388
  const d3 = [], g3 = f3.filter((n2) => {
2389
- const e3 = l(s3.config.consent, r2, n2.consent);
2389
+ const e3 = l(s3.config.consent, i2, n2.consent);
2390
2390
  return !e3 || (n2.consent = e3, d3.push(n2), false);
2391
2391
  });
2392
2392
  if (s3.queuePush.push(...g3), !d3.length) return { id: o3, destination: s3, queue: f3 };
@@ -2395,21 +2395,21 @@ async function _(n, e2, t2 = {}, o2) {
2395
2395
  s3.dlq || (s3.dlq = []);
2396
2396
  const w2 = (function(n2, e3) {
2397
2397
  const t3 = n2.config.before;
2398
- return t3 ? P(t3, A(e3)) : [];
2398
+ return t3 ? E(t3, D(e3)) : [];
2399
2399
  })(s3, n.transformers);
2400
2400
  let y2 = 0;
2401
2401
  return await Promise.all(d3.map(async (e3) => {
2402
- e3.globals = a(i2, e3.globals), e3.user = a(u2, e3.user);
2403
- let r3 = e3;
2402
+ e3.globals = a(r2, e3.globals), e3.user = a(u2, e3.user);
2403
+ let i3 = e3;
2404
2404
  if (w2.length > 0 && n.transformers && Object.keys(n.transformers).length > 0) {
2405
- const o4 = await $(n, n.transformers, w2, e3, t2.ingest, t2.respond);
2405
+ const o4 = await S(n, n.transformers, w2, e3, t2.ingest, t2.respond);
2406
2406
  if (null === o4) return e3;
2407
- r3 = o4;
2407
+ i3 = o4;
2408
2408
  }
2409
2409
  const c2 = Date.now(), f4 = await h(J, (e4) => {
2410
2410
  const t3 = s3.type || "unknown";
2411
- n.logger.scope(t3).error("Push failed", { error: e4, event: r3.name }), m3 = e4, s3.dlq.push([r3, e4]);
2412
- })(n, s3, o3, r3, t2.ingest, t2.respond);
2411
+ n.logger.scope(t3).error("Push failed", { error: e4, event: i3.name }), m3 = e4, s3.dlq.push([i3, e4]);
2412
+ })(n, s3, o3, i3, t2.ingest, t2.respond);
2413
2413
  return y2 += Date.now() - c2, void 0 !== f4 && (p2 = f4), e3;
2414
2414
  })), { id: o3, destination: s3, error: m3, response: p2, totalDuration: y2 };
2415
2415
  })), d2 = {}, g2 = {}, m2 = {};
@@ -2417,30 +2417,30 @@ async function _(n, e2, t2 = {}, o2) {
2417
2417
  if (e3.skipped) continue;
2418
2418
  const t3 = e3.destination, o3 = { type: t3.type || "unknown", data: e3.response };
2419
2419
  n.status.destinations[e3.id] || (n.status.destinations[e3.id] = { count: 0, failed: 0, duration: 0 });
2420
- const s3 = n.status.destinations[e3.id], r3 = Date.now();
2421
- e3.error ? (o3.error = e3.error, m2[e3.id] = o3, s3.failed++, s3.lastAt = r3, s3.duration += e3.totalDuration || 0, n.status.failed++) : e3.queue && e3.queue.length ? (t3.queuePush = (t3.queuePush || []).concat(e3.queue), g2[e3.id] = o3) : (d2[e3.id] = o3, s3.count++, s3.lastAt = r3, s3.duration += e3.totalDuration || 0, n.status.out++);
2420
+ const s3 = n.status.destinations[e3.id], i3 = Date.now();
2421
+ e3.error ? (o3.error = e3.error, m2[e3.id] = o3, s3.failed++, s3.lastAt = i3, s3.duration += e3.totalDuration || 0, n.status.failed++) : e3.queue && e3.queue.length ? (t3.queuePush = (t3.queuePush || []).concat(e3.queue), g2[e3.id] = o3) : (d2[e3.id] = o3, s3.count++, s3.lastAt = i3, s3.duration += e3.totalDuration || 0, n.status.out++);
2422
2422
  }
2423
2423
  return N({ event: e2, ...Object.keys(d2).length && { done: d2 }, ...Object.keys(g2).length && { queued: g2 }, ...Object.keys(m2).length && { failed: m2 } });
2424
2424
  }
2425
2425
  async function F(n, e2, t2) {
2426
2426
  if (e2.init && !e2.config.init) {
2427
- const o2 = e2.type || "unknown", s2 = n.logger.scope(o2), r2 = { collector: n, logger: s2, id: t2, config: e2.config, env: L(e2.env, e2.config.env) };
2427
+ const o2 = e2.type || "unknown", s2 = n.logger.scope(o2), i2 = { collector: n, logger: s2, id: t2, config: e2.config, env: L(e2.env, e2.config.env) };
2428
2428
  s2.debug("init");
2429
- const i2 = await w(e2.init, "DestinationInit", n.hooks)(r2);
2430
- if (false === i2) return i2;
2431
- if (e2.config = { ...i2 || e2.config, init: true }, e2.queueOn?.length) {
2429
+ const r2 = await w(e2.init, "DestinationInit", n.hooks)(i2);
2430
+ if (false === r2) return r2;
2431
+ if (e2.config = { ...r2 || e2.config, init: true }, e2.queueOn?.length) {
2432
2432
  const o3 = e2.queueOn;
2433
2433
  e2.queueOn = [];
2434
- for (const { type: s3, data: r3 } of o3) G(n, e2, t2, s3, r3);
2434
+ for (const { type: s3, data: i3 } of o3) B(n, e2, t2, s3, i3);
2435
2435
  }
2436
2436
  s2.debug("init done");
2437
2437
  }
2438
2438
  return true;
2439
2439
  }
2440
- async function J(n, e2, t2, o2, s2, r2) {
2441
- const { config: i2 } = e2, a2 = await p(o2, i2, n);
2440
+ async function J(n, e2, t2, o2, s2, i2) {
2441
+ const { config: r2 } = e2, a2 = await p(o2, r2, n);
2442
2442
  if (a2.ignore) return false;
2443
- const c2 = e2.type || "unknown", f2 = n.logger.scope(c2), l2 = { collector: n, logger: f2, id: t2, config: i2, data: a2.data, rule: a2.mapping, ingest: s2, env: { ...L(e2.env, i2.env), ...r2 ? { respond: r2 } : {} } }, g2 = a2.mapping, m2 = a2.mappingKey || "* *";
2443
+ const c2 = e2.type || "unknown", f2 = n.logger.scope(c2), l2 = { collector: n, logger: f2, id: t2, config: r2, data: a2.data, rule: a2.mapping, ingest: s2, env: { ...L(e2.env, r2.env), ...i2 ? { respond: i2 } : {} } }, g2 = a2.mapping, m2 = a2.mappingKey || "* *";
2444
2444
  if (!g2?.batch || !e2.pushBatch) {
2445
2445
  f2.debug("push", { event: a2.event.name });
2446
2446
  const t3 = await w(e2.push, "DestinationPush", n.hooks)(a2.event, l2);
@@ -2450,7 +2450,7 @@ async function J(n, e2, t2, o2, s2, r2) {
2450
2450
  if (e2.batches = e2.batches || {}, !e2.batches[m2]) {
2451
2451
  const o4 = { key: m2, events: [], data: [] };
2452
2452
  e2.batches[m2] = { batched: o4, batchFn: u(() => {
2453
- const o5 = e2.batches[m2].batched, a3 = { collector: n, logger: f2, id: t2, config: i2, data: void 0, rule: g2, ingest: s2, env: { ...L(e2.env, i2.env), ...r2 ? { respond: r2 } : {} } };
2453
+ const o5 = e2.batches[m2].batched, a3 = { collector: n, logger: f2, id: t2, config: r2, data: void 0, rule: g2, ingest: s2, env: { ...L(e2.env, r2.env), ...i2 ? { respond: i2 } : {} } };
2454
2454
  f2.debug("push batch", { events: o5.events.length }), w(e2.pushBatch, "DestinationPushBatch", n.hooks)(o5, a3), f2.debug("push batch done"), o5.events = [], o5.data = [];
2455
2455
  }, g2.batch) };
2456
2456
  }
@@ -2463,8 +2463,8 @@ function N(n) {
2463
2463
  return { ok: !n?.failed, ...n };
2464
2464
  }
2465
2465
  function W(n) {
2466
- const { code: e2, config: t2 = {}, env: o2 = {} } = n, { config: s2 } = E(n, "before"), r2 = { ...e2.config, ...t2, ...s2 }, i2 = L(e2.env, o2);
2467
- return { ...e2, config: r2, env: i2 };
2466
+ const { code: e2, config: t2 = {}, env: o2 = {} } = n, { config: s2 } = A(n, "before"), i2 = { ...e2.config, ...t2, ...s2 }, r2 = L(e2.env, o2);
2467
+ return { ...e2, config: i2, env: r2 };
2468
2468
  }
2469
2469
  async function z(n, e2 = {}) {
2470
2470
  const t2 = {};
@@ -2474,48 +2474,48 @@ async function z(n, e2 = {}) {
2474
2474
  function L(n, e2) {
2475
2475
  return n || e2 ? e2 ? n && m(n) && m(e2) ? { ...n, ...e2 } : e2 : n : {};
2476
2476
  }
2477
- async function Y(n, e2, t2) {
2477
+ async function X(n, e2, t2) {
2478
2478
  const o2 = Object.entries(n).map(async ([n2, o3]) => {
2479
2479
  const s2 = o3.destroy;
2480
2480
  if (!s2) return;
2481
- const r2 = o3.type || "unknown", i2 = t2.scope(r2), a2 = { id: n2, config: o3.config, env: o3.env ?? {}, logger: i2 };
2481
+ const i2 = o3.type || "unknown", r2 = t2.scope(i2), a2 = { id: n2, config: o3.config, env: o3.env ?? {}, logger: r2 };
2482
2482
  try {
2483
2483
  await Promise.race([s2(a2), new Promise((t3, o4) => setTimeout(() => o4(new Error(`${e2} '${n2}' destroy timed out`)), 5e3))]);
2484
2484
  } catch (t3) {
2485
- i2.error(`${e2} '${n2}' destroy failed: ${t3}`);
2485
+ r2.error(`${e2} '${n2}' destroy failed: ${t3}`);
2486
2486
  }
2487
2487
  });
2488
2488
  await Promise.allSettled(o2);
2489
2489
  }
2490
- async function Z(n, e2, o2, r2) {
2491
- let i2, a2, c2 = false, u2 = false;
2490
+ async function Y(n, e2, o2, i2) {
2491
+ let r2, a2, c2 = false, u2 = false;
2492
2492
  switch (e2) {
2493
2493
  case t.Commands.Config:
2494
- X(o2) && (M(n.config, o2, { shallow: false }), a2 = o2, c2 = true);
2494
+ K(o2) && (M(n.config, o2, { shallow: false }), a2 = o2, c2 = true);
2495
2495
  break;
2496
2496
  case t.Commands.Consent:
2497
- if (X(o2)) {
2497
+ if (K(o2)) {
2498
2498
  const { update: e3, runQueue: t2 } = s(n, o2);
2499
2499
  a2 = e3, c2 = true, u2 = t2;
2500
2500
  }
2501
2501
  break;
2502
2502
  case t.Commands.Custom:
2503
- X(o2) && (n.custom = M(n.custom, o2), a2 = o2, c2 = true);
2503
+ K(o2) && (n.custom = M(n.custom, o2), a2 = o2, c2 = true);
2504
2504
  break;
2505
2505
  case t.Commands.Destination:
2506
- X(o2) && ("code" in o2 && X(o2.code) ? i2 = await U(n, o2, r2) : V(o2.push) && (i2 = await U(n, { code: o2 }, r2)));
2506
+ K(o2) && ("code" in o2 && K(o2.code) ? r2 = await H(n, o2, i2) : V(o2.push) && (r2 = await H(n, { code: o2 }, i2)));
2507
2507
  break;
2508
2508
  case t.Commands.Globals:
2509
- X(o2) && (n.globals = M(n.globals, o2), a2 = o2, c2 = true);
2509
+ K(o2) && (n.globals = M(n.globals, o2), a2 = o2, c2 = true);
2510
2510
  break;
2511
2511
  case t.Commands.On:
2512
- K(o2) && await B(n, o2, r2);
2512
+ _(o2) && await I(n, o2, i2);
2513
2513
  break;
2514
2514
  case t.Commands.Ready:
2515
2515
  c2 = true;
2516
2516
  break;
2517
2517
  case t.Commands.Run:
2518
- i2 = await en(n, o2), c2 = true;
2518
+ r2 = await nn(n, o2), c2 = true;
2519
2519
  break;
2520
2520
  case t.Commands.Session:
2521
2521
  c2 = true;
@@ -2523,71 +2523,71 @@ async function Z(n, e2, o2, r2) {
2523
2523
  case t.Commands.Shutdown:
2524
2524
  await (async function(n2) {
2525
2525
  const e3 = n2.logger;
2526
- await Y(n2.sources, "source", e3), await Y(n2.destinations, "destination", e3), await Y(n2.transformers, "transformer", e3);
2526
+ await X(n2.sources, "source", e3), await X(n2.destinations, "destination", e3), await X(n2.transformers, "transformer", e3);
2527
2527
  })(n);
2528
2528
  break;
2529
2529
  case t.Commands.User:
2530
- X(o2) && (M(n.user, o2, { shallow: false }), a2 = o2, c2 = true);
2530
+ K(o2) && (M(n.user, o2, { shallow: false }), a2 = o2, c2 = true);
2531
2531
  }
2532
- return c2 && await H(n, e2, void 0, a2), u2 && (i2 = await _(n)), i2 || N({ ok: true });
2532
+ return c2 && await G(n, e2, void 0, a2), u2 && (r2 = await U(n)), r2 || N({ ok: true });
2533
2533
  }
2534
- function nn(n, e2) {
2534
+ function Z(n, e2) {
2535
2535
  if (!e2.name) throw new Error("Event name is required");
2536
2536
  const [t2, o2] = e2.name.split(" ");
2537
2537
  if (!t2 || !o2) throw new Error("Event name is invalid");
2538
2538
  ++n.count;
2539
- const { timestamp: s2 = Date.now(), group: r2 = n.group, count: i2 = n.count } = e2, { name: a2 = `${t2} ${o2}`, data: c2 = {}, context: u2 = {}, globals: f2 = n.globals, custom: l2 = {}, user: d2 = n.user, nested: g2 = [], consent: m2 = n.consent, id: p2 = `${s2}-${r2}-${i2}`, trigger: h2 = "", entity: w2 = t2, action: y2 = o2, timing: b2 = 0, version: v2 = { source: n.version, tagging: n.config.tagging || 0 }, source: k2 = { type: "collector", id: "", previous_id: "" } } = e2;
2540
- return { name: a2, data: c2, context: u2, globals: f2, custom: l2, user: d2, nested: g2, consent: m2, id: p2, trigger: h2, entity: w2, action: y2, timestamp: s2, timing: b2, group: r2, count: i2, version: v2, source: k2 };
2539
+ const { timestamp: s2 = Date.now(), group: i2 = n.group, count: r2 = n.count } = e2, { name: a2 = `${t2} ${o2}`, data: c2 = {}, context: u2 = {}, globals: f2 = n.globals, custom: l2 = {}, user: d2 = n.user, nested: g2 = [], consent: m2 = n.consent, id: p2 = `${s2}-${i2}-${r2}`, trigger: h2 = "", entity: w2 = t2, action: y2 = o2, timing: b2 = 0, version: v2 = { source: n.version, tagging: n.config.tagging || 0 }, source: k2 = { type: "collector", id: "", previous_id: "" } } = e2;
2540
+ return { name: a2, data: c2, context: u2, globals: f2, custom: l2, user: d2, nested: g2, consent: m2, id: p2, trigger: h2, entity: w2, action: y2, timestamp: s2, timing: b2, group: i2, count: r2, version: v2, source: k2 };
2541
2541
  }
2542
- async function en(n, e2) {
2542
+ async function nn(n, e2) {
2543
2543
  n.allowed = true, n.count = 0, n.group = Q(), n.timing = Date.now(), e2 && (e2.consent && (n.consent = M(n.consent, e2.consent)), e2.user && (n.user = M(n.user, e2.user)), e2.globals && (n.globals = M(n.config.globalsStatic || {}, e2.globals)), e2.custom && (n.custom = M(n.custom, e2.custom))), Object.values(n.destinations).forEach((n2) => {
2544
2544
  n2.queuePush = [];
2545
2545
  }), n.queue = [], n.round++;
2546
- return await _(n);
2546
+ return await U(n);
2547
2547
  }
2548
- function an(n, e2) {
2549
- return rn(async (t2, o2 = {}) => await sn(async () => {
2550
- const s2 = Date.now(), { id: r2, ingest: i2, respond: a2, mapping: c2, preChain: u2 } = o2;
2548
+ function rn(n, e2) {
2549
+ return sn(async (t2, o2 = {}) => await on(async () => {
2550
+ const s2 = Date.now(), { id: i2, ingest: r2, respond: a2, mapping: c2, preChain: u2 } = o2;
2551
2551
  let f2 = t2;
2552
- const l2 = i2 ? Object.freeze(i2) : void 0;
2552
+ const l2 = r2 ? Object.freeze(r2) : void 0;
2553
2553
  if (c2) {
2554
- const e3 = await on(f2, c2, n);
2554
+ const e3 = await tn(f2, c2, n);
2555
2555
  if (e3.ignore) return N({ ok: true });
2556
2556
  if (c2.consent) {
2557
- if (!tn(c2.consent, n.consent, e3.event.consent)) return N({ ok: true });
2557
+ if (!en(c2.consent, n.consent, e3.event.consent)) return N({ ok: true });
2558
2558
  }
2559
2559
  f2 = e3.event;
2560
2560
  }
2561
2561
  if (u2?.length && n.transformers && Object.keys(n.transformers).length > 0) {
2562
- const e3 = await $(n, n.transformers, u2, f2, l2, a2);
2562
+ const e3 = await S(n, n.transformers, u2, f2, l2, a2);
2563
2563
  if (null === e3) return N({ ok: true });
2564
2564
  f2 = e3;
2565
2565
  }
2566
- const d2 = e2(f2), g2 = nn(n, d2), m2 = await _(n, g2, { id: r2, ingest: l2, respond: a2 });
2567
- if (r2) {
2568
- n.status.sources[r2] || (n.status.sources[r2] = { count: 0, duration: 0 });
2569
- const e3 = n.status.sources[r2];
2566
+ const d2 = e2(f2), g2 = Z(n, d2), m2 = await U(n, g2, { id: i2, ingest: l2, respond: a2 });
2567
+ if (i2) {
2568
+ n.status.sources[i2] || (n.status.sources[i2] = { count: 0, duration: 0 });
2569
+ const e3 = n.status.sources[i2];
2570
2570
  e3.count++, e3.lastAt = Date.now(), e3.duration += Date.now() - s2;
2571
2571
  }
2572
2572
  return m2;
2573
2573
  }, () => N({ ok: false }))(), "Push", n.hooks);
2574
2574
  }
2575
- async function fn(n) {
2576
- const e2 = r({ globalsStatic: {}, sessionStatic: {}, tagging: 0, run: true }, n, { merge: false, extend: false }), t2 = { level: n.logger?.level, handler: n.logger?.handler }, o2 = i(t2), s2 = { ...e2.globalsStatic, ...n.globals }, a2 = { allowed: false, config: e2, consent: n.consent || {}, count: 0, custom: n.custom || {}, destinations: {}, transformers: {}, globals: s2, group: "", hooks: {}, logger: o2, on: {}, queue: [], round: 0, session: void 0, status: { startedAt: Date.now(), in: 0, out: 0, failed: 0, sources: {}, destinations: {} }, timing: Date.now(), user: n.user || {}, version: "2.0.1", sources: {}, pending: { sources: {}, destinations: {} }, push: void 0, command: void 0 };
2577
- return a2.push = an(a2, (n2) => ({ timing: Math.round((Date.now() - a2.timing) / 10) / 100, source: { type: "collector", id: "", previous_id: "" }, ...n2 })), a2.command = (function(n2, e3) {
2578
- return cn(async (t3, o3, s3) => await un(async () => await e3(n2, t3, o3, s3), () => N({ ok: false }))(), "Command", n2.hooks);
2579
- })(a2, Z), a2.destinations = await z(a2, n.destinations || {}), a2.transformers = await (async function(n2, e3 = {}) {
2575
+ async function un(n) {
2576
+ const e2 = i({ globalsStatic: {}, sessionStatic: {}, tagging: 0, run: true }, n, { merge: false, extend: false }), t2 = { level: n.logger?.level, handler: n.logger?.handler }, o2 = r(t2), s2 = { ...e2.globalsStatic, ...n.globals }, a2 = { allowed: false, config: e2, consent: n.consent || {}, count: 0, custom: n.custom || {}, destinations: {}, transformers: {}, globals: s2, group: "", hooks: {}, logger: o2, on: {}, queue: [], round: 0, session: void 0, status: { startedAt: Date.now(), in: 0, out: 0, failed: 0, sources: {}, destinations: {} }, timing: Date.now(), user: n.user || {}, version: "2.1.0", sources: {}, pending: { sources: {}, destinations: {} }, push: void 0, command: void 0 };
2577
+ return a2.push = rn(a2, (n2) => ({ timing: Math.round((Date.now() - a2.timing) / 10) / 100, source: { type: "collector", id: "", previous_id: "" }, ...n2 })), a2.command = (function(n2, e3) {
2578
+ return an(async (t3, o3, s3) => await cn(async () => await e3(n2, t3, o3, s3), () => N({ ok: false }))(), "Command", n2.hooks);
2579
+ })(a2, Y), a2.destinations = await z(a2, n.destinations || {}), a2.transformers = await (async function(n2, e3 = {}) {
2580
2580
  const t3 = {};
2581
2581
  for (const [o3, s3] of Object.entries(e3)) {
2582
- const { code: e4, env: r2 = {} } = s3, { config: i2 } = E(s3, "next"), a3 = n2.logger.scope("transformer").scope(o3), c2 = { collector: n2, logger: a3, id: o3, config: i2, env: r2 }, u2 = await e4(c2);
2582
+ const { code: e4, env: i2 = {} } = s3, { config: r2 } = A(s3, "next"), a3 = n2.logger.scope("transformer").scope(o3), c2 = { collector: n2, logger: a3, id: o3, config: r2, env: i2 }, u2 = await e4(c2);
2583
2583
  t3[o3] = u2;
2584
2584
  }
2585
2585
  return t3;
2586
2586
  })(a2, n.transformers || {}), a2;
2587
2587
  }
2588
- async function ln(n) {
2588
+ async function fn(n) {
2589
2589
  n = n || {};
2590
- const e2 = await fn(n), t2 = (o2 = e2, { type: "elb", config: {}, push: async (n2, e3, t3, s3, r3, i3) => {
2590
+ const e2 = await un(n), t2 = (o2 = e2, { type: "elb", config: {}, push: async (n2, e3, t3, s3, i3, r3) => {
2591
2591
  if ("string" == typeof n2 && n2.startsWith("walker ")) {
2592
2592
  const s4 = n2.replace("walker ", "");
2593
2593
  return o2.command(s4, e3, t3);
@@ -2598,76 +2598,76 @@ async function ln(n) {
2598
2598
  if (!n2 || "object" != typeof n2) return N({ ok: false });
2599
2599
  a3 = n2, e3 && "object" == typeof e3 && !Array.isArray(e3) && (a3.data = { ...a3.data || {}, ...e3 });
2600
2600
  }
2601
- return s3 && "object" == typeof s3 && (a3.context = s3), r3 && Array.isArray(r3) && (a3.nested = r3), i3 && "object" == typeof i3 && (a3.custom = i3), o2.push(a3);
2601
+ return s3 && "object" == typeof s3 && (a3.context = s3), i3 && Array.isArray(i3) && (a3.nested = i3), r3 && "object" == typeof r3 && (a3.custom = r3), o2.push(a3);
2602
2602
  } });
2603
2603
  var o2;
2604
2604
  e2.sources.elb = t2;
2605
- const s2 = await I(e2, n.sources || {});
2605
+ const s2 = await T(e2, n.sources || {});
2606
2606
  Object.assign(e2.sources, s2);
2607
- const { consent: r2, user: i2, globals: a2, custom: c2 } = n;
2608
- r2 && await e2.command("consent", r2), i2 && await e2.command("user", i2), a2 && Object.assign(e2.globals, a2), c2 && Object.assign(e2.custom, c2), e2.config.run && await e2.command("run");
2607
+ const { consent: i2, user: r2, globals: a2, custom: c2 } = n;
2608
+ i2 && await e2.command("consent", i2), r2 && await e2.command("user", r2), a2 && Object.assign(e2.globals, a2), c2 && Object.assign(e2.custom, c2), e2.config.run && await e2.command("run");
2609
2609
  let u2 = t2.push;
2610
2610
  const f2 = Object.values(e2.sources).filter((n2) => "elb" !== n2.type), l2 = f2.find((n2) => n2.config.primary);
2611
2611
  return l2 ? u2 = l2.push : f2.length > 0 && (u2 = f2[0].push), { collector: e2, elb: u2 };
2612
2612
  }
2613
- function dn(n) {
2613
+ function ln(n) {
2614
2614
  if (null === n || "object" != typeof n) return n;
2615
- if (Array.isArray(n)) return n.map(dn);
2615
+ if (Array.isArray(n)) return n.map(ln);
2616
2616
  const e2 = {};
2617
- for (const [t2, o2] of Object.entries(n)) e2[t2] = "function" == typeof o2 ? o2 : dn(o2);
2617
+ for (const [t2, o2] of Object.entries(n)) e2[t2] = "function" == typeof o2 ? o2 : ln(o2);
2618
2618
  return e2;
2619
2619
  }
2620
- function gn(n) {
2621
- const e2 = [], { simulation: t2, ...o2 } = n, s2 = dn(o2);
2620
+ function dn(n) {
2621
+ const e2 = [], { simulation: t2, ...o2 } = n, s2 = ln(o2);
2622
2622
  for (const n2 of t2) {
2623
2623
  const t3 = n2.startsWith("call:") ? n2.slice(5) : n2, o3 = t3.split(".");
2624
- let r2 = s2;
2625
- for (let n3 = 0; n3 < o3.length - 1 && null != r2[o3[n3]]; n3++) r2 = r2[o3[n3]];
2626
- const i2 = o3[o3.length - 1];
2627
- if (null == r2 || !(i2 in r2)) continue;
2628
- const a2 = r2[i2];
2629
- "function" == typeof a2 && (r2[i2] = function(...n3) {
2624
+ let i2 = s2;
2625
+ for (let n3 = 0; n3 < o3.length - 1 && null != i2[o3[n3]]; n3++) i2 = i2[o3[n3]];
2626
+ const r2 = o3[o3.length - 1];
2627
+ if (null == i2 || !(r2 in i2)) continue;
2628
+ const a2 = i2[r2];
2629
+ "function" == typeof a2 && (i2[r2] = function(...n3) {
2630
2630
  return e2.push({ fn: t3, args: n3, ts: Date.now() }), a2.apply(this, n3);
2631
2631
  });
2632
2632
  }
2633
2633
  return { wrappedEnv: s2, calls: e2 };
2634
2634
  }
2635
- async function mn(n) {
2635
+ async function gn(n) {
2636
2636
  const e2 = Date.now();
2637
2637
  try {
2638
2638
  switch (n.step) {
2639
2639
  case "transformer":
2640
2640
  return await (async function(n2, e3) {
2641
- const { code: t2, config: o2 = {}, event: s2 } = n2, { collector: r2 } = await ln({ transformers: { sim: { code: t2, config: o2 } } }), i2 = r2.transformers?.sim;
2642
- if (!i2) throw new Error("Transformer failed to initialize");
2643
- const a2 = await i2.push(s2, { collector: r2, logger: r2.logger.scope("transformer").scope("sim"), id: "sim", config: i2.config, env: i2.config?.env || {} });
2641
+ const { code: t2, config: o2 = {}, event: s2 } = n2, { collector: i2 } = await fn({ transformers: { sim: { code: t2, config: o2 } } }), r2 = i2.transformers?.sim;
2642
+ if (!r2) throw new Error("Transformer failed to initialize");
2643
+ const a2 = await r2.push(s2, { collector: i2, logger: i2.logger.scope("transformer").scope("sim"), id: "sim", config: r2.config, env: r2.config?.env || {} });
2644
2644
  let c2;
2645
- c2 = false === a2 ? [] : null == a2 ? [s2] : [a2];
2645
+ c2 = false === a2 ? [] : null == a2 ? [s2] : [a2.event || s2];
2646
2646
  return { step: "transformer", name: n2.name, events: c2, calls: [], duration: Date.now() - e3 };
2647
2647
  })(n, e2);
2648
2648
  case "source":
2649
2649
  return await (async function(n2, e3) {
2650
- const { code: t2, config: o2 = {}, setup: s2, input: r2, env: i2, consent: a2 } = n2, c2 = { functional: true, marketing: true, analytics: true };
2650
+ const { code: t2, config: o2 = {}, setup: s2, input: i2, env: r2, consent: a2 } = n2, c2 = { functional: true, marketing: true, analytics: true };
2651
2651
  let u2;
2652
2652
  if (s2) {
2653
- const n3 = s2(r2, i2);
2653
+ const n3 = s2(i2, r2);
2654
2654
  "function" == typeof n3 && (u2 = n3);
2655
2655
  }
2656
- const f2 = [], { collector: l2 } = await ln({ consent: a2 || c2, sources: { sim: { code: t2, config: o2, env: i2, next: "spy" } }, transformers: { spy: { code: () => ({ type: "spy", config: {}, push: (n3) => (f2.push(JSON.parse(JSON.stringify(n3))), n3) }) } } });
2656
+ const f2 = [], { collector: l2 } = await fn({ consent: a2 || c2, sources: { sim: { code: t2, config: o2, env: r2, next: "spy" } }, transformers: { spy: { code: () => ({ type: "spy", config: {}, push: (n3) => (f2.push(JSON.parse(JSON.stringify(n3))), { event: n3 }) }) } } });
2657
2657
  u2 && u2();
2658
2658
  return { step: "source", name: n2.name, events: f2, calls: [], duration: Date.now() - e3 };
2659
2659
  })(n, e2);
2660
2660
  case "destination":
2661
2661
  return await (async function(n2, e3) {
2662
- const { code: t2, config: o2 = {}, event: s2, consent: r2, env: i2, track: a2 } = n2, c2 = { functional: true, marketing: true, analytics: true };
2663
- let u2 = [], f2 = i2;
2664
- if (i2 && a2 && a2.length > 0) {
2665
- const n3 = gn({ ...i2, simulation: a2 });
2662
+ const { code: t2, config: o2 = {}, event: s2, consent: i2, env: r2, track: a2 } = n2, c2 = { functional: true, marketing: true, analytics: true };
2663
+ let u2 = [], f2 = r2;
2664
+ if (r2 && a2 && a2.length > 0) {
2665
+ const n3 = dn({ ...r2, simulation: a2 });
2666
2666
  f2 = n3.wrappedEnv, u2 = n3.calls;
2667
2667
  }
2668
2668
  const l2 = { ...o2 };
2669
2669
  f2 && (l2.env = f2);
2670
- const { collector: d2 } = await ln({ consent: r2 || c2, destinations: { sim: { code: t2, config: l2 } } });
2670
+ const { collector: d2 } = await fn({ consent: i2 || c2, destinations: { sim: { code: t2, config: l2 } } });
2671
2671
  return await d2.push(s2), { step: "destination", name: n2.name, events: [], calls: u2, duration: Date.now() - e3 };
2672
2672
  })(n, e2);
2673
2673
  }
@@ -2881,7 +2881,7 @@ async function executeConfigSimulation(_content, configPath, typedEvent, tempDir
2881
2881
  const destinations = flowConfig.destinations;
2882
2882
  const envs = await loadDestinationEnvs(destinations || {});
2883
2883
  const destEnv = envs[step.name];
2884
- const result = await mn({
2884
+ const result = await gn({
2885
2885
  step: "destination",
2886
2886
  name: step.name,
2887
2887
  code,
@@ -2906,7 +2906,7 @@ async function executeConfigSimulation(_content, configPath, typedEvent, tempDir
2906
2906
  }
2907
2907
  const mod = await import(packageName);
2908
2908
  const code = mod.default || Object.values(mod)[0];
2909
- const result = await mn({
2909
+ const result = await gn({
2910
2910
  step: "transformer",
2911
2911
  name: step.name,
2912
2912
  code,
@@ -2978,7 +2978,7 @@ async function simulateSourceCLI(flowConfig, setupInput, options) {
2978
2978
  document: dom.window.document,
2979
2979
  localStorage: dom.window.localStorage
2980
2980
  };
2981
- const result = await mn({
2981
+ const result = await gn({
2982
2982
  step: "source",
2983
2983
  name: options.sourceStep,
2984
2984
  code,