@walkeros/cli 3.3.0 → 3.4.0-next-1776749829492

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
@@ -193,6 +193,33 @@ var init_config_file = __esm({
193
193
  }
194
194
  });
195
195
 
196
+ // src/core/client-context.ts
197
+ function setClientContext(input) {
198
+ const envType = process.env.WALKEROS_CLIENT_TYPE;
199
+ const type = envType ?? input.type ?? "cli";
200
+ context = { type, version: input.version };
201
+ }
202
+ function getClientContext() {
203
+ return context;
204
+ }
205
+ function resetClientContext() {
206
+ context = void 0;
207
+ }
208
+ function clientContextHeaders() {
209
+ if (!context) return {};
210
+ return {
211
+ "User-Agent": `walkeros-${context.type}/${context.version}`,
212
+ "X-WalkerOS-Client": context.type,
213
+ "X-WalkerOS-Client-Version": context.version
214
+ };
215
+ }
216
+ var context;
217
+ var init_client_context = __esm({
218
+ "src/core/client-context.ts"() {
219
+ "use strict";
220
+ }
221
+ });
222
+
196
223
  // src/core/http.ts
197
224
  function normalizeHeaders(headers) {
198
225
  if (!headers) return {};
@@ -205,17 +232,29 @@ function mergeAuthHeaders(token, headers) {
205
232
  if (token) normalized.Authorization = `Bearer ${token}`;
206
233
  return normalized;
207
234
  }
235
+ function buildHeaders(token, headers) {
236
+ return {
237
+ ...clientContextHeaders(),
238
+ ...mergeAuthHeaders(token, headers)
239
+ };
240
+ }
208
241
  async function apiFetch(path19, init) {
209
242
  const baseUrl = resolveAppUrl();
210
243
  const token = resolveToken()?.token;
211
244
  return fetch(`${baseUrl}${path19}`, {
212
245
  ...init,
213
- headers: mergeAuthHeaders(token, init?.headers)
246
+ headers: buildHeaders(token, init?.headers)
214
247
  });
215
248
  }
216
249
  async function publicFetch(path19, init) {
217
250
  const baseUrl = resolveAppUrl();
218
- return fetch(`${baseUrl}${path19}`, init);
251
+ return fetch(`${baseUrl}${path19}`, {
252
+ ...init,
253
+ headers: {
254
+ ...clientContextHeaders(),
255
+ ...normalizeHeaders(init?.headers)
256
+ }
257
+ });
219
258
  }
220
259
  async function deployFetch(path19, init) {
221
260
  const baseUrl = resolveAppUrl();
@@ -226,13 +265,14 @@ async function deployFetch(path19, init) {
226
265
  );
227
266
  return fetch(`${baseUrl}${path19}`, {
228
267
  ...init,
229
- headers: mergeAuthHeaders(token, init?.headers)
268
+ headers: buildHeaders(token, init?.headers)
230
269
  });
231
270
  }
232
271
  var init_http = __esm({
233
272
  "src/core/http.ts"() {
234
273
  "use strict";
235
274
  init_config_file();
275
+ init_client_context();
236
276
  }
237
277
  });
238
278
 
@@ -1741,7 +1781,8 @@ ${dataDeclaration}`;
1741
1781
  } else {
1742
1782
  const stage2Entry = (buildOptions.platform || "node") === "browser" ? generateWebEntry(stage1Path, dataPayload, {
1743
1783
  windowCollector: buildOptions.windowCollector,
1744
- windowElb: buildOptions.windowElb
1784
+ windowElb: buildOptions.windowElb,
1785
+ platform: buildOptions.platform
1745
1786
  }) : generateServerEntry(stage1Path, dataPayload);
1746
1787
  const stage2EntryPath = path10.join(TEMP_DIR, "stage2.mjs");
1747
1788
  await fs9.writeFile(stage2EntryPath, stage2Entry);
@@ -2131,6 +2172,7 @@ async function createEntryPoint(flowSettings, buildOptions, packagePaths) {
2131
2172
  validateComponentNames(flowWithSections.transformers, "transformers");
2132
2173
  if (flowWithSections.stores)
2133
2174
  validateComponentNames(flowWithSections.stores, "stores");
2175
+ const withDev = buildOptions.withDev !== void 0 ? buildOptions.withDev === true : buildOptions.skipWrapper === true;
2134
2176
  const { importStatements, devExportEntries } = await generateImportStatements(
2135
2177
  buildOptions.packages,
2136
2178
  destinationPackages,
@@ -2139,7 +2181,7 @@ async function createEntryPoint(flowSettings, buildOptions, packagePaths) {
2139
2181
  storePackages,
2140
2182
  explicitCodeImports,
2141
2183
  packagePaths,
2142
- buildOptions.skipWrapper === true
2184
+ withDev
2143
2185
  );
2144
2186
  const importsCode = importStatements.join("\n");
2145
2187
  const hasFlow = Object.values(flowSettings.sources || {}).some(
@@ -2408,12 +2450,24 @@ function generateWebEntry(stage1Path, dataPayload, options = {}) {
2408
2450
  );
2409
2451
  }
2410
2452
  const assignmentCode = assignments.length > 0 ? "\n" + assignments.join("\n") : "";
2453
+ const platform = options.platform ?? "browser";
2454
+ const envBlock = platform === "browser" ? `
2455
+ if (config.sources) {
2456
+ for (const key of Object.keys(config.sources)) {
2457
+ const source = config.sources[key];
2458
+ if (!source) continue;
2459
+ const env = source.env ?? (source.env = {});
2460
+ env.window = env.window ?? (typeof window !== 'undefined' ? window : undefined);
2461
+ env.document = env.document ?? (typeof document !== 'undefined' ? document : undefined);
2462
+ }
2463
+ }` : "";
2411
2464
  return `import { startFlow, wireConfig } from '${stage1Path}';
2412
2465
 
2413
2466
  const __configData = ${dataPayload};
2414
2467
 
2415
2468
  (async () => {
2416
- const { collector, elb } = await startFlow(wireConfig(__configData));${assignmentCode}
2469
+ const config = wireConfig(__configData);${envBlock}
2470
+ const { collector, elb } = await startFlow(config);${assignmentCode}
2417
2471
  })();`;
2418
2472
  }
2419
2473
  function generateWrapEntry(stage1Path, options = {}) {
@@ -2459,10 +2513,22 @@ function generateWrapEntry(stage1Path, options = {}) {
2459
2513
  }
2460
2514
  // --- End preview mode preflight ---
2461
2515
  ` : "";
2516
+ const platform = options.platform ?? "browser";
2517
+ const envBlock = platform === "browser" ? `
2518
+ if (config.sources) {
2519
+ for (const key of Object.keys(config.sources)) {
2520
+ const source = config.sources[key];
2521
+ if (!source) continue;
2522
+ const env = source.env ?? (source.env = {});
2523
+ env.window = env.window ?? (typeof window !== 'undefined' ? window : undefined);
2524
+ env.document = env.document ?? (typeof document !== 'undefined' ? document : undefined);
2525
+ }
2526
+ }` : "";
2462
2527
  return `import { startFlow, wireConfig, __configData } from '${stage1Path}';
2463
2528
 
2464
2529
  (async () => {${preflightBlock}
2465
- const { collector, elb } = await startFlow(wireConfig(__configData));${assignmentCode}
2530
+ const config = wireConfig(__configData);${envBlock}
2531
+ const { collector, elb } = await startFlow(config);${assignmentCode}
2466
2532
  })();`;
2467
2533
  }
2468
2534
  function generateWrapEntryServer(stage1Path) {
@@ -2568,6 +2634,55 @@ var init_bundler = __esm({
2568
2634
  }
2569
2635
  });
2570
2636
 
2637
+ // src/commands/bundle/targets.ts
2638
+ function resolveTarget(target) {
2639
+ const preset = BUNDLE_TARGETS[target];
2640
+ if (!preset) {
2641
+ throw new Error(
2642
+ `Unknown target: ${target}. Valid: ${Object.keys(BUNDLE_TARGETS).join(", ")}`
2643
+ );
2644
+ }
2645
+ return preset;
2646
+ }
2647
+ var BUNDLE_TARGETS;
2648
+ var init_targets = __esm({
2649
+ "src/commands/bundle/targets.ts"() {
2650
+ "use strict";
2651
+ BUNDLE_TARGETS = Object.freeze({
2652
+ cdn: Object.freeze({
2653
+ skipWrapper: false,
2654
+ withDev: false,
2655
+ platform: "browser",
2656
+ injectEnv: true
2657
+ }),
2658
+ "cdn-skeleton": Object.freeze({
2659
+ skipWrapper: true,
2660
+ withDev: false,
2661
+ platform: "browser",
2662
+ injectEnv: false
2663
+ }),
2664
+ runner: Object.freeze({
2665
+ skipWrapper: true,
2666
+ withDev: false,
2667
+ platform: "node",
2668
+ injectEnv: false
2669
+ }),
2670
+ simulate: Object.freeze({
2671
+ skipWrapper: true,
2672
+ withDev: true,
2673
+ platform: "node",
2674
+ injectEnv: false
2675
+ }),
2676
+ push: Object.freeze({
2677
+ skipWrapper: true,
2678
+ withDev: true,
2679
+ platform: "node",
2680
+ injectEnv: false
2681
+ })
2682
+ });
2683
+ }
2684
+ });
2685
+
2571
2686
  // src/commands/bundle/upload.ts
2572
2687
  import fs10 from "fs-extra";
2573
2688
  function sanitizeUrl(url) {
@@ -2640,7 +2755,8 @@ function createApiClient() {
2640
2755
  baseUrl: resolveAppUrl(),
2641
2756
  headers: {
2642
2757
  Authorization: `Bearer ${token}`,
2643
- "Content-Type": "application/json"
2758
+ "Content-Type": "application/json",
2759
+ ...clientContextHeaders()
2644
2760
  }
2645
2761
  });
2646
2762
  }
@@ -2649,6 +2765,7 @@ var init_api_client = __esm({
2649
2765
  "use strict";
2650
2766
  init_auth();
2651
2767
  init_config_file();
2768
+ init_client_context();
2652
2769
  }
2653
2770
  });
2654
2771
 
@@ -2868,6 +2985,20 @@ Build Summary: ${successCount}/${results.length} succeeded`
2868
2985
  }
2869
2986
  }
2870
2987
  async function bundle(configOrPath, options = {}) {
2988
+ let effectiveTarget;
2989
+ if (options.target) {
2990
+ effectiveTarget = options.target;
2991
+ } else if (options.buildOverrides?.skipWrapper === true) {
2992
+ effectiveTarget = "simulate";
2993
+ } else {
2994
+ effectiveTarget = "cdn";
2995
+ }
2996
+ const preset = resolveTarget(effectiveTarget);
2997
+ if (options.buildOverrides?.skipWrapper !== void 0 && !options.target && process.env.WALKEROS_SUPPRESS_DEPRECATIONS !== "1") {
2998
+ console.warn(
2999
+ "[@walkeros/cli] buildOverrides.skipWrapper is deprecated. Pass `target: 'cdn' | 'cdn-skeleton' | 'runner' | 'simulate' | 'push'` instead. Set WALKEROS_SUPPRESS_DEPRECATIONS=1 to silence this warning."
3000
+ );
3001
+ }
2871
3002
  let rawConfig;
2872
3003
  let configPath = path12.resolve(process.cwd(), "walkeros.config.json");
2873
3004
  if (typeof configOrPath === "string") {
@@ -2876,10 +3007,15 @@ async function bundle(configOrPath, options = {}) {
2876
3007
  } else {
2877
3008
  rawConfig = configOrPath;
2878
3009
  }
3010
+ const mergedOverrides = {
3011
+ ...options.buildOverrides ?? {},
3012
+ skipWrapper: preset.skipWrapper,
3013
+ withDev: preset.withDev
3014
+ };
2879
3015
  const { flowSettings, buildOptions } = loadBundleConfig(rawConfig, {
2880
3016
  configPath,
2881
3017
  flowName: options.flowName,
2882
- buildOverrides: options.buildOverrides
3018
+ buildOverrides: mergedOverrides
2883
3019
  });
2884
3020
  if (options.cache !== void 0) {
2885
3021
  buildOptions.cache = options.cache;
@@ -2918,6 +3054,7 @@ var init_bundle = __esm({
2918
3054
  init_config();
2919
3055
  init_utils();
2920
3056
  init_bundler();
3057
+ init_targets();
2921
3058
  init_upload();
2922
3059
  init_stats();
2923
3060
  init_api_client();
@@ -3035,16 +3172,16 @@ import {
3035
3172
  // ../collector/dist/index.mjs
3036
3173
  import { assign as o } from "@walkeros/core";
3037
3174
  import { assign as r, createLogger as i } from "@walkeros/core";
3038
- import { assign as a, buildCacheContext as c, clone as u, compileCache as f, checkCache as l, storeCache as d, compileNext as g, createIngest as p, debounce as m, getId as h, getGrantedConsent as y, isDefined as v, isFunction as b, isObject as w, isRouteArray as k, processEventMapping as C, resolveNext as O, tryCatchAsync as j, useHooks as A } from "@walkeros/core";
3039
- import { isArray as x } from "@walkeros/core";
3175
+ import { assign as a, buildCacheContext as c, clone as u, compileCache as f, checkCache as l, storeCache as d, compileNext as g, createIngest as m, debounce as p, getId as h, getGrantedConsent as y, isDefined as v, isFunction as b, isObject as k, isRouteArray as w, processEventMapping as C, resolveNext as O, tryCatchAsync as j, useHooks as x } from "@walkeros/core";
3176
+ import { isArray as A } from "@walkeros/core";
3040
3177
  import { tryCatch as q, tryCatchAsync as S } from "@walkeros/core";
3041
3178
  import { createIngest as $, getMappingValue as D, tryCatchAsync as _, compileNext as I, resolveNext as P, isRouteArray as E, compileCache as M, checkCache as R, storeCache as H, applyUpdate as T, buildCacheContext as G } from "@walkeros/core";
3042
- import { createIngest as N, isObject as B, tryCatchAsync as U, useHooks as F, compileNext as W, resolveNext as L, isRouteArray as V, compileCache as z, checkCache as J, storeCache as K, buildCacheContext as Q } from "@walkeros/core";
3043
- import { assign as be, getId as we, isFunction as ke, isString as Ce } from "@walkeros/core";
3044
- import { isObject as Oe } from "@walkeros/core";
3045
- import { createIngest as Se, getGrantedConsent as $e, processEventMapping as De, tryCatchAsync as _e, useHooks as Ie } from "@walkeros/core";
3046
- import { useHooks as Ee, tryCatchAsync as Me } from "@walkeros/core";
3047
- import { useHooks as Re } from "@walkeros/core";
3179
+ import { createIngest as N, isObject as U, tryCatchAsync as B, useHooks as F, compileNext as W, resolveNext as z, isRouteArray as L, compileCache as V, checkCache as J, storeCache as K, buildCacheContext as Q } from "@walkeros/core";
3180
+ import { assign as ke, getId as we, isFunction as Ce, isString as Oe } from "@walkeros/core";
3181
+ import { isObject as je } from "@walkeros/core";
3182
+ import { createIngest as $e, getGrantedConsent as De, processEventMapping as _e, tryCatchAsync as Ie, useHooks as Pe } from "@walkeros/core";
3183
+ import { useHooks as Me, tryCatchAsync as Re } from "@walkeros/core";
3184
+ import { useHooks as He } from "@walkeros/core";
3048
3185
  function X(e, n) {
3049
3186
  return e.storeId && n.stores[e.storeId] ? n.stores[e.storeId] : n.stores.__cache;
3050
3187
  }
@@ -3052,7 +3189,7 @@ function Y(e) {
3052
3189
  const n = {};
3053
3190
  for (const [t, o2] of Object.entries(e)) {
3054
3191
  const e2 = o2.config?.next;
3055
- e2 && !V(e2) ? n[t] = { next: e2 } : n[t] = {};
3192
+ e2 && !L(e2) ? n[t] = { next: e2 } : n[t] = {};
3056
3193
  }
3057
3194
  return n;
3058
3195
  }
@@ -3099,7 +3236,7 @@ async function oe(e, n, t, o2, s, r2, i2) {
3099
3236
  }
3100
3237
  if (s && s._meta && s._meta.path.length > 256) return e.logger.error(`Max path length exceeded at ${o3}`), { event: null, respond: c2 };
3101
3238
  s && s._meta && (s._meta.hops++, s._meta.path.push(o3));
3102
- if (!await U(ne)(e, r3, o3)) return e.logger.error(`Transformer init failed: ${o3}`), { event: null, respond: c2 };
3239
+ if (!await B(ne)(e, r3, o3)) return e.logger.error(`Transformer init failed: ${o3}`), { event: null, respond: c2 };
3103
3240
  if (i2 && void 0 !== r3.config?.chainMocks?.[i2]) {
3104
3241
  const n2 = r3.config.chainMocks[i2];
3105
3242
  e.logger.scope(`transformer:${r3.type || "unknown"}`).debug("chainMock", { chain: i2 }), a2 = n2;
@@ -3110,7 +3247,7 @@ async function oe(e, n, t, o2, s, r2, i2) {
3110
3247
  continue;
3111
3248
  }
3112
3249
  if (r3.config?.disabled) continue;
3113
- const u2 = r3.config?.cache, f2 = u2 ? z(u2) : void 0, l2 = f2 ? X(f2, e) : void 0;
3250
+ const u2 = r3.config?.cache, f2 = u2 ? V(u2) : void 0, l2 = f2 ? X(f2, e) : void 0;
3114
3251
  let d2;
3115
3252
  if (f2 && l2) {
3116
3253
  const e2 = Q(s, a2), n2 = J(f2, l2, e2, `t:${o3}`);
@@ -3122,23 +3259,23 @@ async function oe(e, n, t, o2, s, r2, i2) {
3122
3259
  }
3123
3260
  const g2 = r3.config.before;
3124
3261
  if (g2) {
3125
- const t2 = ee("string" == typeof g2 || Array.isArray(g2) && !V(g2) ? g2 : L(W(g2), Q(s, a2)) || void 0, Y(n));
3262
+ const t2 = ee("string" == typeof g2 || Array.isArray(g2) && !L(g2) ? g2 : z(W(g2), Q(s, a2)) || void 0, Y(n));
3126
3263
  if (t2.length > 0) {
3127
3264
  const o4 = await oe(e, n, t2, a2, s, c2, i2);
3128
3265
  if (null === o4.event) return { event: null, respond: o4.respond ?? c2 };
3129
3266
  o4.respond && (c2 = o4.respond), a2 = Array.isArray(o4.event) ? o4.event[0] : o4.event;
3130
3267
  }
3131
3268
  }
3132
- const p2 = await U(te, (n2) => (e.logger.scope(`transformer:${r3.type || "unknown"}`).error("Push failed", { error: n2 }), false))(e, r3, o3, a2, s, c2);
3133
- if (false === p2) return { event: null, respond: c2 };
3134
- if (Array.isArray(p2)) {
3135
- const r4 = t.slice(t.indexOf(o3) + 1), u3 = await Promise.all(p2.map(async (t2) => {
3269
+ const m2 = await B(te, (n2) => (e.logger.scope(`transformer:${r3.type || "unknown"}`).error("Push failed", { error: n2 }), false))(e, r3, o3, a2, s, c2);
3270
+ if (false === m2) return { event: null, respond: c2 };
3271
+ if (Array.isArray(m2)) {
3272
+ const r4 = t.slice(t.indexOf(o3) + 1), u3 = await Promise.all(m2.map(async (t2) => {
3136
3273
  const o4 = t2.event || a2, u4 = s ? { ...s, _meta: { ...s._meta, path: [...s._meta.path] } } : N("unknown");
3137
3274
  if (t2.next) {
3138
3275
  let s2 = t2.next;
3139
- if (V(t2.next)) {
3276
+ if (L(t2.next)) {
3140
3277
  const e2 = W(t2.next);
3141
- s2 = L(e2, Q(u4, o4));
3278
+ s2 = z(e2, Q(u4, o4));
3142
3279
  }
3143
3280
  if (s2) {
3144
3281
  const t3 = ee(s2, Y(n));
@@ -3157,13 +3294,13 @@ async function oe(e, n, t, o2, s, r2, i2) {
3157
3294
  } else l3.push(e2);
3158
3295
  return 0 === l3.length ? { event: null, respond: f3 } : 1 === l3.length ? { event: l3[0], respond: f3 } : { event: l3, respond: f3 };
3159
3296
  }
3160
- if (p2 && "object" == typeof p2) {
3161
- const { event: t2, respond: o4, next: r4 } = p2;
3297
+ if (m2 && "object" == typeof m2) {
3298
+ const { event: t2, respond: o4, next: r4 } = m2;
3162
3299
  if (o4 && (c2 = o4), r4) {
3163
3300
  let o5 = r4;
3164
- if (V(r4)) {
3301
+ if (L(r4)) {
3165
3302
  const e2 = W(r4);
3166
- if (o5 = L(e2, Q(s, a2)), !o5) {
3303
+ if (o5 = z(e2, Q(s, a2)), !o5) {
3167
3304
  t2 && (a2 = t2);
3168
3305
  continue;
3169
3306
  }
@@ -3173,8 +3310,8 @@ async function oe(e, n, t, o2, s, r2, i2) {
3173
3310
  }
3174
3311
  t2 && (a2 = t2);
3175
3312
  }
3176
- if (d2 && l2 && K(l2, d2.key, a2, d2.ttl), (!p2 || "object" == typeof p2 && !p2.next) && r3.config.next && V(r3.config.next)) {
3177
- const t2 = r3.config.next, o4 = W(t2), u3 = L(o4, Q(s, a2));
3313
+ if (d2 && l2 && K(l2, d2.key, a2, d2.ttl), (!m2 || "object" == typeof m2 && !m2.next) && r3.config.next && L(r3.config.next)) {
3314
+ const t2 = r3.config.next, o4 = W(t2), u3 = z(o4, Q(s, a2));
3178
3315
  if (u3) {
3179
3316
  const t3 = ee(u3, Y(n));
3180
3317
  if (t3.length > 0) return oe(e, n, t3, a2, s, c2, i2);
@@ -3185,17 +3322,17 @@ async function oe(e, n, t, o2, s, r2, i2) {
3185
3322
  return { event: a2, respond: c2 };
3186
3323
  }
3187
3324
  function se(e) {
3188
- return e && B(e) ? e : {};
3325
+ return e && U(e) ? e : {};
3189
3326
  }
3190
- function Ge(e) {
3327
+ function Ne(e) {
3191
3328
  if (null === e || "object" != typeof e) return e;
3192
- if (Array.isArray(e)) return e.map(Ge);
3329
+ if (Array.isArray(e)) return e.map(Ne);
3193
3330
  const n = {};
3194
- for (const [t, o2] of Object.entries(e)) n[t] = "function" == typeof o2 ? o2 : Ge(o2);
3331
+ for (const [t, o2] of Object.entries(e)) n[t] = "function" == typeof o2 ? o2 : Ne(o2);
3195
3332
  return n;
3196
3333
  }
3197
- function Ne(e) {
3198
- const n = [], { simulation: t, ...o2 } = e, s = Ge(o2);
3334
+ function Ue(e) {
3335
+ const n = [], { simulation: t, ...o2 } = e, s = Ne(o2);
3199
3336
  for (const e2 of t) {
3200
3337
  const t2 = e2.startsWith("call:") ? e2.slice(5) : e2, o3 = t2.split(".");
3201
3338
  let r2 = s;
@@ -3373,6 +3510,7 @@ function applyOverrides(config, overrides) {
3373
3510
  }
3374
3511
  }
3375
3512
  }
3513
+ config.run = true;
3376
3514
  if (overrides.transformerMocks) {
3377
3515
  const transformers = config.transformers;
3378
3516
  if (transformers) {
@@ -4326,7 +4464,7 @@ async function simulateDestination(configOrPath, event, options) {
4326
4464
  ...devEnv.push,
4327
4465
  simulation: devEnv.simulation
4328
4466
  };
4329
- const { wrappedEnv, calls } = Ne(combined);
4467
+ const { wrappedEnv, calls } = Ue(combined);
4330
4468
  if (destConfig) destConfig.env = wrappedEnv;
4331
4469
  trackedCalls = calls;
4332
4470
  }
@@ -4644,7 +4782,7 @@ import { resolve as resolve2, dirname as dirname2 } from "path";
4644
4782
  // src/runtime/load-bundle.ts
4645
4783
  import { resolve } from "path";
4646
4784
  import { pathToFileURL as pathToFileURL2 } from "url";
4647
- async function loadBundle(file, context, logger) {
4785
+ async function loadBundle(file, context2, logger) {
4648
4786
  const absolutePath = resolve(file);
4649
4787
  const fileUrl = pathToFileURL2(absolutePath).href;
4650
4788
  logger?.debug?.(`Importing bundle: ${absolutePath}`);
@@ -4655,7 +4793,7 @@ async function loadBundle(file, context, logger) {
4655
4793
  );
4656
4794
  }
4657
4795
  logger?.debug?.("Calling factory function...");
4658
- const result = await module.default(context ?? {});
4796
+ const result = await module.default(context2 ?? {});
4659
4797
  if (!result || !result.collector || typeof result.collector.push !== "function") {
4660
4798
  throw new Error(
4661
4799
  `Invalid bundle: factory must return { collector } with a push function`
@@ -5651,7 +5789,7 @@ function buildConnectionGraph(config) {
5651
5789
  return connections;
5652
5790
  }
5653
5791
  function checkCompatibility(conn, errors, warnings) {
5654
- const fromOuts = Object.entries(conn.from.examples).filter(([, ex]) => ex.out !== void 0 && ex.out !== false).map(([name, ex]) => ({ name, value: ex.out }));
5792
+ const fromOuts = Object.entries(conn.from.examples).filter(([, ex]) => ex.out !== void 0 && ex.out.length > 0).map(([name, ex]) => ({ name, value: ex.out }));
5655
5793
  const toIns = Object.entries(conn.to.examples).filter(([, ex]) => ex.in !== void 0).map(([name, ex]) => ({ name, value: ex.in }));
5656
5794
  const path19 = `${conn.from.type}.${conn.from.name} \u2192 ${conn.to.type}.${conn.to.name}`;
5657
5795
  if (fromOuts.length === 0 || toIns.length === 0) {
@@ -6124,6 +6262,63 @@ async function logoutCommand(options) {
6124
6262
 
6125
6263
  // src/commands/auth/index.ts
6126
6264
  init_api_client();
6265
+
6266
+ // src/core/api-error.ts
6267
+ var ApiError = class extends Error {
6268
+ code;
6269
+ details;
6270
+ // Populated only for CLIENT_OUTDATED responses (HTTP 426).
6271
+ minVersion;
6272
+ clientVersion;
6273
+ client;
6274
+ upgrade;
6275
+ docs;
6276
+ constructor(message, options) {
6277
+ super(message);
6278
+ this.name = "ApiError";
6279
+ this.code = options?.code;
6280
+ this.details = options?.details;
6281
+ this.minVersion = options?.minVersion;
6282
+ this.clientVersion = options?.clientVersion;
6283
+ this.client = options?.client;
6284
+ this.upgrade = options?.upgrade;
6285
+ this.docs = options?.docs;
6286
+ }
6287
+ };
6288
+ function throwApiError(error, fallbackMessage) {
6289
+ if (error && typeof error === "object" && "error" in error && typeof error.error === "object") {
6290
+ const inner = error.error;
6291
+ const message = inner.message || fallbackMessage;
6292
+ const code = inner.code;
6293
+ const details = inner.details?.errors;
6294
+ const options = { code, details };
6295
+ if (code === "CLIENT_OUTDATED") {
6296
+ options.minVersion = inner.minVersion;
6297
+ options.clientVersion = inner.clientVersion;
6298
+ options.client = inner.client;
6299
+ options.upgrade = inner.upgrade;
6300
+ options.docs = inner.docs;
6301
+ }
6302
+ throw new ApiError(message, options);
6303
+ }
6304
+ throw new ApiError(fallbackMessage);
6305
+ }
6306
+ function handleCliError(err) {
6307
+ if (err instanceof ApiError && err.code === "CLIENT_OUTDATED") {
6308
+ console.error(`
6309
+ ${err.message}
6310
+ `);
6311
+ if (err.upgrade) console.error(` Upgrade: ${err.upgrade}`);
6312
+ if (err.docs) console.error(` Docs: ${err.docs}
6313
+ `);
6314
+ process.exit(2);
6315
+ }
6316
+ const message = err instanceof Error ? err.message : String(err);
6317
+ console.error(message);
6318
+ process.exit(1);
6319
+ }
6320
+
6321
+ // src/commands/auth/index.ts
6127
6322
  init_cli_logger();
6128
6323
  init_output();
6129
6324
  async function whoami() {
@@ -6145,15 +6340,13 @@ async function whoamiCommand(options) {
6145
6340
  if (data.projectId) logger.info(`Project: ${data.projectId}`);
6146
6341
  }
6147
6342
  } catch (error) {
6148
- logger.error(error instanceof Error ? error.message : String(error));
6149
- process.exit(1);
6343
+ handleCliError(error);
6150
6344
  }
6151
6345
  }
6152
6346
 
6153
6347
  // src/commands/projects/index.ts
6154
6348
  init_api_client();
6155
6349
  init_auth();
6156
- init_cli_logger();
6157
6350
  init_output();
6158
6351
  async function listProjects() {
6159
6352
  const client = createApiClient();
@@ -6201,13 +6394,11 @@ async function deleteProject(options = {}) {
6201
6394
  return data ?? { success: true };
6202
6395
  }
6203
6396
  async function handleResult(fn, options) {
6204
- const logger = createCLILogger(options);
6205
6397
  try {
6206
6398
  const result = await fn();
6207
6399
  await writeResult(JSON.stringify(result, null, 2), options);
6208
6400
  } catch (error) {
6209
- logger.error(error instanceof Error ? error.message : String(error));
6210
- process.exit(1);
6401
+ handleCliError(error);
6211
6402
  }
6212
6403
  }
6213
6404
  async function listProjectsCommand(options) {
@@ -6244,32 +6435,7 @@ async function deleteProjectCommand(projectId, options) {
6244
6435
 
6245
6436
  // src/commands/flows/index.ts
6246
6437
  init_api_client();
6247
-
6248
- // src/core/api-error.ts
6249
- var ApiError = class extends Error {
6250
- code;
6251
- details;
6252
- constructor(message, options) {
6253
- super(message);
6254
- this.name = "ApiError";
6255
- this.code = options?.code;
6256
- this.details = options?.details;
6257
- }
6258
- };
6259
- function throwApiError(error, fallbackMessage) {
6260
- if (error && typeof error === "object" && "error" in error && typeof error.error === "object") {
6261
- const inner = error.error;
6262
- const message = inner.message || fallbackMessage;
6263
- const code = inner.code;
6264
- const details = inner.details?.errors;
6265
- throw new ApiError(message, { code, details });
6266
- }
6267
- throw new ApiError(fallbackMessage);
6268
- }
6269
-
6270
- // src/commands/flows/index.ts
6271
6438
  init_auth();
6272
- init_cli_logger();
6273
6439
  init_output();
6274
6440
  init_stdin();
6275
6441
  async function listFlows(options = {}) {
@@ -6360,13 +6526,11 @@ async function duplicateFlow(options) {
6360
6526
  return data;
6361
6527
  }
6362
6528
  async function handleResult2(fn, options) {
6363
- const logger = createCLILogger(options);
6364
6529
  try {
6365
6530
  const result = await fn();
6366
6531
  await writeResult(JSON.stringify(result, null, 2), options);
6367
6532
  } catch (error) {
6368
- logger.error(error instanceof Error ? error.message : String(error));
6369
- process.exit(1);
6533
+ handleCliError(error);
6370
6534
  }
6371
6535
  }
6372
6536
  async function listFlowsCommand(options) {
@@ -6634,8 +6798,7 @@ async function deployCommand(flowId, options) {
6634
6798
  log.info(`Status: ${r2.status}`);
6635
6799
  }
6636
6800
  } catch (err) {
6637
- log.error(err instanceof Error ? err.message : "Deploy failed");
6638
- process.exit(1);
6801
+ handleCliError(err);
6639
6802
  }
6640
6803
  }
6641
6804
  async function getDeploymentCommand(flowId, options) {
@@ -6662,8 +6825,7 @@ async function getDeploymentCommand(flowId, options) {
6662
6825
  if (r2.publicUrl) log.info(`URL: ${r2.publicUrl}`);
6663
6826
  if (r2.errorMessage) log.error(`Error: ${r2.errorMessage}`);
6664
6827
  } catch (err) {
6665
- log.error(err instanceof Error ? err.message : "Failed to get deployment");
6666
- process.exit(1);
6828
+ handleCliError(err);
6667
6829
  }
6668
6830
  }
6669
6831
 
@@ -6727,13 +6889,11 @@ async function deleteDeployment(options) {
6727
6889
  return data ?? { success: true };
6728
6890
  }
6729
6891
  async function handleResult3(fn, options) {
6730
- const logger = createCLILogger(options);
6731
6892
  try {
6732
6893
  const result = await fn();
6733
6894
  await writeResult(JSON.stringify(result, null, 2), options);
6734
6895
  } catch (error) {
6735
- logger.error(error instanceof Error ? error.message : String(error));
6736
- process.exit(1);
6896
+ handleCliError(error);
6737
6897
  }
6738
6898
  }
6739
6899
  async function listDeploymentsCommand(options) {
@@ -6835,18 +6995,15 @@ async function createDeployCommand(config, options) {
6835
6995
  log.info(" -e WALKEROS_APP_URL=https://app.walkeros.io \\");
6836
6996
  log.info(" walkeros/flow:latest");
6837
6997
  } catch (err) {
6838
- log.error(
6839
- err instanceof Error ? err.message : "Failed to create deployment"
6840
- );
6841
- process.exit(1);
6998
+ handleCliError(err);
6842
6999
  }
6843
7000
  }
6844
7001
 
6845
7002
  // src/commands/feedback/index.ts
6846
7003
  init_config_file();
6847
7004
  init_http();
6848
- init_cli_logger();
6849
7005
  import { createInterface } from "readline";
7006
+ init_cli_logger();
6850
7007
  async function feedback(text, options) {
6851
7008
  const config = readConfig();
6852
7009
  const anonymous = options?.anonymous ?? config?.anonymousFeedback ?? true;
@@ -6899,8 +7056,7 @@ async function feedbackCommand(text) {
6899
7056
  await feedback(text, { anonymous });
6900
7057
  logger.info("Feedback sent. Thanks!");
6901
7058
  } catch (error) {
6902
- logger.error(error instanceof Error ? error.message : String(error));
6903
- process.exit(1);
7059
+ handleCliError(error);
6904
7060
  }
6905
7061
  }
6906
7062
  function promptUser(question) {
@@ -6954,7 +7110,8 @@ async function wrapSkeleton(options) {
6954
7110
  ...windowCollector ? { windowCollector } : {},
6955
7111
  ...windowElb ? { windowElb } : {},
6956
7112
  ...options.previewOrigin ? { previewOrigin: options.previewOrigin } : {},
6957
- ...options.previewScope ? { previewScope: options.previewScope } : {}
7113
+ ...options.previewScope ? { previewScope: options.previewScope } : {},
7114
+ platform
6958
7115
  }) : generateWrapEntryServer(absoluteSkeletonPath);
6959
7116
  const entryDir = await fs17.mkdtemp(path18.join(os2.tmpdir(), "walkeros-wrap-"));
6960
7117
  const entryPath = path18.join(entryDir, "entry.mjs");
@@ -7002,6 +7159,7 @@ async function wrapSkeleton(options) {
7002
7159
  init_auth();
7003
7160
  init_http();
7004
7161
  init_api_client();
7162
+ init_client_context();
7005
7163
  init_config_file();
7006
7164
  init_sse();
7007
7165
  init_utils();
@@ -7113,6 +7271,7 @@ export {
7113
7271
  bundle,
7114
7272
  bundleCommand,
7115
7273
  bundleRemote,
7274
+ clientContextHeaders,
7116
7275
  compareOutput,
7117
7276
  createApiClient,
7118
7277
  createDeployCommand,
@@ -7137,6 +7296,7 @@ export {
7137
7296
  feedbackCommand,
7138
7297
  findExample,
7139
7298
  getAuthHeaders,
7299
+ getClientContext,
7140
7300
  getDeployment,
7141
7301
  getDeploymentBySlug,
7142
7302
  getDeploymentBySlugCommand,
@@ -7163,8 +7323,10 @@ export {
7163
7323
  pushCommand,
7164
7324
  readConfig,
7165
7325
  requireProjectId,
7326
+ resetClientContext,
7166
7327
  run,
7167
7328
  runCommand,
7329
+ setClientContext,
7168
7330
  simulateDestination,
7169
7331
  simulateSource,
7170
7332
  simulateTransformer,