commet 1.2.1 → 1.3.1

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 (3) hide show
  1. package/README.md +2 -0
  2. package/dist/index.js +79 -21
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -13,6 +13,8 @@
13
13
 
14
14
  <br/>
15
15
 
16
+ Manage your [Commet](https://commet.co) project from the terminal. Link to your organization, generate TypeScript types for autocomplete on plan codes and feature codes, and inspect your billing setup.
17
+
16
18
  ## Installation
17
19
 
18
20
  ```bash
package/dist/index.js CHANGED
@@ -30,12 +30,16 @@ var import_commander11 = require("commander");
30
30
  // package.json
31
31
  var package_default = {
32
32
  name: "commet",
33
- version: "1.2.1",
33
+ version: "1.3.1",
34
34
  description: "Commet CLI - Manage your billing platform from the command line",
35
35
  bin: {
36
36
  commet: "./bin/commet"
37
37
  },
38
- files: ["dist", "bin", "README.md"],
38
+ files: [
39
+ "dist",
40
+ "bin",
41
+ "README.md"
42
+ ],
39
43
  scripts: {
40
44
  build: "tsup",
41
45
  dev: "tsup --watch",
@@ -43,7 +47,12 @@ var package_default = {
43
47
  "lint:fix": "biome lint --write src/",
44
48
  typecheck: "tsc --noEmit"
45
49
  },
46
- keywords: ["billing", "cli", "typescript", "commet"],
50
+ keywords: [
51
+ "billing",
52
+ "cli",
53
+ "typescript",
54
+ "commet"
55
+ ],
47
56
  author: "Commet Team",
48
57
  license: "MIT",
49
58
  dependencies: {
@@ -315,27 +324,39 @@ var GITHUB_REPO = "commet-labs/commet";
315
324
  var TEMPLATES = [
316
325
  {
317
326
  name: "fixed",
318
- dir: "fixed-saas",
319
- templateId: "fixed-saas",
320
- description: "Fixed subscriptions (monthly/yearly plans)"
327
+ dir: "fixed",
328
+ templateId: "fixed",
329
+ description: "Fixed subscriptions with boolean features"
321
330
  },
322
331
  {
323
332
  name: "seats",
324
- dir: "team-saas",
325
- templateId: "seat-based-saas",
326
- description: "Seat-based billing (per team member)"
333
+ dir: "seats",
334
+ templateId: "seats",
335
+ description: "Per-seat billing for team collaboration"
336
+ },
337
+ {
338
+ name: "metered",
339
+ dir: "metered",
340
+ templateId: "metered",
341
+ description: "Usage-based billing with included amounts and overage"
327
342
  },
328
343
  {
329
344
  name: "credits",
330
- dir: "credits-saas",
331
- templateId: "credits-saas",
332
- description: "Credit-based billing (prepaid usage blocks)"
345
+ dir: "credits",
346
+ templateId: "credits",
347
+ description: "Credit-based consumption with packs and top-ups"
348
+ },
349
+ {
350
+ name: "balance-ai",
351
+ dir: "balance-ai",
352
+ templateId: "balance-ai",
353
+ description: "AI product with automatic token cost tracking and margin"
333
354
  },
334
355
  {
335
- name: "usage-based",
336
- dir: "usage-based-saas",
337
- templateId: "usage-based-saas",
338
- description: "Usage-based billing (metered, pay for what you use)"
356
+ name: "balance-fixed",
357
+ dir: "balance-fixed",
358
+ templateId: "balance-fixed",
359
+ description: "Prepaid balance with fixed unit prices"
339
360
  }
340
361
  ];
341
362
  async function downloadTemplate(templateDir, dest, ref) {
@@ -384,6 +405,17 @@ function copyEnvExample(dest) {
384
405
  fs2.copyFileSync(examplePath, envPath);
385
406
  }
386
407
  }
408
+ function writeApiKeyToEnv(dest, apiKey, environment) {
409
+ const envPath = path2.join(dest, ".env");
410
+ if (!fs2.existsSync(envPath)) return;
411
+ let content = fs2.readFileSync(envPath, "utf-8");
412
+ content = content.replace(/COMMET_API_KEY=.*/, `COMMET_API_KEY=${apiKey}`);
413
+ content = content.replace(
414
+ /COMMET_ENVIRONMENT=.*/,
415
+ `COMMET_ENVIRONMENT=${environment}`
416
+ );
417
+ fs2.writeFileSync(envPath, content);
418
+ }
387
419
  function linkProject(dest, orgId, orgName, environment) {
388
420
  const commetDir = path2.join(dest, ".commet");
389
421
  fs2.mkdirSync(commetDir, { recursive: true });
@@ -395,7 +427,7 @@ function linkProject(dest, orgId, orgName, environment) {
395
427
  }
396
428
  var createCommand = new import_commander.Command("create").description("Create a new Commet app from a template").argument("[name]", "Project name").option(
397
429
  "-t, --template <template>",
398
- "Template to use (fixed, seats, credits, usage-based)"
430
+ "Template to use (fixed, seats, metered, credits, balance-ai, balance-fixed)"
399
431
  ).option("--ref <ref>", "Git ref to fetch templates from", "main").option("--list", "List available templates").action(async (argName, opts) => {
400
432
  if (opts.list) {
401
433
  console.log(import_chalk3.default.bold("\nAvailable templates:\n"));
@@ -452,6 +484,17 @@ var createCommand = new import_commander.Command("create").description("Create a
452
484
  }
453
485
  const auth = loadAuth();
454
486
  const baseURL = getBaseURL(auth.environment);
487
+ if (auth.environment !== "sandbox") {
488
+ console.log(
489
+ import_chalk3.default.red(
490
+ "\u2717 `commet create` is only available in sandbox environment"
491
+ )
492
+ );
493
+ console.log(
494
+ import_chalk3.default.dim("Run `commet logout` and login to sandbox to use templates")
495
+ );
496
+ return;
497
+ }
455
498
  const orgsSpinner = (0, import_ora2.default)("Fetching organizations...").start();
456
499
  const orgsResult = await apiRequest(`${baseURL}/api/cli/organizations`);
457
500
  if (orgsResult.error || !orgsResult.data) {
@@ -543,6 +586,22 @@ var createCommand = new import_commander.Command("create").description("Create a
543
586
  `Created ${templateResult.data.plansCreated} plans and ${templateResult.data.featuresCreated} features`
544
587
  );
545
588
  }
589
+ const keySpinner = (0, import_ora2.default)("Creating API key...").start();
590
+ const keyResult = await apiRequest(`${baseURL}/api/cli/api-keys`, {
591
+ method: "POST",
592
+ body: JSON.stringify({
593
+ organizationId: selectedOrg.id,
594
+ name: `${template.name} (CLI)`
595
+ })
596
+ });
597
+ if (keyResult.error || !keyResult.data) {
598
+ keySpinner.fail("Failed to create API key");
599
+ console.log(import_chalk3.default.dim(keyResult.error));
600
+ console.log(import_chalk3.default.dim("You can create one manually in the dashboard"));
601
+ } else {
602
+ writeApiKeyToEnv(dest, keyResult.data.apiKey, auth.environment);
603
+ keySpinner.succeed("API key created and saved to .env");
604
+ }
546
605
  linkProject(dest, selectedOrg.id, selectedOrg.name, auth.environment);
547
606
  console.log(import_chalk3.default.green(`
548
607
  \u2713 Created ${projectName}`));
@@ -550,7 +609,6 @@ var createCommand = new import_commander.Command("create").description("Create a
550
609
  console.log(import_chalk3.default.dim(` Organization: ${selectedOrg.name}`));
551
610
  console.log();
552
611
  console.log(` ${import_chalk3.default.cyan("cd")} ${projectName}`);
553
- console.log(` ${import_chalk3.default.dim("Update .env with your keys")}`);
554
612
  console.log(` ${import_chalk3.default.cyan("npm install")}`);
555
613
  console.log(` ${import_chalk3.default.cyan("npm run dev")}`);
556
614
  console.log();
@@ -683,7 +741,7 @@ var linkCommand = new import_commander3.Command("link").description("Link this p
683
741
  })),
684
742
  theme: promptTheme
685
743
  });
686
- } catch (error) {
744
+ } catch (_error) {
687
745
  console.log(import_chalk5.default.yellow("\n\u26A0 Link cancelled"));
688
746
  return;
689
747
  }
@@ -895,7 +953,7 @@ function validateTypeScriptProject() {
895
953
  const content = fs4.readFileSync(tsconfigPath, "utf8");
896
954
  JSON.parse(content);
897
955
  return true;
898
- } catch (error) {
956
+ } catch (_error) {
899
957
  return false;
900
958
  }
901
959
  }
@@ -1126,7 +1184,7 @@ var switchCommand = new import_commander8.Command("switch").description("Switch
1126
1184
  })),
1127
1185
  theme: promptTheme
1128
1186
  });
1129
- } catch (error) {
1187
+ } catch (_error) {
1130
1188
  console.log(import_chalk10.default.yellow("\n\u26A0 Switch cancelled"));
1131
1189
  return;
1132
1190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commet",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "Commet CLI - Manage your billing platform from the command line",
5
5
  "bin": {
6
6
  "commet": "./bin/commet"