@zalify/cli 0.2.1 → 0.2.3

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/dist/cli.js +94 -5
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -11424,11 +11424,51 @@ function logout() {
11424
11424
  console.log("✓ Logged out (local credentials deleted).");
11425
11425
  console.log(" To revoke the key itself: app.zalify.com → Settings → Developer.");
11426
11426
  }
11427
- function whoami() {
11427
+ function ago(iso) {
11428
+ if (!iso)
11429
+ return "never";
11430
+ const ms = Date.now() - new Date(iso).getTime();
11431
+ const minutes = Math.round(ms / 60000);
11432
+ if (minutes < 1)
11433
+ return "just now";
11434
+ if (minutes < 60)
11435
+ return `${minutes}m ago`;
11436
+ const hours = Math.round(minutes / 60);
11437
+ if (hours < 24)
11438
+ return `${hours}h ago`;
11439
+ return `${Math.round(hours / 24)}d ago`;
11440
+ }
11441
+ async function whoami() {
11428
11442
  const config = requireConfig();
11429
- console.log(`workspace ${config.workspaceName || "(unknown)"} [${config.workspaceId}]`);
11443
+ let live = null;
11444
+ let liveError = null;
11445
+ try {
11446
+ const res = await fetch(`${config.appUrl}/api/cli/whoami`, {
11447
+ headers: { Authorization: `Bearer ${config.key}` }
11448
+ });
11449
+ if (res.ok) {
11450
+ live = await res.json();
11451
+ } else if (res.status === 401) {
11452
+ liveError = "key is invalid or was revoked — run `zalify login`";
11453
+ } else {
11454
+ liveError = `server returned ${res.status}`;
11455
+ }
11456
+ } catch {
11457
+ liveError = "could not reach the server (offline?)";
11458
+ }
11459
+ const ws = live?.workspace;
11460
+ console.log(`workspace ${ws?.name ?? config.workspaceName ?? "(unknown)"} (${ws?.slug ?? config.workspaceSlug ?? "?"}) [${ws?.id ?? config.workspaceId}]`);
11461
+ if (live) {
11462
+ console.log(`plan ${live.plan.name} (${live.plan.type})`);
11463
+ if (live.key.createdByName) {
11464
+ console.log(`user ${live.key.createdByName}`);
11465
+ }
11466
+ console.log(`key ${live.key.name ?? config.key.slice(0, 16) + "…"} — created ${live.key.createdAt ? new Date(live.key.createdAt).toISOString().slice(0, 10) : "?"}, last used ${ago(live.key.lastRequest)}`);
11467
+ } else {
11468
+ console.log(`key ${config.key.slice(0, 16)}…`);
11469
+ }
11430
11470
  console.log(`app ${config.appUrl}`);
11431
- console.log(`key ${config.key.slice(0, 16)}…`);
11471
+ console.log(live ? "status ✓ key verified" : `status ! not verified — ${liveError}`);
11432
11472
  }
11433
11473
 
11434
11474
  // src/assets.ts
@@ -11486,8 +11526,13 @@ async function assetsPush(storeDir) {
11486
11526
  body: JSON.stringify(body)
11487
11527
  });
11488
11528
  const json = await res.json().catch(() => ({}));
11489
- if (!res.ok)
11529
+ if (!res.ok) {
11530
+ if (json.code === "UPGRADE_REQUIRED") {
11531
+ throw new Error(`${json.error ?? "This feature requires a paid plan."}
11532
+ ` + ` Upgrade this workspace at ${config.appUrl} (Settings → Billing).`);
11533
+ }
11490
11534
  throw new Error(`${path9} ${res.status}: ${JSON.stringify(json)}`);
11535
+ }
11491
11536
  return json;
11492
11537
  }
11493
11538
  const files = readdirSync(imagesDir).filter((f) => f.endsWith(".png")).map((name) => {
@@ -11566,10 +11611,51 @@ async function assetsPush(storeDir) {
11566
11611
  console.log("Done.");
11567
11612
  }
11568
11613
 
11614
+ // src/self-update.ts
11615
+ import { spawnSync } from "node:child_process";
11616
+ import { realpathSync } from "node:fs";
11617
+ function detectManager() {
11618
+ let binPath = process.argv[1] ?? "";
11619
+ try {
11620
+ binPath = realpathSync(binPath);
11621
+ } catch {}
11622
+ if (binPath.includes("/pnpm/") || binPath.includes("/.pnpm/")) {
11623
+ return { cmd: "pnpm", args: ["add", "-g", "@zalify/cli@latest"] };
11624
+ }
11625
+ if (binPath.includes("/.bun/")) {
11626
+ return { cmd: "bun", args: ["add", "-g", "@zalify/cli@latest"] };
11627
+ }
11628
+ return { cmd: "npm", args: ["install", "-g", "@zalify/cli@latest"] };
11629
+ }
11630
+ function selfUpdate(currentVersion) {
11631
+ const { cmd, args } = detectManager();
11632
+ console.log(`Current version: ${currentVersion}`);
11633
+ console.log(`Updating via: ${cmd} ${args.join(" ")}
11634
+ `);
11635
+ const result = spawnSync(cmd, args, { stdio: "inherit" });
11636
+ if (result.error || result.status !== 0) {
11637
+ console.error(`
11638
+ Update failed${result.error ? `: ${result.error.message}` : ""}.` + `
11639
+ Try manually: ${cmd} ${args.join(" ")}`);
11640
+ process.exit(result.status ?? 1);
11641
+ }
11642
+ const check = spawnSync("zalify", ["--version"], { encoding: "utf8" });
11643
+ const updated = check.stdout?.trim();
11644
+ console.log(updated && updated !== currentVersion ? `
11645
+ ✓ Updated ${currentVersion} → ${updated}` : `
11646
+ ✓ Done${updated ? ` (version: ${updated})` : ""}`);
11647
+ }
11648
+
11569
11649
  // src/cli.ts
11570
11650
  var __dirname4 = dirname(fileURLToPath3(import.meta.url));
11571
11651
  var require2 = createRequire2(import.meta.url);
11572
11652
  var pkg = require2(join3(__dirname4, "..", "package.json"));
11653
+ try {
11654
+ updateNotifier({ pkg }).notify({
11655
+ isGlobal: true,
11656
+ message: "Update available {currentVersion} → {latestVersion}\nRun `zalify self-update`"
11657
+ });
11658
+ } catch {}
11573
11659
  var program2 = new Command;
11574
11660
  program2.name("zalify").description("Zalify CLI - command-line interface for Zalify").version(pkg.version, "-v, --version", "output the current version");
11575
11661
  program2.command("version").description("Print Zalify CLI version and check for updates").action(async () => {
@@ -11592,11 +11678,14 @@ A new version (${update.latest}) is available. Run "npm i -g @zalify/cli@latest"
11592
11678
  }
11593
11679
  } catch {}
11594
11680
  });
11681
+ program2.command("self-update").description("Update the CLI to the latest version (auto-detects pnpm/bun/npm)").action(() => selfUpdate(pkg.version));
11595
11682
  program2.command("login").description("Authenticate via the browser and store a workspace API key").option("--app-url <url>", "Zalify app origin (default: https://app.zalify.com)").action(async (options) => {
11596
11683
  await login(options);
11597
11684
  });
11598
11685
  program2.command("logout").description("Delete the stored CLI credentials").action(() => logout());
11599
- program2.command("whoami").description("Show the authorized workspace and key prefix").action(() => whoami());
11686
+ program2.command("whoami").description("Verify the stored key and show workspace, plan, and key details").action(async () => {
11687
+ await whoami();
11688
+ });
11600
11689
  var assets = program2.command("assets").description("Sync images with the Zalify asset library");
11601
11690
  assets.command("push <store-dir>").description("Upload <store-dir>/images/*.png (sha256 dedup, writes assets.json)").action(async (storeDir) => {
11602
11691
  await assetsPush(storeDir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zalify/cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Zalify CLI - command-line interface for Zalify",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",