@helm-ai/cli 0.24.0 → 0.25.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 +126 -12
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli.ts
4
- import { Command as Command2 } from "commander";
4
+ import { Command as Command3 } from "commander";
5
5
  import kleur8 from "kleur";
6
6
 
7
7
  // src/lib/branding.ts
@@ -25,7 +25,7 @@ function renderSplash(ctx) {
25
25
  }
26
26
 
27
27
  // src/version.ts
28
- var version = "0.24.0";
28
+ var version = "0.25.0";
29
29
 
30
30
  // src/commands/auth.ts
31
31
  import prompts from "prompts";
@@ -395,6 +395,7 @@ var HelmClient = class _HelmClient {
395
395
  const data = await this.request("create_invoice", "POST", input);
396
396
  return data.invoice;
397
397
  },
398
+ // No line_items: update_invoice ignores them. Lines go through lineItems below.
398
399
  update: async (invoiceId, input) => {
399
400
  const data = await this.request("update_invoice", "POST", { invoice_id: invoiceId, ...input });
400
401
  return data.invoice;
@@ -452,9 +453,30 @@ var HelmClient = class _HelmClient {
452
453
  const data = await this.request("get_estimates", "GET", filters);
453
454
  return data.estimates ?? [];
454
455
  },
456
+ get: async (estimateId) => {
457
+ const data = await this.request("get_estimate", "GET", { estimate_id: estimateId });
458
+ return data.estimate;
459
+ },
455
460
  create: async (input) => {
456
461
  const data = await this.request("create_estimate", "POST", input);
457
462
  return data.estimate;
463
+ },
464
+ update: async (estimateId, input) => {
465
+ const data = await this.request("update_estimate", "POST", { estimate_id: estimateId, ...input });
466
+ return data.estimate;
467
+ }
468
+ };
469
+ // Lines on an existing invoice or estimate. The database re-totals the
470
+ // document on every change; each call returns the line plus the new totals.
471
+ lineItems = {
472
+ add: async (input) => {
473
+ return await this.request("add_line_item", "POST", input);
474
+ },
475
+ update: async (input) => {
476
+ return await this.request("update_line_item", "POST", input);
477
+ },
478
+ delete: async (input) => {
479
+ return await this.request("delete_line_item", "POST", input);
458
480
  }
459
481
  };
460
482
  products = {
@@ -2258,6 +2280,58 @@ async function resolveLineItems(opts) {
2258
2280
  var LINE_ITEM_HELP = 'line item "description|quantity|rate" or "description|rate" (repeatable)';
2259
2281
  var LINE_ITEMS_FILE_HELP = 'JSON array of line items [{description, quantity, rate}] (path, or "-" for stdin)';
2260
2282
 
2283
+ // src/commands/line-item.ts
2284
+ import { InvalidArgumentError as InvalidArgumentError2 } from "commander";
2285
+ function parseAmount(value) {
2286
+ const n = Number(value.trim().replace(/^\$/, "").replace(/,/g, ""));
2287
+ if (value.trim() === "" || !Number.isFinite(n)) throw new InvalidArgumentError2(`"${value}" is not a number.`);
2288
+ return n;
2289
+ }
2290
+ function parseQuantity(value) {
2291
+ const n = parseAmount(value);
2292
+ if (n <= 0) throw new InvalidArgumentError2('Quantity must be greater than 0. Use "line remove" to drop a line.');
2293
+ return n;
2294
+ }
2295
+ function parsePosition(value) {
2296
+ const n = Number(value);
2297
+ if (!Number.isInteger(n) || n < 0) throw new InvalidArgumentError2(`"${value}" is not a valid position.`);
2298
+ return n;
2299
+ }
2300
+ function registerLineItemCommands(parent, documentType) {
2301
+ const cmd = parent.command("line").alias("lines").description(`Edit the line items on an ${documentType}`);
2302
+ const run = async (profile, fn) => {
2303
+ try {
2304
+ const client = HelmClient.fromProfile(resolveProfile(profile));
2305
+ console.log(JSON.stringify(await fn(client), null, 2));
2306
+ } catch (err) {
2307
+ console.error(formatErrorForCli(err));
2308
+ process.exitCode = 1;
2309
+ }
2310
+ };
2311
+ cmd.command(`add <${documentType}-id>`).description(`Add a custom line to an ${documentType}`).requiredOption("-d, --description <text>", "what the line is for (required)").option("-q, --quantity <n>", "defaults to 1", parseQuantity).option("-r, --rate <amount>", "price per unit (negative for a discount)", parseAmount).option("--position <n>", "sort position (defaults to the end)", parsePosition).option("-p, --profile <name>").addHelpText("after", `
2312
+ Example:
2313
+ helm-ai ${documentType} line add <${documentType}-id> -d "Extra revisions" -q 3 -r 120`).action((documentId, opts) => run(opts.profile, (client) => client.lineItems.add({
2314
+ document_type: documentType,
2315
+ document_id: documentId,
2316
+ description: opts.description,
2317
+ quantity: opts.quantity,
2318
+ rate: opts.rate,
2319
+ position: opts.position
2320
+ })));
2321
+ cmd.command("update <line-id>").description(`Change a line on an ${documentType}`).option("-d, --description <text>").option("-q, --quantity <n>", "", parseQuantity).option("-r, --rate <amount>", "", parseAmount).option("--position <n>", "sort position", parsePosition).option("-p, --profile <name>").action((lineId, opts) => run(opts.profile, (client) => client.lineItems.update({
2322
+ document_type: documentType,
2323
+ line_item_id: lineId,
2324
+ description: opts.description,
2325
+ quantity: opts.quantity,
2326
+ rate: opts.rate,
2327
+ position: opts.position
2328
+ })));
2329
+ cmd.command("remove <line-id>").alias("delete").description(`Remove a line from an ${documentType}`).option("-p, --profile <name>").action((lineId, opts) => run(opts.profile, (client) => client.lineItems.delete({
2330
+ document_type: documentType,
2331
+ line_item_id: lineId
2332
+ })));
2333
+ }
2334
+
2261
2335
  // src/commands/invoice.ts
2262
2336
  function registerInvoiceCommands(parent) {
2263
2337
  const cmd = parent.command("invoice").alias("invoices").description("Manage invoices");
@@ -2274,7 +2348,7 @@ function registerInvoiceCommands(parent) {
2274
2348
  { header: "Number", get: (r) => r.invoice_number },
2275
2349
  { header: "Title", get: (r) => r.title, truncate: 30 },
2276
2350
  { header: "Status", get: (r) => r.status },
2277
- { header: "Total", get: (r) => r.total != null ? `$${r.total.toLocaleString()}` : "" },
2351
+ { header: "Total", get: (r) => r.total_amount != null ? `$${Number(r.total_amount).toLocaleString()}` : "" },
2278
2352
  { header: "Due", get: (r) => r.due_date },
2279
2353
  { header: "ID", get: (r) => r.id, truncate: 8 }
2280
2354
  ], opts.output ?? defaultFormat()));
@@ -2321,15 +2395,20 @@ Examples:
2321
2395
  return;
2322
2396
  }
2323
2397
  });
2324
- cmd.command("update <id>").description("Update an invoice").option("-t, --title <title>").option("-s, --status <status>", "draft|open|partially_paid|paid|archived|cancelled").option("--deal <id>", "deal this invoice bills against").option("--tax-rate <pct>", "", parseFloat).option("--due-date <date>").option("-p, --profile <name>").action(async (id, opts) => {
2398
+ cmd.command("update <id>").description('Update an invoice (details only; edit lines with "invoice line")').option("-t, --title <title>").option("-d, --description <text>").option("-s, --status <status>", "draft|open|partially_paid|paid|archived|cancelled").option("-a, --account <id>").option("--deal <id>", "deal this invoice bills against").option("--tax-rate <pct>", "", parseFloat).option("--issue-date <date>", "ISO 8601").option("--due-date <date>", "ISO 8601").option("--notes <text>", "client-visible notes").option("--internal-notes <text>").option("-p, --profile <name>").action(async (id, opts) => {
2325
2399
  try {
2326
2400
  const client = HelmClient.fromProfile(resolveProfile(opts.profile));
2327
2401
  const invoice = await client.invoices.update(id, {
2328
2402
  title: opts.title,
2403
+ description: opts.description,
2329
2404
  status: opts.status,
2405
+ account_id: opts.account,
2330
2406
  deal_id: opts.deal,
2331
2407
  tax_rate: opts.taxRate,
2332
- due_date: opts.dueDate
2408
+ issue_date: opts.issueDate,
2409
+ due_date: opts.dueDate,
2410
+ notes: opts.notes,
2411
+ internal_notes: opts.internalNotes
2333
2412
  });
2334
2413
  console.log(JSON.stringify(invoice, null, 2));
2335
2414
  } catch (err) {
@@ -2338,6 +2417,7 @@ Examples:
2338
2417
  return;
2339
2418
  }
2340
2419
  });
2420
+ registerLineItemCommands(cmd, "invoice");
2341
2421
  }
2342
2422
 
2343
2423
  // src/commands/payment.ts
@@ -2551,7 +2631,7 @@ function registerEstimateCommands(parent) {
2551
2631
  { header: "Number", get: (r) => r.estimate_number },
2552
2632
  { header: "Title", get: (r) => r.title, truncate: 30 },
2553
2633
  { header: "Status", get: (r) => r.status },
2554
- { header: "Total", get: (r) => r.total != null ? `$${r.total.toLocaleString()}` : "" },
2634
+ { header: "Total", get: (r) => r.total_amount != null ? `$${Number(r.total_amount).toLocaleString()}` : "" },
2555
2635
  { header: "Expires", get: (r) => r.expiry_date },
2556
2636
  { header: "ID", get: (r) => r.id, truncate: 8 }
2557
2637
  ], opts.output ?? defaultFormat()));
@@ -2561,6 +2641,17 @@ function registerEstimateCommands(parent) {
2561
2641
  return;
2562
2642
  }
2563
2643
  });
2644
+ cmd.command("get <id>").description("Get an estimate by ID, with its line items").option("-p, --profile <name>").action(async (id, opts) => {
2645
+ try {
2646
+ const client = HelmClient.fromProfile(resolveProfile(opts.profile));
2647
+ const estimate = await client.estimates.get(id);
2648
+ console.log(JSON.stringify(estimate, null, 2));
2649
+ } catch (err) {
2650
+ console.error(formatErrorForCli(err));
2651
+ process.exitCode = 1;
2652
+ return;
2653
+ }
2654
+ });
2564
2655
  cmd.command("create").description("Create an estimate").requiredOption("-t, --title <title>", "estimate title (required)").option("-d, --description <text>").option("-a, --account <id>").option("-c, --contact <id>", "person at the account the estimate is addressed to").option("-i, --item <item>", LINE_ITEM_HELP, collectLineItem).option("--items <path>", LINE_ITEMS_FILE_HELP).option("--tax-rate <pct>", "", parseFloat).option("--issue-date <date>").option("--expiry-date <date>").option("--notes <text>").option("--internal-notes <text>").option("-p, --profile <name>").addHelpText("after", `
2565
2656
  Examples:
2566
2657
  helm-ai estimate create -t "Launch readiness" -a <account-id> \\
@@ -2587,6 +2678,29 @@ Examples:
2587
2678
  return;
2588
2679
  }
2589
2680
  });
2681
+ cmd.command("update <id>").description('Update an estimate (details only; edit lines with "estimate line")').option("-t, --title <title>").option("-d, --description <text>").option("-s, --status <status>", "draft|sent|accepted|declined|archived|cancelled").option("-a, --account <id>").option("-c, --contact <id>", "person at the account the estimate is addressed to").option("--tax-rate <pct>", "", parseFloat).option("--issue-date <date>").option("--expiry-date <date>").option("--notes <text>").option("--internal-notes <text>").option("-p, --profile <name>").action(async (id, opts) => {
2682
+ try {
2683
+ const client = HelmClient.fromProfile(resolveProfile(opts.profile));
2684
+ const estimate = await client.estimates.update(id, {
2685
+ title: opts.title,
2686
+ description: opts.description,
2687
+ status: opts.status,
2688
+ account_id: opts.account,
2689
+ contact_id: opts.contact,
2690
+ tax_rate: opts.taxRate,
2691
+ issue_date: opts.issueDate,
2692
+ expiry_date: opts.expiryDate,
2693
+ notes: opts.notes,
2694
+ internal_notes: opts.internalNotes
2695
+ });
2696
+ console.log(JSON.stringify(estimate, null, 2));
2697
+ } catch (err) {
2698
+ console.error(formatErrorForCli(err));
2699
+ process.exitCode = 1;
2700
+ return;
2701
+ }
2702
+ });
2703
+ registerLineItemCommands(cmd, "estimate");
2590
2704
  }
2591
2705
 
2592
2706
  // src/commands/product.ts
@@ -3043,16 +3157,16 @@ function registerCalendarCommands(parent) {
3043
3157
  }
3044
3158
 
3045
3159
  // src/commands/doc.ts
3046
- import { InvalidArgumentError as InvalidArgumentError2 } from "commander";
3160
+ import { InvalidArgumentError as InvalidArgumentError3 } from "commander";
3047
3161
  import { readFileSync as readFileSync3 } from "fs";
3048
3162
  function readContent(opts) {
3049
3163
  if (opts.contentFile) return readFileSync3(opts.contentFile, "utf8");
3050
3164
  if (opts.content === "-") return readFileSync3(0, "utf8");
3051
3165
  return opts.content;
3052
3166
  }
3053
- function parsePosition(value) {
3167
+ function parsePosition2(value) {
3054
3168
  const n = Number(value);
3055
- if (!Number.isInteger(n) || n < 0) throw new InvalidArgumentError2("must be a whole number, 0 or more");
3169
+ if (!Number.isInteger(n) || n < 0) throw new InvalidArgumentError3("must be a whole number, 0 or more");
3056
3170
  return n;
3057
3171
  }
3058
3172
  function registerDocCommands(parent) {
@@ -3201,7 +3315,7 @@ function registerDocCommands(parent) {
3201
3315
  return;
3202
3316
  }
3203
3317
  });
3204
- page.command("create <documentId>").description("Add a page to a document (content from --content, --content-file, or stdin with -c -)").option("-t, --title <title>", "page title", "Untitled Page").option("-c, --content <text>", 'content as markdown (use "-" for stdin)').option("--content-file <path>", "read content from a file").option("--icon <name>", "icon name (e.g. FileText)").option("--order <n>", "zero-based position; omit to append at end", parsePosition).option("-p, --profile <name>").action(async (documentId, opts) => {
3318
+ page.command("create <documentId>").description("Add a page to a document (content from --content, --content-file, or stdin with -c -)").option("-t, --title <title>", "page title", "Untitled Page").option("-c, --content <text>", 'content as markdown (use "-" for stdin)').option("--content-file <path>", "read content from a file").option("--icon <name>", "icon name (e.g. FileText)").option("--order <n>", "zero-based position; omit to append at end", parsePosition2).option("-p, --profile <name>").action(async (documentId, opts) => {
3205
3319
  try {
3206
3320
  const client = HelmClient.fromProfile(resolveProfile(opts.profile));
3207
3321
  const newPage = await client.documents.createPage(documentId, {
@@ -3217,7 +3331,7 @@ function registerDocCommands(parent) {
3217
3331
  return;
3218
3332
  }
3219
3333
  });
3220
- page.command("update <documentId> <pageId>").description("Rename, rewrite, re-icon or move a page (content from --content, --content-file, or stdin with -c -)").option("-t, --title <title>", "new page title").option("-c, --content <text>", 'replacement content as markdown (use "-" for stdin)').option("--content-file <path>", "read replacement content from a file").option("--icon <name>", 'icon name (e.g. FileText); "" clears it').option("--order <n>", "move to this zero-based position; the other pages shift", parsePosition).option("-p, --profile <name>").action(async (documentId, pageId, opts) => {
3334
+ page.command("update <documentId> <pageId>").description("Rename, rewrite, re-icon or move a page (content from --content, --content-file, or stdin with -c -)").option("-t, --title <title>", "new page title").option("-c, --content <text>", 'replacement content as markdown (use "-" for stdin)').option("--content-file <path>", "read replacement content from a file").option("--icon <name>", 'icon name (e.g. FileText); "" clears it').option("--order <n>", "move to this zero-based position; the other pages shift", parsePosition2).option("-p, --profile <name>").action(async (documentId, pageId, opts) => {
3221
3335
  try {
3222
3336
  const client = HelmClient.fromProfile(resolveProfile(opts.profile));
3223
3337
  const updated = await client.documents.updatePage(documentId, pageId, {
@@ -4466,7 +4580,7 @@ function registerEmailCommands(parent) {
4466
4580
  }
4467
4581
 
4468
4582
  // src/cli.ts
4469
- var program = new Command2();
4583
+ var program = new Command3();
4470
4584
  program.name("helm-ai").description("Helm CLI \u2014 run your business operations (projects, CRM, billing, automations, AI agents) from the terminal").version(version, "-v, --version").addHelpText("beforeAll", () => process.stdout.isTTY ? renderSplash({ version }) : "");
4471
4585
  registerAuthCommands(program);
4472
4586
  registerProfileCommands(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helm-ai/cli",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Command line interface for Helm",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",