commet 1.2.1 → 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 (2) hide show
  1. package/dist/index.js +82 -21
  2. package/package.json +1 -1
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.0",
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,20 @@ 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(
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
+ }
387
422
  function linkProject(dest, orgId, orgName, environment) {
388
423
  const commetDir = path2.join(dest, ".commet");
389
424
  fs2.mkdirSync(commetDir, { recursive: true });
@@ -395,7 +430,7 @@ function linkProject(dest, orgId, orgName, environment) {
395
430
  }
396
431
  var createCommand = new import_commander.Command("create").description("Create a new Commet app from a template").argument("[name]", "Project name").option(
397
432
  "-t, --template <template>",
398
- "Template to use (fixed, seats, credits, usage-based)"
433
+ "Template to use (fixed, seats, metered, credits, balance-ai, balance-fixed)"
399
434
  ).option("--ref <ref>", "Git ref to fetch templates from", "main").option("--list", "List available templates").action(async (argName, opts) => {
400
435
  if (opts.list) {
401
436
  console.log(import_chalk3.default.bold("\nAvailable templates:\n"));
@@ -452,6 +487,17 @@ var createCommand = new import_commander.Command("create").description("Create a
452
487
  }
453
488
  const auth = loadAuth();
454
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
+ }
455
501
  const orgsSpinner = (0, import_ora2.default)("Fetching organizations...").start();
456
502
  const orgsResult = await apiRequest(`${baseURL}/api/cli/organizations`);
457
503
  if (orgsResult.error || !orgsResult.data) {
@@ -543,6 +589,22 @@ var createCommand = new import_commander.Command("create").description("Create a
543
589
  `Created ${templateResult.data.plansCreated} plans and ${templateResult.data.featuresCreated} features`
544
590
  );
545
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
+ }
546
608
  linkProject(dest, selectedOrg.id, selectedOrg.name, auth.environment);
547
609
  console.log(import_chalk3.default.green(`
548
610
  \u2713 Created ${projectName}`));
@@ -550,7 +612,6 @@ var createCommand = new import_commander.Command("create").description("Create a
550
612
  console.log(import_chalk3.default.dim(` Organization: ${selectedOrg.name}`));
551
613
  console.log();
552
614
  console.log(` ${import_chalk3.default.cyan("cd")} ${projectName}`);
553
- console.log(` ${import_chalk3.default.dim("Update .env with your keys")}`);
554
615
  console.log(` ${import_chalk3.default.cyan("npm install")}`);
555
616
  console.log(` ${import_chalk3.default.cyan("npm run dev")}`);
556
617
  console.log();
@@ -683,7 +744,7 @@ var linkCommand = new import_commander3.Command("link").description("Link this p
683
744
  })),
684
745
  theme: promptTheme
685
746
  });
686
- } catch (error) {
747
+ } catch (_error) {
687
748
  console.log(import_chalk5.default.yellow("\n\u26A0 Link cancelled"));
688
749
  return;
689
750
  }
@@ -895,7 +956,7 @@ function validateTypeScriptProject() {
895
956
  const content = fs4.readFileSync(tsconfigPath, "utf8");
896
957
  JSON.parse(content);
897
958
  return true;
898
- } catch (error) {
959
+ } catch (_error) {
899
960
  return false;
900
961
  }
901
962
  }
@@ -1126,7 +1187,7 @@ var switchCommand = new import_commander8.Command("switch").description("Switch
1126
1187
  })),
1127
1188
  theme: promptTheme
1128
1189
  });
1129
- } catch (error) {
1190
+ } catch (_error) {
1130
1191
  console.log(import_chalk10.default.yellow("\n\u26A0 Switch cancelled"));
1131
1192
  return;
1132
1193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commet",
3
- "version": "1.2.1",
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"