zyntry 0.3.0 → 0.4.0

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 (3) hide show
  1. package/index.mjs +117 -1
  2. package/package.json +5 -1
  3. package/postinstall.js +15 -0
package/index.mjs CHANGED
@@ -145,6 +145,8 @@ function yamlFor(project, credentials) {
145
145
  ` name: "${project.name}"`,
146
146
  ` slug: "${project.slug || ""}"`,
147
147
  ` environment: "${project.environment}"`,
148
+ ` plan: "${project.plan_code || "free"}"`,
149
+ ` region: "automatic"`,
148
150
  ``,
149
151
  `api:`,
150
152
  ` base_url: "${credentials.api_base_url}"`,
@@ -292,6 +294,9 @@ Usage:
292
294
  zyntry plans [create|list] Manage end-user rate plans
293
295
  zyntry users [list|add] Manage end users and their usage
294
296
  zyntry quota <user_id> Check an end-user's quota
297
+ zyntry upgrade [pro|studio] Upgrade this project's plan (opens checkout)
298
+ zyntry apply Apply zyntry.yaml to the project: plan,
299
+ region, and runtimes are reconciled
295
300
  zyntry updates Show recent product updates
296
301
  zyntry mcp Start the Zyntry MCP server (stdio) for
297
302
  Claude Code, Cursor, Windsurf, and any MCP client
@@ -576,7 +581,7 @@ async function commandRun(rest) {
576
581
  }
577
582
  if (!result.ok) {
578
583
  fail("Invoke failed: " + (result.data?.message || result.data?.error || result.status));
579
- if (result.status === 402) dim("The project's plan limits apply. Check quota in the console or upgrade the project.");
584
+ if (result.status === 402) dim("This project's plan limit was reached. Upgrade with: " + COLORS.bold("zyntry upgrade pro"));
580
585
  if (result.status === 429) dim(String(result.data?.reason || "Rate limited — retry shortly."));
581
586
  process.exit(1);
582
587
  }
@@ -848,6 +853,115 @@ function commandMcp() {
848
853
  rl.on("close", () => process.exit(0));
849
854
  }
850
855
 
856
+ /* ------------------------------- upgrade ---------------------------------- */
857
+
858
+ async function commandUpgrade(planArg, projectIdArg) {
859
+ const token = requireToken();
860
+ const planCode = (planArg || "pro").toLowerCase();
861
+ if (!["pro", "studio"].includes(planCode)) { fail("Plans available from the CLI: pro, studio. (Enterprise is sales-assisted.)"); return; }
862
+ const projectId = projectIdArg || readProjectIdFromYamlOptional();
863
+ if (!projectId) { fail("No project context. Run " + COLORS.bold("zyntry init") + " in this directory, or pass -p <project_id>."); return; }
864
+
865
+ const catalog = await api("/api/v1/projects/plans/catalog", {}, token);
866
+ const plan = catalog.ok ? (catalog.data.plans || []).find((p) => p.code === planCode) : null;
867
+ const price = plan ? ("$" + (plan.price_cents / 100).toFixed(2) + "/" + (plan.billing_interval || "month")) : planCode;
868
+ log("Upgrading project to " + COLORS.bold(planCode) + " (" + price + " per project).");
869
+ const consent = await confirm("Authorize the charge? This opens Zyntry checkout in your browser.");
870
+ if (!consent) { dim("Nothing was charged and nothing changed."); return; }
871
+
872
+ const idem = "cli-upgrade-" + projectId + "-" + planCode + "-" + Date.now();
873
+ const result = await api("/api/v1/billing/subscriptions/checkout", {
874
+ method: "POST",
875
+ headers: { "Idempotency-Key": idem },
876
+ body: JSON.stringify({ project_id: projectId, plan_code: planCode }),
877
+ }, token);
878
+ if (!result.ok || !result.data?.url) { fail("Checkout could not be created: " + (result.data?.message || result.status)); process.exit(1); }
879
+ log("\n Complete payment: " + COLORS.cyan(result.data.url));
880
+ openBrowser(result.data.url);
881
+ dim(" The plan activates as soon as checkout and the billing webhook complete —");
882
+ dim(" then every " + planCode + " capability unlocks on this project.");
883
+ }
884
+
885
+ /* -------------------------------- apply ----------------------------------- */
886
+
887
+ function parseYamlConfig() {
888
+ const yamlPath = join(process.cwd(), "zyntry.yaml");
889
+ if (!existsSync(yamlPath)) { fail("No zyntry.yaml in this directory. Run zyntry init first."); process.exit(1); }
890
+ const yaml = readFileSync(yamlPath, "utf8");
891
+ const head = yaml.split("runtimes:")[0];
892
+ const config = {
893
+ projectId: yaml.match(/id:\s*"([^"]+)"/)?.[1] ?? null,
894
+ plan: head.match(/plan:\s*"([^"]+)"/)?.[1] ?? null,
895
+ region: head.match(/region:\s*"([^"]+)"/)?.[1] ?? null,
896
+ runtimes: [],
897
+ };
898
+ const runtimesBlock = yaml.split(/^runtimes:\s*$/m)[1];
899
+ if (runtimesBlock) {
900
+ let current = null;
901
+ for (const rawLine of runtimesBlock.split("\n")) {
902
+ const line = rawLine.trim();
903
+ if (!line || line.startsWith("#")) continue;
904
+ if (line.startsWith("- ")) { if (current) config.runtimes.push(current); current = { name: line.slice(2).replace(/^name:\s*/, "").replace(/"/g, "").trim() }; }
905
+ else if (current && line.startsWith("environment:")) current.environment = line.split(":")[1].trim().replace(/"/g, "");
906
+ else if (current && line.startsWith("region:")) current.region = line.split(":")[1].trim().replace(/"/g, "");
907
+ else if (line && !rawLine.startsWith(" ") && !rawLine.startsWith("-")) { if (current) { config.runtimes.push(current); current = null; } break; }
908
+ }
909
+ if (current) config.runtimes.push(current);
910
+ config.runtimes = config.runtimes.filter((r) => r && r.name);
911
+ }
912
+ return config;
913
+ }
914
+
915
+ async function commandApply() {
916
+ const token = requireToken();
917
+ const config = parseYamlConfig();
918
+ if (!config.projectId) { fail("Could not read project id from zyntry.yaml."); return; }
919
+
920
+ const projectsResult = await api("/api/v1/projects", {}, token);
921
+ if (!projectsResult.ok) { fail("Unable to load projects (" + projectsResult.status + ")."); process.exit(1); }
922
+ const project = (projectsResult.data.projects || []).find((p) => p.id === config.projectId);
923
+ if (!project) { fail("The project in zyntry.yaml is not on this account."); process.exit(1); }
924
+
925
+ log("Applying " + COLORS.bold("zyntry.yaml") + " to " + COLORS.bold(project.name) + " (" + (project.plan_code ?? "free") + ")…");
926
+
927
+ if (config.plan && String(config.plan) !== String(project.plan_code ?? "free")) {
928
+ log(" plan: " + (project.plan_code ?? "free") + " → " + config.plan);
929
+ if (["pro", "studio"].includes(config.plan)) {
930
+ await commandUpgrade(config.plan, config.projectId);
931
+ } else {
932
+ warn(" plan '" + config.plan + "' is not upgradable from the CLI; only pro and studio checkouts are supported.");
933
+ }
934
+ } else {
935
+ dim(" plan: " + (project.plan_code ?? "free") + " (unchanged)");
936
+ }
937
+
938
+ if (config.region && config.region !== "automatic") {
939
+ const patch = await api("/api/v1/projects/" + config.projectId, { method: "PATCH", body: JSON.stringify({ settings: { region: config.region } }) }, token);
940
+ if (patch.ok) ok(" region: " + config.region + " applied");
941
+ else if (patch.data?.error === "region_selection_unavailable") warn(" region: " + config.region + " requires a higher plan — unchanged.");
942
+ else warn(" region: could not apply (" + (patch.data?.message || patch.data?.error || patch.status) + ")");
943
+ } else {
944
+ dim(" region: automatic (unchanged)");
945
+ }
946
+
947
+ const runtimesResult = await api("/api/v1/runtimes?project_id=" + encodeURIComponent(config.projectId) + "&limit=50", {}, token);
948
+ const existing = runtimesResult.ok ? (runtimesResult.data.runtimes || runtimesResult.data.items || []) : [];
949
+ const existingNames = new Set(existing.map((r) => r.name));
950
+ let created = 0;
951
+ for (const wanted of config.runtimes) {
952
+ if (existingNames.has(wanted.name)) { dim(" runtime " + wanted.name + ": exists"); continue; }
953
+ const body = { project_id: config.projectId, name: wanted.name, environment: wanted.environment || "development" };
954
+ if (wanted.region && wanted.region !== "automatic") body.region = wanted.region;
955
+ const create = await api("/api/v1/runtimes", { method: "POST", body: JSON.stringify(body) }, token);
956
+ if (create.ok) { ok(" runtime " + wanted.name + ": created — provisioning"); created++; }
957
+ else warn(" runtime " + wanted.name + ": " + (create.data?.message || create.data?.error || "failed (" + create.status + ")"));
958
+ }
959
+ if (!config.runtimes.length) dim(" runtimes: none declared in zyntry.yaml");
960
+ log("");
961
+ if (created) ok("Apply complete — " + created + " runtime" + (created === 1 ? "" : "s") + " provisioning.");
962
+ else log("Apply complete.");
963
+ }
964
+
851
965
  const [command, ...rest] = process.argv.slice(2);
852
966
  switch (command) {
853
967
  case "login": await commandLogin(); break;
@@ -857,6 +971,8 @@ switch (command) {
857
971
  case "plans": await commandPlans(rest[0]); break;
858
972
  case "users": await commandUsers(rest[0]); break;
859
973
  case "quota": await commandQuota(rest[0]); break;
974
+ case "upgrade": await commandUpgrade(rest[0], rest[1]); break;
975
+ case "apply": case "up": await commandApply(); break;
860
976
  case "projects": await commandProjects(rest[0], rest[1]); break;
861
977
  case "run": case "invoke": await commandRun(rest); break;
862
978
  case "mcp": commandMcp(); break;
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "zyntry",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "The Zyntry CLI — run AI inference, manage runtimes, security groups, and end-user metering from the terminal. Ships with a built-in MCP server for Claude Code, Cursor, and Windsurf.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
8
8
  "zyntry": "./index.mjs"
9
9
  },
10
+ "scripts": {
11
+ "postinstall": "node postinstall.js"
12
+ },
10
13
  "engines": {
11
14
  "node": ">=18"
12
15
  },
@@ -27,6 +30,7 @@
27
30
  },
28
31
  "files": [
29
32
  "index.mjs",
33
+ "postinstall.js",
30
34
  "README.md"
31
35
  ],
32
36
  "preferGlobal": true
package/postinstall.js ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ /** Post-install welcome for the Zyntry CLI. Prints only — no network, no
3
+ * filesystem writes, safe in CI and offline installs. */
4
+ const line = process.platform === "win32" ? "" : "";
5
+ process.stdout.write([
6
+ "",
7
+ "\x1b[1mZyntry CLI installed\x1b[0m",
8
+ "",
9
+ " \x1b[36mzyntry login\x1b[0m approve this device in your browser",
10
+ " \x1b[36mzyntry init\x1b[0m create or link a project in this folder",
11
+ " \x1b[36mzyntry run \"hello\"\x1b[0m run your first inference",
12
+ "",
13
+ " Docs: https://zyntry.space/docs",
14
+ "",
15
+ ].join("\n") + "\n");