swytchcode 2.6.1 → 2.6.2

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 (2) hide show
  1. package/bin/swytchcode.js +40 -25
  2. package/package.json +7 -7
package/bin/swytchcode.js CHANGED
@@ -300,6 +300,8 @@ const userArgs = process.argv.slice(2);
300
300
  // Capture original arg BEFORE mutation
301
301
  const originalArg = process.argv[2] || '';
302
302
  const isCanonicalDemoArg = /^[\w]+\.[\w.]+$/.test(originalArg) && !originalArg.startsWith('-');
303
+ // A single bare word under npx is a potential (invalid) demo lookup — don't pass through to cobra
304
+ const isNpxBareWordArg = isNpx && userArgs.length === 1 && /^[\w]+$/.test(originalArg) && !originalArg.startsWith('-');
303
305
  // Legacy support: npx swytchcode <canonical_id> → npx swytchcode exec <canonical_id>
304
306
  if (userArgs.length > 0 && /^[\w]+\.[\w.]+$/.test(userArgs[0]) && !userArgs[0].startsWith('-')) {
305
307
  userArgs.unshift('exec');
@@ -322,28 +324,9 @@ async function runOnboardingDirectDemo(canonicalId) {
322
324
  await runOnboardingSteps2to4();
323
325
  }
324
326
 
325
- // ─── Normal pass-through (not npx, or npx with non-demo args) ───────────────
326
- if (!isNpx || (userArgs.length > 0 && !isCanonicalDemoArg)) {
327
- const result = spawnBin(binPath, userArgs);
328
- if (result.error) {
329
- err(`swytchcode: failed to launch binary: ${result.error.message}`);
330
- }
331
- process.exit(exitCode(result));
332
- }
333
- // ─── NPX with canonical ID: run demo directly then show onboarding ───────────
334
- if (isNpx && isCanonicalDemoArg) {
335
- runOnboardingDirectDemo(originalArg).catch(e => {
336
- err(`\nswytchcode: onboarding error (${e.message}) — falling back to CLI.\n`);
337
- const result = spawnBin(binPath, userArgs);
338
- process.exit(exitCode(result));
339
- });
340
- } else {
341
- // ─── NPX ONBOARDING FLOW ─────────────────────────────────────────────────────
342
- // Only reached when: isNpx === true AND no args passed (bare `npx swytchcode`)
343
-
327
+ // ─── HTTP helpers (used by both canonical-demo and bare-npx onboarding paths) ─
344
328
  const API_BASE = 'https://api-v2.swytchcode.com/v2/cli';
345
329
 
346
- // Helper to perform HTTP GET (declared inside so it doesn't conflict)
347
330
  function apiGet(urlStr) {
348
331
  return new Promise((resolve, reject) => {
349
332
  const parsed = new URL(urlStr);
@@ -368,6 +351,43 @@ function apiGet(urlStr) {
368
351
  });
369
352
  }
370
353
 
354
+ // ─── Normal pass-through (not npx, or npx with non-demo args) ───────────────
355
+ if (!isNpx || (userArgs.length > 0 && !isCanonicalDemoArg && !isNpxBareWordArg)) {
356
+ const result = spawnBin(binPath, userArgs);
357
+ if (result.error) {
358
+ err(`swytchcode: failed to launch binary: ${result.error.message}`);
359
+ }
360
+ process.exit(exitCode(result));
361
+ }
362
+
363
+ // ─── NPX routing: three mutually exclusive paths ─────────────────────────────
364
+ if (isNpx && isCanonicalDemoArg) {
365
+ // Dotted canonical ID (e.g. stripe.create_payment) — run demo then onboard
366
+ runOnboardingDirectDemo(originalArg).catch(e => {
367
+ err(`\nswytchcode: onboarding error (${e.message}) — falling back to CLI.\n`);
368
+ const result = spawnBin(binPath, userArgs);
369
+ process.exit(exitCode(result));
370
+ });
371
+ } else if (isNpxBareWordArg) {
372
+ // Single bare word (e.g. "abcd") — not a valid canonical ID; show message then onboard
373
+ writeln();
374
+ writeln(` ${c.yellow}⚠ ${c.bold}${originalArg}${c.reset}${c.yellow} isn't a valid demo tool — canonical IDs look like ${c.bold}provider.method${c.reset}`);
375
+ writeln(` ${c.dim}Let's run a working demo instead.${c.reset}`);
376
+ writeln();
377
+ Promise.resolve()
378
+ .then(() => runDemoSelection())
379
+ .then(() => runOnboardingSteps2to4())
380
+ .catch(e => {
381
+ err(`\nswytchcode: onboarding error (${e.message}) — falling back to CLI.\n`);
382
+ process.exit(1);
383
+ });
384
+ } else {
385
+ // Bare npx swytchcode (no args) — full onboarding with welcome banner
386
+ runOnboarding().catch(e => {
387
+ err(`\nswytchcode: onboarding error (${e.message}) — falling back to CLI.\n`);
388
+ const result = spawnBin(binPath, userArgs);
389
+ process.exit(exitCode(result));
390
+ });
371
391
  }
372
392
 
373
393
  async function runDemoSelection() {
@@ -572,8 +592,3 @@ async function runOnboardingSteps2to4() {
572
592
  writeln();
573
593
  }
574
594
 
575
- runOnboarding().catch(e => {
576
- err(`\nswytchcode: onboarding error (${e.message}) — falling back to CLI.\n`);
577
- const result = spawnBin(binPath, userArgs);
578
- process.exit(exitCode(result));
579
- });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swytchcode",
3
- "version": "2.6.1",
3
+ "version": "2.6.2",
4
4
  "description": "Execution authority layer for API integrations",
5
5
  "keywords": [
6
6
  "api",
@@ -23,11 +23,11 @@
23
23
  "README.md"
24
24
  ],
25
25
  "optionalDependencies": {
26
- "swytchcode-cli-darwin-arm64": "2.6.1",
27
- "swytchcode-cli-darwin-x64": "2.6.1",
28
- "swytchcode-cli-linux-arm64": "2.6.1",
29
- "swytchcode-cli-linux-x64": "2.6.1",
30
- "swytchcode-cli-win32-arm64": "2.6.1",
31
- "swytchcode-cli-win32-x64": "2.6.1"
26
+ "swytchcode-cli-darwin-arm64": "2.6.2",
27
+ "swytchcode-cli-darwin-x64": "2.6.2",
28
+ "swytchcode-cli-linux-arm64": "2.6.2",
29
+ "swytchcode-cli-linux-x64": "2.6.2",
30
+ "swytchcode-cli-win32-arm64": "2.6.2",
31
+ "swytchcode-cli-win32-x64": "2.6.2"
32
32
  }
33
33
  }