commet 1.2.0 → 1.3.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 (3) hide show
  1. package/README.md +4 -4
  2. package/dist/index.js +71 -19
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <p>CLI for Commet billing platform</p>
9
9
 
10
10
  <a href="https://www.npmjs.com/package/commet"><img alt="NPM version" src="https://img.shields.io/npm/v/commet.svg?style=for-the-badge&labelColor=000000"></a>
11
- <a href="https://commet.co/docs/library/cli/overview"><img alt="Documentation" src="https://img.shields.io/badge/docs-CLI-blue.svg?style=for-the-badge&labelColor=000000"></a>
11
+ <a href="https://commet.co/docs"><img alt="Documentation" src="https://img.shields.io/badge/docs-CLI-blue.svg?style=for-the-badge&labelColor=000000"></a>
12
12
  </div>
13
13
 
14
14
  <br/>
@@ -68,7 +68,7 @@ commet list plans # List plans
68
68
 
69
69
  ## Documentation
70
70
 
71
- Visit [commet.co/docs/library/cli/overview](https://commet.co/docs/library/cli/overview) for:
71
+ Visit [commet.co/docs](https://commet.co/docs) for:
72
72
 
73
73
  - Complete command reference
74
74
  - Configuration guide
@@ -77,8 +77,8 @@ Visit [commet.co/docs/library/cli/overview](https://commet.co/docs/library/cli/o
77
77
 
78
78
  ## Resources
79
79
 
80
- - [CLI Documentation](https://commet.co/docs/library/cli/overview)
81
- - [SDK Reference](https://commet.co/docs/library/quickstart)
80
+ - [CLI Documentation](https://commet.co/docs)
81
+ - [SDK Reference](https://commet.co/docs)
82
82
  - [GitHub](https://github.com/commet-labs/commet)
83
83
  - [Issues](https://github.com/commet-labs/commet/issues)
84
84
 
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ var import_commander11 = require("commander");
30
30
  // package.json
31
31
  var package_default = {
32
32
  name: "commet",
33
- version: "1.2.0",
33
+ version: "1.3.0",
34
34
  description: "Commet CLI - Manage your billing platform from the command line",
35
35
  bin: {
36
36
  commet: "./bin/commet"
@@ -324,27 +324,39 @@ var GITHUB_REPO = "commet-labs/commet";
324
324
  var TEMPLATES = [
325
325
  {
326
326
  name: "fixed",
327
- dir: "fixed-saas",
328
- templateId: "fixed-saas",
329
- description: "Fixed subscriptions (monthly/yearly plans)"
327
+ dir: "fixed",
328
+ templateId: "fixed",
329
+ description: "Fixed subscriptions with boolean features"
330
330
  },
331
331
  {
332
332
  name: "seats",
333
- dir: "team-saas",
334
- templateId: "seat-based-saas",
335
- 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"
336
342
  },
337
343
  {
338
344
  name: "credits",
339
- dir: "credits-saas",
340
- templateId: "credits-saas",
341
- 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"
342
354
  },
343
355
  {
344
- name: "usage-based",
345
- dir: "usage-based-saas",
346
- templateId: "usage-based-saas",
347
- 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"
348
360
  }
349
361
  ];
350
362
  async function downloadTemplate(templateDir, dest, ref) {
@@ -393,6 +405,20 @@ function copyEnvExample(dest) {
393
405
  fs2.copyFileSync(examplePath, envPath);
394
406
  }
395
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(
413
+ /COMMET_API_KEY=.*/,
414
+ `COMMET_API_KEY=${apiKey}`
415
+ );
416
+ content = content.replace(
417
+ /COMMET_ENVIRONMENT=.*/,
418
+ `COMMET_ENVIRONMENT=${environment}`
419
+ );
420
+ fs2.writeFileSync(envPath, content);
421
+ }
396
422
  function linkProject(dest, orgId, orgName, environment) {
397
423
  const commetDir = path2.join(dest, ".commet");
398
424
  fs2.mkdirSync(commetDir, { recursive: true });
@@ -404,7 +430,7 @@ function linkProject(dest, orgId, orgName, environment) {
404
430
  }
405
431
  var createCommand = new import_commander.Command("create").description("Create a new Commet app from a template").argument("[name]", "Project name").option(
406
432
  "-t, --template <template>",
407
- "Template to use (fixed, seats, credits, usage-based)"
433
+ "Template to use (fixed, seats, metered, credits, balance-ai, balance-fixed)"
408
434
  ).option("--ref <ref>", "Git ref to fetch templates from", "main").option("--list", "List available templates").action(async (argName, opts) => {
409
435
  if (opts.list) {
410
436
  console.log(import_chalk3.default.bold("\nAvailable templates:\n"));
@@ -461,6 +487,17 @@ var createCommand = new import_commander.Command("create").description("Create a
461
487
  }
462
488
  const auth = loadAuth();
463
489
  const baseURL = getBaseURL(auth.environment);
490
+ if (auth.environment !== "sandbox") {
491
+ console.log(
492
+ import_chalk3.default.red(
493
+ "\u2717 `commet create` is only available in sandbox environment"
494
+ )
495
+ );
496
+ console.log(
497
+ import_chalk3.default.dim("Run `commet logout` and login to sandbox to use templates")
498
+ );
499
+ return;
500
+ }
464
501
  const orgsSpinner = (0, import_ora2.default)("Fetching organizations...").start();
465
502
  const orgsResult = await apiRequest(`${baseURL}/api/cli/organizations`);
466
503
  if (orgsResult.error || !orgsResult.data) {
@@ -552,6 +589,22 @@ var createCommand = new import_commander.Command("create").description("Create a
552
589
  `Created ${templateResult.data.plansCreated} plans and ${templateResult.data.featuresCreated} features`
553
590
  );
554
591
  }
592
+ const keySpinner = (0, import_ora2.default)("Creating API key...").start();
593
+ const keyResult = await apiRequest(`${baseURL}/api/cli/api-keys`, {
594
+ method: "POST",
595
+ body: JSON.stringify({
596
+ organizationId: selectedOrg.id,
597
+ name: `${template.name} (CLI)`
598
+ })
599
+ });
600
+ if (keyResult.error || !keyResult.data) {
601
+ keySpinner.fail("Failed to create API key");
602
+ console.log(import_chalk3.default.dim(keyResult.error));
603
+ console.log(import_chalk3.default.dim("You can create one manually in the dashboard"));
604
+ } else {
605
+ writeApiKeyToEnv(dest, keyResult.data.apiKey, auth.environment);
606
+ keySpinner.succeed("API key created and saved to .env");
607
+ }
555
608
  linkProject(dest, selectedOrg.id, selectedOrg.name, auth.environment);
556
609
  console.log(import_chalk3.default.green(`
557
610
  \u2713 Created ${projectName}`));
@@ -559,7 +612,6 @@ var createCommand = new import_commander.Command("create").description("Create a
559
612
  console.log(import_chalk3.default.dim(` Organization: ${selectedOrg.name}`));
560
613
  console.log();
561
614
  console.log(` ${import_chalk3.default.cyan("cd")} ${projectName}`);
562
- console.log(` ${import_chalk3.default.dim("Update .env with your keys")}`);
563
615
  console.log(` ${import_chalk3.default.cyan("npm install")}`);
564
616
  console.log(` ${import_chalk3.default.cyan("npm run dev")}`);
565
617
  console.log();
@@ -692,7 +744,7 @@ var linkCommand = new import_commander3.Command("link").description("Link this p
692
744
  })),
693
745
  theme: promptTheme
694
746
  });
695
- } catch (error) {
747
+ } catch (_error) {
696
748
  console.log(import_chalk5.default.yellow("\n\u26A0 Link cancelled"));
697
749
  return;
698
750
  }
@@ -904,7 +956,7 @@ function validateTypeScriptProject() {
904
956
  const content = fs4.readFileSync(tsconfigPath, "utf8");
905
957
  JSON.parse(content);
906
958
  return true;
907
- } catch (error) {
959
+ } catch (_error) {
908
960
  return false;
909
961
  }
910
962
  }
@@ -1135,7 +1187,7 @@ var switchCommand = new import_commander8.Command("switch").description("Switch
1135
1187
  })),
1136
1188
  theme: promptTheme
1137
1189
  });
1138
- } catch (error) {
1190
+ } catch (_error) {
1139
1191
  console.log(import_chalk10.default.yellow("\n\u26A0 Switch cancelled"));
1140
1192
  return;
1141
1193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commet",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Commet CLI - Manage your billing platform from the command line",
5
5
  "bin": {
6
6
  "commet": "./bin/commet"