@helm-ai/cli 0.26.0 → 0.28.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 (2) hide show
  1. package/dist/cli.js +117 -4
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -25,7 +25,7 @@ function renderSplash(ctx) {
25
25
  }
26
26
 
27
27
  // src/version.ts
28
- var version = "0.26.0";
28
+ var version = "0.28.0";
29
29
 
30
30
  // src/commands/auth.ts
31
31
  import prompts from "prompts";
@@ -362,6 +362,13 @@ var HelmClient = class _HelmClient {
362
362
  return data.pipeline;
363
363
  }
364
364
  };
365
+ hours = {
366
+ /** Hour-plan balances, computed by the server. Filters are ANDed. */
367
+ balance: async (filters = {}) => {
368
+ const data = await this.request("get_hour_balance", "GET", filters);
369
+ return { plans: data.plans ?? [], message: data.message };
370
+ }
371
+ };
365
372
  timeEntries = {
366
373
  list: async (filters = {}) => {
367
374
  const data = await this.request("get_time_entries", "GET", filters);
@@ -446,6 +453,19 @@ var HelmClient = class _HelmClient {
446
453
  refresh: async (id) => {
447
454
  const data = await this.request("refresh_subscription", "POST", { id });
448
455
  return data.subscription;
456
+ },
457
+ // Payment links sent for a subscription, while they wait on the customer.
458
+ links: async (filters = {}) => {
459
+ const data = await this.request("list_subscription_checkouts", "GET", filters);
460
+ return data.checkouts ?? [];
461
+ },
462
+ cancelLink: async (id) => {
463
+ const data = await this.request("cancel_subscription_checkout", "POST", { id });
464
+ return data.checkout;
465
+ },
466
+ renewLink: async (id) => {
467
+ const data = await this.request("renew_subscription_checkout", "POST", { id });
468
+ return data;
449
469
  }
450
470
  };
451
471
  estimates = {
@@ -2209,6 +2229,46 @@ function registerTimeCommands(parent) {
2209
2229
  });
2210
2230
  }
2211
2231
 
2232
+ // src/commands/hours.ts
2233
+ var TYPE_LABELS = {
2234
+ monthly: "Monthly",
2235
+ quarterly: "Quarterly",
2236
+ hours_as_needed: "As needed"
2237
+ };
2238
+ function registerHoursCommands(parent) {
2239
+ const cmd = parent.command("hours").description("Clients' hour plans: prepaid and monthly hours");
2240
+ cmd.command("balance").description("Hours available, used and left on hour plans (every live plan by default)").option("--project <id>", "the plan this project draws from").option("--account <id>", "a client's plans").option("--plan <id>", "one plan, including an ended one").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
2241
+ try {
2242
+ const client = HelmClient.fromProfile(resolveProfile(opts.profile));
2243
+ const { plans, message } = await client.hours.balance({
2244
+ project_id: opts.project,
2245
+ account_id: opts.account,
2246
+ plan_id: opts.plan
2247
+ });
2248
+ const format = opts.output ?? defaultFormat();
2249
+ if (plans.length === 0 && format === "table") {
2250
+ console.log(message ?? "No hour plans found.");
2251
+ return;
2252
+ }
2253
+ console.log(render(plans, [
2254
+ { header: "Client", get: (p) => p.client.name ?? "", truncate: 28 },
2255
+ { header: "Plan", get: (p) => p.name, truncate: 32 },
2256
+ { header: "Type", get: (p) => TYPE_LABELS[p.type] ?? p.type },
2257
+ { header: "Left", get: (p) => `${p.hours.left}h` },
2258
+ { header: "Available", get: (p) => `${p.hours.available}h` },
2259
+ { header: "Used", get: (p) => `${p.hours.used}h` },
2260
+ { header: "Over", get: (p) => p.hours.over > 0 ? `${p.hours.over}h` : "" },
2261
+ { header: "Resets", get: (p) => p.period?.resets_on ?? "" },
2262
+ { header: "Status", get: (p) => p.status !== "active" ? p.status : p.out_of_hours ? "out of hours" : p.low_balance ? "low" : "" },
2263
+ { header: "ID", get: (p) => p.plan_id, truncate: 8 }
2264
+ ], format));
2265
+ } catch (err) {
2266
+ console.error(formatErrorForCli(err));
2267
+ process.exitCode = 1;
2268
+ }
2269
+ });
2270
+ }
2271
+
2212
2272
  // src/lib/line-items.ts
2213
2273
  import { readFileSync as readFileSync2 } from "fs";
2214
2274
  import { InvalidArgumentError } from "commander";
@@ -2491,6 +2551,15 @@ function recurring(r) {
2491
2551
  if (n > 1) return `${base}/${n}${INTERVAL_SHORT[r.billing_interval] ?? r.billing_interval}`;
2492
2552
  return `${base}/${INTERVAL_SHORT[r.billing_interval] ?? r.billing_interval}`;
2493
2553
  }
2554
+ function printLink(url, expiresAt) {
2555
+ console.log("Send this link to the customer:");
2556
+ console.log(url);
2557
+ console.log(
2558
+ `
2559
+ It shows as awaiting payment until they pay` + (expiresAt ? `, and expires ${new Date(expiresAt).toLocaleString()}.` : ".") + `
2560
+ See waiting links with: helm-ai subscription links`
2561
+ );
2562
+ }
2494
2563
  function statusOf(r) {
2495
2564
  return r.cancel_at_period_end && r.status !== "canceled" ? `${r.status} (ending)` : r.status;
2496
2565
  }
@@ -2561,9 +2630,7 @@ function registerSubscriptionCommands(parent) {
2561
2630
  method: opts.checkout ? "checkout" : "auto"
2562
2631
  });
2563
2632
  if (result.method === "checkout") {
2564
- console.log("Send this link to the customer:");
2565
- console.log(result.checkout_url);
2566
- console.log("\nThe subscription appears in Helm once they complete payment.");
2633
+ printLink(result.checkout_url, result.expires_at);
2567
2634
  } else {
2568
2635
  console.log(`\u2713 Subscription started (${result.subscription.stripe_subscription_id})`);
2569
2636
  }
@@ -2572,6 +2639,51 @@ function registerSubscriptionCommands(parent) {
2572
2639
  process.exitCode = 1;
2573
2640
  }
2574
2641
  });
2642
+ cmd.command("links").alias("pending").description("Payment links sent for a subscription that have not been paid").option("-s, --status <status>", "open|expired|completed|canceled|all (default: open and expired)").option("-c, --contact <id>").option("-a, --account <id>").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
2643
+ try {
2644
+ const client = HelmClient.fromProfile(resolveProfile(opts.profile));
2645
+ const rows = await client.subscriptions.links({
2646
+ status: opts.status,
2647
+ contact_id: opts.contact,
2648
+ account_id: opts.account,
2649
+ limit: opts.limit
2650
+ });
2651
+ console.log(render(rows, [
2652
+ { header: "Status", get: (r) => r.status },
2653
+ // "(removed)" only when the record is gone, not when a name is missing.
2654
+ { header: "Customer", get: (r) => r.contact_name ?? (r.contact_id ? "" : "(removed)"), truncate: 24 },
2655
+ { header: "Product", get: (r) => r.product_name ?? (r.product_id ? "" : "(removed)"), truncate: 24 },
2656
+ { header: "Amount", get: (r) => recurring(r) },
2657
+ { header: "Sent", get: (r) => r.created_at.slice(0, 10) },
2658
+ { header: "Expires (UTC)", get: (r) => r.expires_at?.replace("T", " ").slice(0, 16) ?? "" },
2659
+ { header: "Link", get: (r) => r.checkout_url, truncate: 40 },
2660
+ { header: "ID", get: (r) => r.id, truncate: 8 }
2661
+ ], opts.output ?? defaultFormat()));
2662
+ } catch (err) {
2663
+ console.error(formatErrorForCli(err));
2664
+ process.exitCode = 1;
2665
+ }
2666
+ });
2667
+ cmd.command("cancel-link <id>").description("Withdraw an unpaid payment link so it can no longer be paid").option("-p, --profile <name>").action(async (id, opts) => {
2668
+ try {
2669
+ const client = HelmClient.fromProfile(resolveProfile(opts.profile));
2670
+ await client.subscriptions.cancelLink(id);
2671
+ console.log("\u2713 Link canceled");
2672
+ } catch (err) {
2673
+ console.error(formatErrorForCli(err));
2674
+ process.exitCode = 1;
2675
+ }
2676
+ });
2677
+ cmd.command("resend-link <id>").description("Replace an unpaid or expired payment link with a fresh one on the same terms").option("-p, --profile <name>").action(async (id, opts) => {
2678
+ try {
2679
+ const client = HelmClient.fromProfile(resolveProfile(opts.profile));
2680
+ const result = await client.subscriptions.renewLink(id);
2681
+ if (result.method === "checkout") printLink(result.checkout_url, result.expires_at);
2682
+ } catch (err) {
2683
+ console.error(formatErrorForCli(err));
2684
+ process.exitCode = 1;
2685
+ }
2686
+ });
2575
2687
  cmd.command("cancel <id>").description("Cancel a subscription (at the end of the current period by default)").option("--now", "end it immediately instead of at the period end").option("-p, --profile <name>").action(async (id, opts) => {
2576
2688
  try {
2577
2689
  const client = HelmClient.fromProfile(resolveProfile(opts.profile));
@@ -4592,6 +4704,7 @@ registerDealCommands(program);
4592
4704
  registerPipelineCommands(program);
4593
4705
  registerTaskCommands(program);
4594
4706
  registerTimeCommands(program);
4707
+ registerHoursCommands(program);
4595
4708
  registerInvoiceCommands(program);
4596
4709
  registerPaymentCommands(program);
4597
4710
  registerSubscriptionCommands(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helm-ai/cli",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "description": "Command line interface for Helm",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",