@helm-ai/cli 0.23.0 → 0.24.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.
- package/dist/cli.js +102 -19
- 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.
|
|
28
|
+
var version = "0.24.0";
|
|
29
29
|
|
|
30
30
|
// src/commands/auth.ts
|
|
31
31
|
import prompts from "prompts";
|
|
@@ -2187,6 +2187,77 @@ function registerTimeCommands(parent) {
|
|
|
2187
2187
|
});
|
|
2188
2188
|
}
|
|
2189
2189
|
|
|
2190
|
+
// src/lib/line-items.ts
|
|
2191
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
2192
|
+
import { InvalidArgumentError } from "commander";
|
|
2193
|
+
function parseLineItem(value) {
|
|
2194
|
+
const parts = value.split("|");
|
|
2195
|
+
if (parts.length < 2) {
|
|
2196
|
+
throw new Error(`Invalid --item "${value}". Use "description|quantity|rate" or "description|rate".`);
|
|
2197
|
+
}
|
|
2198
|
+
const num = (s, label) => {
|
|
2199
|
+
const n = Number(s.trim().replace(/^\$/, "").replace(/,/g, ""));
|
|
2200
|
+
if (s.trim() === "" || !Number.isFinite(n)) throw new Error(`Invalid ${label} "${s}" in --item "${value}"`);
|
|
2201
|
+
return n;
|
|
2202
|
+
};
|
|
2203
|
+
const rate = num(parts.pop(), "rate");
|
|
2204
|
+
let quantity = 1;
|
|
2205
|
+
if (parts.length >= 2) {
|
|
2206
|
+
const maybeQty = Number(parts[parts.length - 1].trim());
|
|
2207
|
+
if (parts[parts.length - 1].trim() !== "" && Number.isFinite(maybeQty)) {
|
|
2208
|
+
quantity = maybeQty;
|
|
2209
|
+
parts.pop();
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
const description = parts.join("|").trim();
|
|
2213
|
+
if (!description) throw new Error(`Missing description in --item "${value}"`);
|
|
2214
|
+
if (quantity <= 0) throw new Error(`Quantity must be greater than 0 in --item "${value}"`);
|
|
2215
|
+
return { description, quantity, rate };
|
|
2216
|
+
}
|
|
2217
|
+
function collectLineItem(value, previous = []) {
|
|
2218
|
+
try {
|
|
2219
|
+
return [...previous, parseLineItem(value)];
|
|
2220
|
+
} catch (e) {
|
|
2221
|
+
throw new InvalidArgumentError(e.message);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
async function readLineItemsFile(path) {
|
|
2225
|
+
let raw;
|
|
2226
|
+
if (path === "-") {
|
|
2227
|
+
const chunks = [];
|
|
2228
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
2229
|
+
raw = Buffer.concat(chunks).toString("utf8");
|
|
2230
|
+
} else {
|
|
2231
|
+
raw = readFileSync2(path, "utf8");
|
|
2232
|
+
}
|
|
2233
|
+
let parsed;
|
|
2234
|
+
try {
|
|
2235
|
+
parsed = JSON.parse(raw);
|
|
2236
|
+
} catch (e) {
|
|
2237
|
+
throw new Error(`Invalid JSON in ${path === "-" ? "stdin" : path}: ${e.message}`);
|
|
2238
|
+
}
|
|
2239
|
+
if (!Array.isArray(parsed)) throw new Error("--items must be a JSON array of {description, quantity, rate}");
|
|
2240
|
+
return parsed.map((item, i) => {
|
|
2241
|
+
if (!item || typeof item !== "object" || typeof item.description !== "string" || !item.description.trim()) {
|
|
2242
|
+
throw new Error(`--items[${i}] needs a description`);
|
|
2243
|
+
}
|
|
2244
|
+
if (item.rate != null && !Number.isFinite(Number(item.rate))) throw new Error(`--items[${i}] has an invalid rate`);
|
|
2245
|
+
if (item.quantity != null && !(Number(item.quantity) > 0)) throw new Error(`--items[${i}] needs a quantity greater than 0`);
|
|
2246
|
+
return {
|
|
2247
|
+
...item,
|
|
2248
|
+
quantity: item.quantity != null ? Number(item.quantity) : 1,
|
|
2249
|
+
rate: item.rate != null ? Number(item.rate) : 0
|
|
2250
|
+
};
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
async function resolveLineItems(opts) {
|
|
2254
|
+
const fromFile = opts.items ? await readLineItemsFile(opts.items) : [];
|
|
2255
|
+
const all = [...fromFile, ...opts.item ?? []];
|
|
2256
|
+
return all.length ? all : void 0;
|
|
2257
|
+
}
|
|
2258
|
+
var LINE_ITEM_HELP = 'line item "description|quantity|rate" or "description|rate" (repeatable)';
|
|
2259
|
+
var LINE_ITEMS_FILE_HELP = 'JSON array of line items [{description, quantity, rate}] (path, or "-" for stdin)';
|
|
2260
|
+
|
|
2190
2261
|
// src/commands/invoice.ts
|
|
2191
2262
|
function registerInvoiceCommands(parent) {
|
|
2192
2263
|
const cmd = parent.command("invoice").alias("invoices").description("Manage invoices");
|
|
@@ -2224,7 +2295,11 @@ function registerInvoiceCommands(parent) {
|
|
|
2224
2295
|
return;
|
|
2225
2296
|
}
|
|
2226
2297
|
});
|
|
2227
|
-
cmd.command("create").description("Create an invoice").requiredOption("-t, --title <title>", "invoice title (required)").option("-d, --description <text>").option("-a, --account <id>").option("--deal <id>", "deal this invoice bills against").option("--tax-rate <pct>", "tax rate %", 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>").
|
|
2298
|
+
cmd.command("create").description("Create an invoice").requiredOption("-t, --title <title>", "invoice title (required)").option("-d, --description <text>").option("-a, --account <id>").option("--deal <id>", "deal this invoice bills against").option("-i, --item <item>", LINE_ITEM_HELP, collectLineItem).option("--items <path>", LINE_ITEMS_FILE_HELP).option("--tax-rate <pct>", "tax rate %", 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>").addHelpText("after", `
|
|
2299
|
+
Examples:
|
|
2300
|
+
helm-ai invoice create -t "October retainer" -a <account-id> \\
|
|
2301
|
+
--item "Development|10|150" --item "Hosting|49"
|
|
2302
|
+
helm-ai invoice create -t "October retainer" -a <account-id> --items items.json`).action(async (opts) => {
|
|
2228
2303
|
try {
|
|
2229
2304
|
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2230
2305
|
const invoice = await client.invoices.create({
|
|
@@ -2232,6 +2307,7 @@ function registerInvoiceCommands(parent) {
|
|
|
2232
2307
|
description: opts.description,
|
|
2233
2308
|
account_id: opts.account,
|
|
2234
2309
|
deal_id: opts.deal,
|
|
2310
|
+
line_items: await resolveLineItems(opts),
|
|
2235
2311
|
tax_rate: opts.taxRate,
|
|
2236
2312
|
issue_date: opts.issueDate,
|
|
2237
2313
|
due_date: opts.dueDate,
|
|
@@ -2485,17 +2561,24 @@ function registerEstimateCommands(parent) {
|
|
|
2485
2561
|
return;
|
|
2486
2562
|
}
|
|
2487
2563
|
});
|
|
2488
|
-
cmd.command("create").description("Create an estimate").requiredOption("-t, --title <title>", "estimate title (required)").option("-d, --description <text>").option("-a, --account <id>").option("--tax-rate <pct>", "", parseFloat).option("--issue-date <date>").option("--expiry-date <date>").option("--notes <text>").option("-p, --profile <name>").
|
|
2564
|
+
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
|
+
Examples:
|
|
2566
|
+
helm-ai estimate create -t "Launch readiness" -a <account-id> \\
|
|
2567
|
+
--item "Checkout fixes|4|150" --item "Speed pass|500"
|
|
2568
|
+
helm-ai estimate create -t "Launch readiness" --items items.json`).action(async (opts) => {
|
|
2489
2569
|
try {
|
|
2490
2570
|
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2491
2571
|
const estimate = await client.estimates.create({
|
|
2492
2572
|
title: opts.title,
|
|
2493
2573
|
description: opts.description,
|
|
2494
2574
|
account_id: opts.account,
|
|
2575
|
+
contact_id: opts.contact,
|
|
2576
|
+
line_items: await resolveLineItems(opts),
|
|
2495
2577
|
tax_rate: opts.taxRate,
|
|
2496
2578
|
issue_date: opts.issueDate,
|
|
2497
2579
|
expiry_date: opts.expiryDate,
|
|
2498
|
-
notes: opts.notes
|
|
2580
|
+
notes: opts.notes,
|
|
2581
|
+
internal_notes: opts.internalNotes
|
|
2499
2582
|
});
|
|
2500
2583
|
console.log(JSON.stringify(estimate, null, 2));
|
|
2501
2584
|
} catch (err) {
|
|
@@ -2960,16 +3043,16 @@ function registerCalendarCommands(parent) {
|
|
|
2960
3043
|
}
|
|
2961
3044
|
|
|
2962
3045
|
// src/commands/doc.ts
|
|
2963
|
-
import { InvalidArgumentError } from "commander";
|
|
2964
|
-
import { readFileSync as
|
|
3046
|
+
import { InvalidArgumentError as InvalidArgumentError2 } from "commander";
|
|
3047
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
2965
3048
|
function readContent(opts) {
|
|
2966
|
-
if (opts.contentFile) return
|
|
2967
|
-
if (opts.content === "-") return
|
|
3049
|
+
if (opts.contentFile) return readFileSync3(opts.contentFile, "utf8");
|
|
3050
|
+
if (opts.content === "-") return readFileSync3(0, "utf8");
|
|
2968
3051
|
return opts.content;
|
|
2969
3052
|
}
|
|
2970
3053
|
function parsePosition(value) {
|
|
2971
3054
|
const n = Number(value);
|
|
2972
|
-
if (!Number.isInteger(n) || n < 0) throw new
|
|
3055
|
+
if (!Number.isInteger(n) || n < 0) throw new InvalidArgumentError2("must be a whole number, 0 or more");
|
|
2973
3056
|
return n;
|
|
2974
3057
|
}
|
|
2975
3058
|
function registerDocCommands(parent) {
|
|
@@ -3079,7 +3162,7 @@ function registerDocCommands(parent) {
|
|
|
3079
3162
|
].filter(([, address]) => address);
|
|
3080
3163
|
if (opts.editsFile) {
|
|
3081
3164
|
if (single.length) throw new Error("Use --edits-file or a single-edit flag, not both.");
|
|
3082
|
-
edits = JSON.parse(
|
|
3165
|
+
edits = JSON.parse(readFileSync3(opts.editsFile === "-" ? 0 : opts.editsFile, "utf8"));
|
|
3083
3166
|
if (!Array.isArray(edits)) throw new Error("--edits-file must contain a JSON array of edits.");
|
|
3084
3167
|
} else {
|
|
3085
3168
|
if (single.length !== 1) {
|
|
@@ -3337,11 +3420,11 @@ import ora from "ora";
|
|
|
3337
3420
|
import { writeFileSync as writeFileSync2 } from "fs";
|
|
3338
3421
|
|
|
3339
3422
|
// src/lib/csv.ts
|
|
3340
|
-
import { readFileSync as
|
|
3423
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
3341
3424
|
import { parse as parse2 } from "csv-parse/sync";
|
|
3342
3425
|
function readDataFile(path) {
|
|
3343
3426
|
const ext = path.toLowerCase().split(".").pop();
|
|
3344
|
-
const raw =
|
|
3427
|
+
const raw = readFileSync4(path, "utf8");
|
|
3345
3428
|
if (ext === "json") {
|
|
3346
3429
|
const data = JSON.parse(raw);
|
|
3347
3430
|
if (!Array.isArray(data)) throw new Error("JSON file must contain an array of objects");
|
|
@@ -3919,8 +4002,8 @@ async function readJsonSource(path) {
|
|
|
3919
4002
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
3920
4003
|
raw = Buffer.concat(chunks).toString("utf8");
|
|
3921
4004
|
} else {
|
|
3922
|
-
const { readFileSync:
|
|
3923
|
-
raw =
|
|
4005
|
+
const { readFileSync: readFileSync6 } = await import("fs");
|
|
4006
|
+
raw = readFileSync6(path, "utf8");
|
|
3924
4007
|
}
|
|
3925
4008
|
try {
|
|
3926
4009
|
return JSON.parse(raw);
|
|
@@ -4015,8 +4098,8 @@ function registerWorkflowCommands(parent) {
|
|
|
4015
4098
|
try {
|
|
4016
4099
|
let triggerData;
|
|
4017
4100
|
if (opts.dataFile) {
|
|
4018
|
-
const { readFileSync:
|
|
4019
|
-
triggerData = JSON.parse(
|
|
4101
|
+
const { readFileSync: readFileSync6 } = await import("fs");
|
|
4102
|
+
triggerData = JSON.parse(readFileSync6(opts.dataFile, "utf8"));
|
|
4020
4103
|
} else if (opts.data) {
|
|
4021
4104
|
triggerData = JSON.parse(opts.data);
|
|
4022
4105
|
}
|
|
@@ -4251,7 +4334,7 @@ Next: add emails with
|
|
|
4251
4334
|
}
|
|
4252
4335
|
|
|
4253
4336
|
// src/commands/email.ts
|
|
4254
|
-
import { readFileSync as
|
|
4337
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
4255
4338
|
function registerEmailCommands(parent) {
|
|
4256
4339
|
const cmd = parent.command("email").description("Draft and revise email from your own address");
|
|
4257
4340
|
cmd.command("identities").alias("addresses").description("List the addresses you can send from").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
@@ -4283,7 +4366,7 @@ function registerEmailCommands(parent) {
|
|
|
4283
4366
|
const splitAddrs = (v) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
4284
4367
|
let body = opts.body;
|
|
4285
4368
|
if (opts.bodyFile) {
|
|
4286
|
-
body =
|
|
4369
|
+
body = readFileSync5(opts.bodyFile === "-" ? 0 : opts.bodyFile, "utf8");
|
|
4287
4370
|
}
|
|
4288
4371
|
if (!body && !opts.html) {
|
|
4289
4372
|
throw new Error("--body, --body-file, or --html is required");
|
|
@@ -4344,7 +4427,7 @@ function registerEmailCommands(parent) {
|
|
|
4344
4427
|
const splitAddrs = (v) => v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
4345
4428
|
let body = opts.body;
|
|
4346
4429
|
if (opts.bodyFile) {
|
|
4347
|
-
body =
|
|
4430
|
+
body = readFileSync5(opts.bodyFile === "-" ? 0 : opts.bodyFile, "utf8");
|
|
4348
4431
|
}
|
|
4349
4432
|
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
4350
4433
|
const draft = await client.email.updateDraft({
|