@helm-ai/cli 0.21.0 → 0.22.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 +181 -1
- 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.22.0";
|
|
29
29
|
|
|
30
30
|
// src/commands/auth.ts
|
|
31
31
|
import prompts from "prompts";
|
|
@@ -410,6 +410,43 @@ var HelmClient = class _HelmClient {
|
|
|
410
410
|
return data.payment;
|
|
411
411
|
}
|
|
412
412
|
};
|
|
413
|
+
// Customer subscriptions -- the recurring revenue the workspace bills its own
|
|
414
|
+
// clients, not the workspace's own Helm plan.
|
|
415
|
+
subscriptions = {
|
|
416
|
+
list: async (filters = {}) => {
|
|
417
|
+
const data = await this.request("list_subscriptions", "GET", filters);
|
|
418
|
+
return data.subscriptions ?? [];
|
|
419
|
+
},
|
|
420
|
+
get: async (idOrStripeId) => {
|
|
421
|
+
const key = idOrStripeId.startsWith("sub_") ? "stripe_subscription_id" : "id";
|
|
422
|
+
const data = await this.request("get_subscription", "GET", { [key]: idOrStripeId });
|
|
423
|
+
return data.subscription;
|
|
424
|
+
},
|
|
425
|
+
mrr: async () => {
|
|
426
|
+
const data = await this.request("get_subscription_mrr", "GET", {});
|
|
427
|
+
return data.mrr;
|
|
428
|
+
},
|
|
429
|
+
create: async (input) => {
|
|
430
|
+
const data = await this.request("create_subscription", "POST", input);
|
|
431
|
+
return data;
|
|
432
|
+
},
|
|
433
|
+
cancel: async (id, immediately = false) => {
|
|
434
|
+
const data = await this.request("cancel_subscription", "POST", { id, immediately });
|
|
435
|
+
return data.subscription;
|
|
436
|
+
},
|
|
437
|
+
pause: async (id, resumes_at) => {
|
|
438
|
+
const data = await this.request("pause_subscription", "POST", { id, resumes_at });
|
|
439
|
+
return data.subscription;
|
|
440
|
+
},
|
|
441
|
+
resume: async (id) => {
|
|
442
|
+
const data = await this.request("resume_subscription", "POST", { id });
|
|
443
|
+
return data.subscription;
|
|
444
|
+
},
|
|
445
|
+
refresh: async (id) => {
|
|
446
|
+
const data = await this.request("refresh_subscription", "POST", { id });
|
|
447
|
+
return data.subscription;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
413
450
|
estimates = {
|
|
414
451
|
list: async (filters = {}) => {
|
|
415
452
|
const data = await this.request("get_estimates", "GET", filters);
|
|
@@ -2254,6 +2291,148 @@ function registerPaymentCommands(parent) {
|
|
|
2254
2291
|
});
|
|
2255
2292
|
}
|
|
2256
2293
|
|
|
2294
|
+
// src/commands/subscription.ts
|
|
2295
|
+
var INTERVAL_SHORT = { day: "day", week: "wk", month: "mo", year: "yr" };
|
|
2296
|
+
function money(cents, currency) {
|
|
2297
|
+
if (cents === null || cents === void 0) return "";
|
|
2298
|
+
return new Intl.NumberFormat("en-US", {
|
|
2299
|
+
style: "currency",
|
|
2300
|
+
currency: (currency || "usd").toUpperCase(),
|
|
2301
|
+
maximumFractionDigits: 2
|
|
2302
|
+
}).format(cents / 100);
|
|
2303
|
+
}
|
|
2304
|
+
function recurring(r) {
|
|
2305
|
+
const base = money(r.amount, r.currency);
|
|
2306
|
+
if (!r.billing_interval) return base;
|
|
2307
|
+
const n = r.interval_count && r.interval_count > 1 ? r.interval_count : 1;
|
|
2308
|
+
if (n > 1) return `${base}/${n}${INTERVAL_SHORT[r.billing_interval] ?? r.billing_interval}`;
|
|
2309
|
+
return `${base}/${INTERVAL_SHORT[r.billing_interval] ?? r.billing_interval}`;
|
|
2310
|
+
}
|
|
2311
|
+
function statusOf(r) {
|
|
2312
|
+
return r.cancel_at_period_end && r.status !== "canceled" ? `${r.status} (ending)` : r.status;
|
|
2313
|
+
}
|
|
2314
|
+
function registerSubscriptionCommands(parent) {
|
|
2315
|
+
const cmd = parent.command("subscription").alias("subscriptions").alias("sub").description("Recurring plans you bill your customers");
|
|
2316
|
+
cmd.command("list").description("List customer subscriptions").option("-s, --status <status>", "active|trialing|past_due|unpaid|canceled|incomplete|paused").option("--active", "only live revenue (active, trialing, past_due)").option("--origin <origin>", "helm|external \u2014 helm revenue is fee-bearing").option("-a, --account <id>").option("-c, --contact <id>").option("--product <id>").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2317
|
+
try {
|
|
2318
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2319
|
+
const rows = await client.subscriptions.list({
|
|
2320
|
+
status: opts.status,
|
|
2321
|
+
active_only: opts.active || void 0,
|
|
2322
|
+
origin: opts.origin,
|
|
2323
|
+
account_id: opts.account,
|
|
2324
|
+
contact_id: opts.contact,
|
|
2325
|
+
product_id: opts.product,
|
|
2326
|
+
limit: opts.limit
|
|
2327
|
+
});
|
|
2328
|
+
console.log(render(rows, [
|
|
2329
|
+
{ header: "Status", get: (r) => statusOf(r) },
|
|
2330
|
+
{ header: "Amount", get: (r) => recurring(r) },
|
|
2331
|
+
{ header: "Source", get: (r) => r.origin === "helm" ? "Helm" : "observed" },
|
|
2332
|
+
{ header: "Renews", get: (r) => r.current_period_end?.slice(0, 10) ?? "" },
|
|
2333
|
+
{ header: "Stripe", get: (r) => r.stripe_subscription_id, truncate: 20 },
|
|
2334
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2335
|
+
], opts.output ?? defaultFormat()));
|
|
2336
|
+
} catch (err) {
|
|
2337
|
+
console.error(formatErrorForCli(err));
|
|
2338
|
+
process.exitCode = 1;
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
cmd.command("mrr").description("Monthly recurring revenue, split by source").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2342
|
+
try {
|
|
2343
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2344
|
+
const mrr = await client.subscriptions.mrr();
|
|
2345
|
+
const format = opts.output ?? defaultFormat();
|
|
2346
|
+
if (format === "json") {
|
|
2347
|
+
console.log(JSON.stringify(mrr, null, 2));
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
console.log(`Through Helm ${money(mrr.helm_cents)}`);
|
|
2351
|
+
console.log(`Observed ${money(mrr.external_cents)}`);
|
|
2352
|
+
console.log(`Total ${money(mrr.total_cents)} (${mrr.count} live subscriptions)`);
|
|
2353
|
+
} catch (err) {
|
|
2354
|
+
console.error(formatErrorForCli(err));
|
|
2355
|
+
process.exitCode = 1;
|
|
2356
|
+
}
|
|
2357
|
+
});
|
|
2358
|
+
cmd.command("get <id>").description("Show one subscription (Helm id or Stripe sub_\u2026 id)").option("-o, --output <format>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2359
|
+
try {
|
|
2360
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2361
|
+
const sub = await client.subscriptions.get(id);
|
|
2362
|
+
console.log(JSON.stringify(sub, null, 2));
|
|
2363
|
+
} catch (err) {
|
|
2364
|
+
console.error(formatErrorForCli(err));
|
|
2365
|
+
process.exitCode = 1;
|
|
2366
|
+
}
|
|
2367
|
+
});
|
|
2368
|
+
cmd.command("create").description("Start billing a customer on a recurring schedule").requiredOption("-c, --contact <id>", "the person to bill (Stripe bills a person, not an account)").requiredOption("--product <id>", "a recurring product from your catalogue").option("--price <id>", "price tier on that product; omit to use its default price").option("-a, --account <id>", "account attribution; defaults to the contact's account").option("-q, --quantity <n>", "seats or units", (v) => parseInt(v, 10), 1).option("--trial <days>", "free trial length in days", (v) => parseInt(v, 10)).option("--checkout", "always return a payment link instead of charging a saved card").option("-p, --profile <name>").action(async (opts) => {
|
|
2369
|
+
try {
|
|
2370
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2371
|
+
const result = await client.subscriptions.create({
|
|
2372
|
+
contact_id: opts.contact,
|
|
2373
|
+
product_id: opts.product,
|
|
2374
|
+
product_price_id: opts.price,
|
|
2375
|
+
account_id: opts.account,
|
|
2376
|
+
quantity: opts.quantity,
|
|
2377
|
+
trial_days: opts.trial,
|
|
2378
|
+
method: opts.checkout ? "checkout" : "auto"
|
|
2379
|
+
});
|
|
2380
|
+
if (result.method === "checkout") {
|
|
2381
|
+
console.log("Send this link to the customer:");
|
|
2382
|
+
console.log(result.checkout_url);
|
|
2383
|
+
console.log("\nThe subscription appears in Helm once they complete payment.");
|
|
2384
|
+
} else {
|
|
2385
|
+
console.log(`\u2713 Subscription started (${result.subscription.stripe_subscription_id})`);
|
|
2386
|
+
}
|
|
2387
|
+
} catch (err) {
|
|
2388
|
+
console.error(formatErrorForCli(err));
|
|
2389
|
+
process.exitCode = 1;
|
|
2390
|
+
}
|
|
2391
|
+
});
|
|
2392
|
+
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) => {
|
|
2393
|
+
try {
|
|
2394
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2395
|
+
const sub = await client.subscriptions.cancel(id, !!opts.now);
|
|
2396
|
+
console.log(
|
|
2397
|
+
opts.now ? "\u2713 Cancelled" : `\u2713 Will end ${sub.current_period_end?.slice(0, 10) ?? "at the period end"}`
|
|
2398
|
+
);
|
|
2399
|
+
} catch (err) {
|
|
2400
|
+
console.error(formatErrorForCli(err));
|
|
2401
|
+
process.exitCode = 1;
|
|
2402
|
+
}
|
|
2403
|
+
});
|
|
2404
|
+
cmd.command("pause <id>").description("Pause collection without ending the subscription").option("--resumes <date>", "ISO date to resume automatically").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2405
|
+
try {
|
|
2406
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2407
|
+
await client.subscriptions.pause(id, opts.resumes);
|
|
2408
|
+
console.log("\u2713 Paused");
|
|
2409
|
+
} catch (err) {
|
|
2410
|
+
console.error(formatErrorForCli(err));
|
|
2411
|
+
process.exitCode = 1;
|
|
2412
|
+
}
|
|
2413
|
+
});
|
|
2414
|
+
cmd.command("resume <id>").description("Resume billing (undoes a pending cancellation or a pause)").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2415
|
+
try {
|
|
2416
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2417
|
+
await client.subscriptions.resume(id);
|
|
2418
|
+
console.log("\u2713 Resumed");
|
|
2419
|
+
} catch (err) {
|
|
2420
|
+
console.error(formatErrorForCli(err));
|
|
2421
|
+
process.exitCode = 1;
|
|
2422
|
+
}
|
|
2423
|
+
});
|
|
2424
|
+
cmd.command("refresh <id>").description("Re-read one subscription from Stripe and update Helm's copy").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2425
|
+
try {
|
|
2426
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2427
|
+
const sub = await client.subscriptions.refresh(id);
|
|
2428
|
+
console.log(`\u2713 Refreshed (${sub.status})`);
|
|
2429
|
+
} catch (err) {
|
|
2430
|
+
console.error(formatErrorForCli(err));
|
|
2431
|
+
process.exitCode = 1;
|
|
2432
|
+
}
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2257
2436
|
// src/commands/estimate.ts
|
|
2258
2437
|
function registerEstimateCommands(parent) {
|
|
2259
2438
|
const cmd = parent.command("estimate").alias("estimates").description("Manage estimates");
|
|
@@ -4085,6 +4264,7 @@ registerTaskCommands(program);
|
|
|
4085
4264
|
registerTimeCommands(program);
|
|
4086
4265
|
registerInvoiceCommands(program);
|
|
4087
4266
|
registerPaymentCommands(program);
|
|
4267
|
+
registerSubscriptionCommands(program);
|
|
4088
4268
|
registerEstimateCommands(program);
|
|
4089
4269
|
registerProductCommands(program);
|
|
4090
4270
|
registerFormCommands(program);
|