@helm-ai/cli 0.23.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.
- package/dist/cli.js +225 -28
- 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
|
|
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.
|
|
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 = {
|
|
@@ -2187,6 +2209,129 @@ function registerTimeCommands(parent) {
|
|
|
2187
2209
|
});
|
|
2188
2210
|
}
|
|
2189
2211
|
|
|
2212
|
+
// src/lib/line-items.ts
|
|
2213
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
2214
|
+
import { InvalidArgumentError } from "commander";
|
|
2215
|
+
function parseLineItem(value) {
|
|
2216
|
+
const parts = value.split("|");
|
|
2217
|
+
if (parts.length < 2) {
|
|
2218
|
+
throw new Error(`Invalid --item "${value}". Use "description|quantity|rate" or "description|rate".`);
|
|
2219
|
+
}
|
|
2220
|
+
const num = (s, label) => {
|
|
2221
|
+
const n = Number(s.trim().replace(/^\$/, "").replace(/,/g, ""));
|
|
2222
|
+
if (s.trim() === "" || !Number.isFinite(n)) throw new Error(`Invalid ${label} "${s}" in --item "${value}"`);
|
|
2223
|
+
return n;
|
|
2224
|
+
};
|
|
2225
|
+
const rate = num(parts.pop(), "rate");
|
|
2226
|
+
let quantity = 1;
|
|
2227
|
+
if (parts.length >= 2) {
|
|
2228
|
+
const maybeQty = Number(parts[parts.length - 1].trim());
|
|
2229
|
+
if (parts[parts.length - 1].trim() !== "" && Number.isFinite(maybeQty)) {
|
|
2230
|
+
quantity = maybeQty;
|
|
2231
|
+
parts.pop();
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
const description = parts.join("|").trim();
|
|
2235
|
+
if (!description) throw new Error(`Missing description in --item "${value}"`);
|
|
2236
|
+
if (quantity <= 0) throw new Error(`Quantity must be greater than 0 in --item "${value}"`);
|
|
2237
|
+
return { description, quantity, rate };
|
|
2238
|
+
}
|
|
2239
|
+
function collectLineItem(value, previous = []) {
|
|
2240
|
+
try {
|
|
2241
|
+
return [...previous, parseLineItem(value)];
|
|
2242
|
+
} catch (e) {
|
|
2243
|
+
throw new InvalidArgumentError(e.message);
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
async function readLineItemsFile(path) {
|
|
2247
|
+
let raw;
|
|
2248
|
+
if (path === "-") {
|
|
2249
|
+
const chunks = [];
|
|
2250
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
2251
|
+
raw = Buffer.concat(chunks).toString("utf8");
|
|
2252
|
+
} else {
|
|
2253
|
+
raw = readFileSync2(path, "utf8");
|
|
2254
|
+
}
|
|
2255
|
+
let parsed;
|
|
2256
|
+
try {
|
|
2257
|
+
parsed = JSON.parse(raw);
|
|
2258
|
+
} catch (e) {
|
|
2259
|
+
throw new Error(`Invalid JSON in ${path === "-" ? "stdin" : path}: ${e.message}`);
|
|
2260
|
+
}
|
|
2261
|
+
if (!Array.isArray(parsed)) throw new Error("--items must be a JSON array of {description, quantity, rate}");
|
|
2262
|
+
return parsed.map((item, i) => {
|
|
2263
|
+
if (!item || typeof item !== "object" || typeof item.description !== "string" || !item.description.trim()) {
|
|
2264
|
+
throw new Error(`--items[${i}] needs a description`);
|
|
2265
|
+
}
|
|
2266
|
+
if (item.rate != null && !Number.isFinite(Number(item.rate))) throw new Error(`--items[${i}] has an invalid rate`);
|
|
2267
|
+
if (item.quantity != null && !(Number(item.quantity) > 0)) throw new Error(`--items[${i}] needs a quantity greater than 0`);
|
|
2268
|
+
return {
|
|
2269
|
+
...item,
|
|
2270
|
+
quantity: item.quantity != null ? Number(item.quantity) : 1,
|
|
2271
|
+
rate: item.rate != null ? Number(item.rate) : 0
|
|
2272
|
+
};
|
|
2273
|
+
});
|
|
2274
|
+
}
|
|
2275
|
+
async function resolveLineItems(opts) {
|
|
2276
|
+
const fromFile = opts.items ? await readLineItemsFile(opts.items) : [];
|
|
2277
|
+
const all = [...fromFile, ...opts.item ?? []];
|
|
2278
|
+
return all.length ? all : void 0;
|
|
2279
|
+
}
|
|
2280
|
+
var LINE_ITEM_HELP = 'line item "description|quantity|rate" or "description|rate" (repeatable)';
|
|
2281
|
+
var LINE_ITEMS_FILE_HELP = 'JSON array of line items [{description, quantity, rate}] (path, or "-" for stdin)';
|
|
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
|
+
|
|
2190
2335
|
// src/commands/invoice.ts
|
|
2191
2336
|
function registerInvoiceCommands(parent) {
|
|
2192
2337
|
const cmd = parent.command("invoice").alias("invoices").description("Manage invoices");
|
|
@@ -2203,7 +2348,7 @@ function registerInvoiceCommands(parent) {
|
|
|
2203
2348
|
{ header: "Number", get: (r) => r.invoice_number },
|
|
2204
2349
|
{ header: "Title", get: (r) => r.title, truncate: 30 },
|
|
2205
2350
|
{ header: "Status", get: (r) => r.status },
|
|
2206
|
-
{ header: "Total", get: (r) => r.
|
|
2351
|
+
{ header: "Total", get: (r) => r.total_amount != null ? `$${Number(r.total_amount).toLocaleString()}` : "" },
|
|
2207
2352
|
{ header: "Due", get: (r) => r.due_date },
|
|
2208
2353
|
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2209
2354
|
], opts.output ?? defaultFormat()));
|
|
@@ -2224,7 +2369,11 @@ function registerInvoiceCommands(parent) {
|
|
|
2224
2369
|
return;
|
|
2225
2370
|
}
|
|
2226
2371
|
});
|
|
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>").
|
|
2372
|
+
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", `
|
|
2373
|
+
Examples:
|
|
2374
|
+
helm-ai invoice create -t "October retainer" -a <account-id> \\
|
|
2375
|
+
--item "Development|10|150" --item "Hosting|49"
|
|
2376
|
+
helm-ai invoice create -t "October retainer" -a <account-id> --items items.json`).action(async (opts) => {
|
|
2228
2377
|
try {
|
|
2229
2378
|
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2230
2379
|
const invoice = await client.invoices.create({
|
|
@@ -2232,6 +2381,7 @@ function registerInvoiceCommands(parent) {
|
|
|
2232
2381
|
description: opts.description,
|
|
2233
2382
|
account_id: opts.account,
|
|
2234
2383
|
deal_id: opts.deal,
|
|
2384
|
+
line_items: await resolveLineItems(opts),
|
|
2235
2385
|
tax_rate: opts.taxRate,
|
|
2236
2386
|
issue_date: opts.issueDate,
|
|
2237
2387
|
due_date: opts.dueDate,
|
|
@@ -2245,15 +2395,20 @@ function registerInvoiceCommands(parent) {
|
|
|
2245
2395
|
return;
|
|
2246
2396
|
}
|
|
2247
2397
|
});
|
|
2248
|
-
cmd.command("update <id>").description(
|
|
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) => {
|
|
2249
2399
|
try {
|
|
2250
2400
|
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2251
2401
|
const invoice = await client.invoices.update(id, {
|
|
2252
2402
|
title: opts.title,
|
|
2403
|
+
description: opts.description,
|
|
2253
2404
|
status: opts.status,
|
|
2405
|
+
account_id: opts.account,
|
|
2254
2406
|
deal_id: opts.deal,
|
|
2255
2407
|
tax_rate: opts.taxRate,
|
|
2256
|
-
|
|
2408
|
+
issue_date: opts.issueDate,
|
|
2409
|
+
due_date: opts.dueDate,
|
|
2410
|
+
notes: opts.notes,
|
|
2411
|
+
internal_notes: opts.internalNotes
|
|
2257
2412
|
});
|
|
2258
2413
|
console.log(JSON.stringify(invoice, null, 2));
|
|
2259
2414
|
} catch (err) {
|
|
@@ -2262,6 +2417,7 @@ function registerInvoiceCommands(parent) {
|
|
|
2262
2417
|
return;
|
|
2263
2418
|
}
|
|
2264
2419
|
});
|
|
2420
|
+
registerLineItemCommands(cmd, "invoice");
|
|
2265
2421
|
}
|
|
2266
2422
|
|
|
2267
2423
|
// src/commands/payment.ts
|
|
@@ -2475,7 +2631,7 @@ function registerEstimateCommands(parent) {
|
|
|
2475
2631
|
{ header: "Number", get: (r) => r.estimate_number },
|
|
2476
2632
|
{ header: "Title", get: (r) => r.title, truncate: 30 },
|
|
2477
2633
|
{ header: "Status", get: (r) => r.status },
|
|
2478
|
-
{ header: "Total", get: (r) => r.
|
|
2634
|
+
{ header: "Total", get: (r) => r.total_amount != null ? `$${Number(r.total_amount).toLocaleString()}` : "" },
|
|
2479
2635
|
{ header: "Expires", get: (r) => r.expiry_date },
|
|
2480
2636
|
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2481
2637
|
], opts.output ?? defaultFormat()));
|
|
@@ -2485,17 +2641,57 @@ function registerEstimateCommands(parent) {
|
|
|
2485
2641
|
return;
|
|
2486
2642
|
}
|
|
2487
2643
|
});
|
|
2488
|
-
cmd.command("
|
|
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
|
+
});
|
|
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", `
|
|
2656
|
+
Examples:
|
|
2657
|
+
helm-ai estimate create -t "Launch readiness" -a <account-id> \\
|
|
2658
|
+
--item "Checkout fixes|4|150" --item "Speed pass|500"
|
|
2659
|
+
helm-ai estimate create -t "Launch readiness" --items items.json`).action(async (opts) => {
|
|
2489
2660
|
try {
|
|
2490
2661
|
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2491
2662
|
const estimate = await client.estimates.create({
|
|
2492
2663
|
title: opts.title,
|
|
2493
2664
|
description: opts.description,
|
|
2494
2665
|
account_id: opts.account,
|
|
2666
|
+
contact_id: opts.contact,
|
|
2667
|
+
line_items: await resolveLineItems(opts),
|
|
2495
2668
|
tax_rate: opts.taxRate,
|
|
2496
2669
|
issue_date: opts.issueDate,
|
|
2497
2670
|
expiry_date: opts.expiryDate,
|
|
2498
|
-
notes: opts.notes
|
|
2671
|
+
notes: opts.notes,
|
|
2672
|
+
internal_notes: opts.internalNotes
|
|
2673
|
+
});
|
|
2674
|
+
console.log(JSON.stringify(estimate, null, 2));
|
|
2675
|
+
} catch (err) {
|
|
2676
|
+
console.error(formatErrorForCli(err));
|
|
2677
|
+
process.exitCode = 1;
|
|
2678
|
+
return;
|
|
2679
|
+
}
|
|
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
|
|
2499
2695
|
});
|
|
2500
2696
|
console.log(JSON.stringify(estimate, null, 2));
|
|
2501
2697
|
} catch (err) {
|
|
@@ -2504,6 +2700,7 @@ function registerEstimateCommands(parent) {
|
|
|
2504
2700
|
return;
|
|
2505
2701
|
}
|
|
2506
2702
|
});
|
|
2703
|
+
registerLineItemCommands(cmd, "estimate");
|
|
2507
2704
|
}
|
|
2508
2705
|
|
|
2509
2706
|
// src/commands/product.ts
|
|
@@ -2960,16 +3157,16 @@ function registerCalendarCommands(parent) {
|
|
|
2960
3157
|
}
|
|
2961
3158
|
|
|
2962
3159
|
// src/commands/doc.ts
|
|
2963
|
-
import { InvalidArgumentError } from "commander";
|
|
2964
|
-
import { readFileSync as
|
|
3160
|
+
import { InvalidArgumentError as InvalidArgumentError3 } from "commander";
|
|
3161
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
2965
3162
|
function readContent(opts) {
|
|
2966
|
-
if (opts.contentFile) return
|
|
2967
|
-
if (opts.content === "-") return
|
|
3163
|
+
if (opts.contentFile) return readFileSync3(opts.contentFile, "utf8");
|
|
3164
|
+
if (opts.content === "-") return readFileSync3(0, "utf8");
|
|
2968
3165
|
return opts.content;
|
|
2969
3166
|
}
|
|
2970
|
-
function
|
|
3167
|
+
function parsePosition2(value) {
|
|
2971
3168
|
const n = Number(value);
|
|
2972
|
-
if (!Number.isInteger(n) || n < 0) throw new
|
|
3169
|
+
if (!Number.isInteger(n) || n < 0) throw new InvalidArgumentError3("must be a whole number, 0 or more");
|
|
2973
3170
|
return n;
|
|
2974
3171
|
}
|
|
2975
3172
|
function registerDocCommands(parent) {
|
|
@@ -3079,7 +3276,7 @@ function registerDocCommands(parent) {
|
|
|
3079
3276
|
].filter(([, address]) => address);
|
|
3080
3277
|
if (opts.editsFile) {
|
|
3081
3278
|
if (single.length) throw new Error("Use --edits-file or a single-edit flag, not both.");
|
|
3082
|
-
edits = JSON.parse(
|
|
3279
|
+
edits = JSON.parse(readFileSync3(opts.editsFile === "-" ? 0 : opts.editsFile, "utf8"));
|
|
3083
3280
|
if (!Array.isArray(edits)) throw new Error("--edits-file must contain a JSON array of edits.");
|
|
3084
3281
|
} else {
|
|
3085
3282
|
if (single.length !== 1) {
|
|
@@ -3118,7 +3315,7 @@ function registerDocCommands(parent) {
|
|
|
3118
3315
|
return;
|
|
3119
3316
|
}
|
|
3120
3317
|
});
|
|
3121
|
-
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",
|
|
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) => {
|
|
3122
3319
|
try {
|
|
3123
3320
|
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3124
3321
|
const newPage = await client.documents.createPage(documentId, {
|
|
@@ -3134,7 +3331,7 @@ function registerDocCommands(parent) {
|
|
|
3134
3331
|
return;
|
|
3135
3332
|
}
|
|
3136
3333
|
});
|
|
3137
|
-
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",
|
|
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) => {
|
|
3138
3335
|
try {
|
|
3139
3336
|
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3140
3337
|
const updated = await client.documents.updatePage(documentId, pageId, {
|
|
@@ -3337,11 +3534,11 @@ import ora from "ora";
|
|
|
3337
3534
|
import { writeFileSync as writeFileSync2 } from "fs";
|
|
3338
3535
|
|
|
3339
3536
|
// src/lib/csv.ts
|
|
3340
|
-
import { readFileSync as
|
|
3537
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
3341
3538
|
import { parse as parse2 } from "csv-parse/sync";
|
|
3342
3539
|
function readDataFile(path) {
|
|
3343
3540
|
const ext = path.toLowerCase().split(".").pop();
|
|
3344
|
-
const raw =
|
|
3541
|
+
const raw = readFileSync4(path, "utf8");
|
|
3345
3542
|
if (ext === "json") {
|
|
3346
3543
|
const data = JSON.parse(raw);
|
|
3347
3544
|
if (!Array.isArray(data)) throw new Error("JSON file must contain an array of objects");
|
|
@@ -3919,8 +4116,8 @@ async function readJsonSource(path) {
|
|
|
3919
4116
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
3920
4117
|
raw = Buffer.concat(chunks).toString("utf8");
|
|
3921
4118
|
} else {
|
|
3922
|
-
const { readFileSync:
|
|
3923
|
-
raw =
|
|
4119
|
+
const { readFileSync: readFileSync6 } = await import("fs");
|
|
4120
|
+
raw = readFileSync6(path, "utf8");
|
|
3924
4121
|
}
|
|
3925
4122
|
try {
|
|
3926
4123
|
return JSON.parse(raw);
|
|
@@ -4015,8 +4212,8 @@ function registerWorkflowCommands(parent) {
|
|
|
4015
4212
|
try {
|
|
4016
4213
|
let triggerData;
|
|
4017
4214
|
if (opts.dataFile) {
|
|
4018
|
-
const { readFileSync:
|
|
4019
|
-
triggerData = JSON.parse(
|
|
4215
|
+
const { readFileSync: readFileSync6 } = await import("fs");
|
|
4216
|
+
triggerData = JSON.parse(readFileSync6(opts.dataFile, "utf8"));
|
|
4020
4217
|
} else if (opts.data) {
|
|
4021
4218
|
triggerData = JSON.parse(opts.data);
|
|
4022
4219
|
}
|
|
@@ -4251,7 +4448,7 @@ Next: add emails with
|
|
|
4251
4448
|
}
|
|
4252
4449
|
|
|
4253
4450
|
// src/commands/email.ts
|
|
4254
|
-
import { readFileSync as
|
|
4451
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
4255
4452
|
function registerEmailCommands(parent) {
|
|
4256
4453
|
const cmd = parent.command("email").description("Draft and revise email from your own address");
|
|
4257
4454
|
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 +4480,7 @@ function registerEmailCommands(parent) {
|
|
|
4283
4480
|
const splitAddrs = (v) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
4284
4481
|
let body = opts.body;
|
|
4285
4482
|
if (opts.bodyFile) {
|
|
4286
|
-
body =
|
|
4483
|
+
body = readFileSync5(opts.bodyFile === "-" ? 0 : opts.bodyFile, "utf8");
|
|
4287
4484
|
}
|
|
4288
4485
|
if (!body && !opts.html) {
|
|
4289
4486
|
throw new Error("--body, --body-file, or --html is required");
|
|
@@ -4344,7 +4541,7 @@ function registerEmailCommands(parent) {
|
|
|
4344
4541
|
const splitAddrs = (v) => v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
4345
4542
|
let body = opts.body;
|
|
4346
4543
|
if (opts.bodyFile) {
|
|
4347
|
-
body =
|
|
4544
|
+
body = readFileSync5(opts.bodyFile === "-" ? 0 : opts.bodyFile, "utf8");
|
|
4348
4545
|
}
|
|
4349
4546
|
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
4350
4547
|
const draft = await client.email.updateDraft({
|
|
@@ -4383,7 +4580,7 @@ function registerEmailCommands(parent) {
|
|
|
4383
4580
|
}
|
|
4384
4581
|
|
|
4385
4582
|
// src/cli.ts
|
|
4386
|
-
var program = new
|
|
4583
|
+
var program = new Command3();
|
|
4387
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 }) : "");
|
|
4388
4585
|
registerAuthCommands(program);
|
|
4389
4586
|
registerProfileCommands(program);
|