@barekey/cli 0.3.3 → 0.5.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 (63) hide show
  1. package/README.md +53 -12
  2. package/bun.lock +9 -3
  3. package/dist/auth-provider.js +7 -4
  4. package/dist/command-utils.d.ts +1 -1
  5. package/dist/command-utils.js +7 -6
  6. package/dist/commands/audit.d.ts +2 -0
  7. package/dist/commands/audit.js +47 -0
  8. package/dist/commands/auth.js +22 -7
  9. package/dist/commands/billing.d.ts +2 -0
  10. package/dist/commands/billing.js +62 -0
  11. package/dist/commands/env.js +158 -98
  12. package/dist/commands/init.d.ts +2 -0
  13. package/dist/commands/init.js +32 -0
  14. package/dist/commands/org.d.ts +2 -0
  15. package/dist/commands/org.js +85 -0
  16. package/dist/commands/project.d.ts +2 -0
  17. package/dist/commands/project.js +99 -0
  18. package/dist/commands/stage.d.ts +2 -0
  19. package/dist/commands/stage.js +125 -0
  20. package/dist/commands/target-prompts.d.ts +184 -0
  21. package/dist/commands/target-prompts.js +312 -0
  22. package/dist/commands/typegen.d.ts +2 -2
  23. package/dist/commands/typegen.js +61 -22
  24. package/dist/constants.d.ts +1 -1
  25. package/dist/constants.js +1 -1
  26. package/dist/context/session-id.d.ts +11 -0
  27. package/dist/context/session-id.js +14 -0
  28. package/dist/contracts/index.d.ts +491 -0
  29. package/dist/contracts/index.js +307 -0
  30. package/dist/credentials-store.js +70 -11
  31. package/dist/http.d.ts +34 -0
  32. package/dist/http.js +56 -2
  33. package/dist/index.js +12 -0
  34. package/dist/runtime-config.d.ts +4 -0
  35. package/dist/runtime-config.js +16 -11
  36. package/dist/typegen/core.d.ts +45 -0
  37. package/dist/typegen/core.js +219 -0
  38. package/dist/types.d.ts +5 -3
  39. package/package.json +2 -2
  40. package/src/auth-provider.ts +8 -5
  41. package/src/command-utils.ts +8 -7
  42. package/src/commands/audit.ts +63 -0
  43. package/src/commands/auth.ts +32 -37
  44. package/src/commands/billing.ts +73 -0
  45. package/src/commands/env.ts +215 -189
  46. package/src/commands/init.ts +47 -0
  47. package/src/commands/org.ts +104 -0
  48. package/src/commands/project.ts +130 -0
  49. package/src/commands/stage.ts +167 -0
  50. package/src/commands/target-prompts.ts +357 -0
  51. package/src/commands/typegen.ts +75 -29
  52. package/src/constants.ts +1 -1
  53. package/src/context/session-id.ts +14 -0
  54. package/src/contracts/index.ts +370 -0
  55. package/src/credentials-store.ts +86 -12
  56. package/src/http.ts +78 -2
  57. package/src/index.ts +12 -0
  58. package/src/runtime-config.ts +25 -14
  59. package/src/typegen/core.ts +311 -0
  60. package/src/types.ts +5 -3
  61. package/test/command-utils.test.ts +47 -0
  62. package/test/credentials-store.test.ts +40 -0
  63. package/test/runtime-config.test.ts +125 -0
@@ -0,0 +1,73 @@
1
+ import { Command } from "commander";
2
+
3
+ import { createCliAuthProvider } from "../auth-provider.js";
4
+ import { requireLocalSession, toJsonOutput, type EnvTargetOptions } from "../command-utils.js";
5
+ import { BillingCatalogResponseSchema, BillingStatusResponseSchema } from "../contracts/index.js";
6
+ import { getJson, postJson } from "../http.js";
7
+ import { promptForOrganizationSlug } from "./target-prompts.js";
8
+
9
+ async function runBillingCatalog(options: { json?: boolean }) {
10
+ const local = await requireLocalSession();
11
+ const authProvider = createCliAuthProvider();
12
+ const accessToken = await authProvider.getAccessToken();
13
+ const response = await getJson({
14
+ baseUrl: local.baseUrl,
15
+ path: "/v1/cli/billing/catalog",
16
+ accessToken,
17
+ schema: BillingCatalogResponseSchema,
18
+ });
19
+
20
+ if (options.json) {
21
+ toJsonOutput(true, response);
22
+ return;
23
+ }
24
+
25
+ console.log(`Plans: ${response.variants.length}`);
26
+ console.log(`Metered features: ${Object.values(response.featureIds).join(", ")}`);
27
+ }
28
+
29
+ async function runBillingStatus(options: EnvTargetOptions & { json?: boolean }) {
30
+ const local = await requireLocalSession();
31
+ const authProvider = createCliAuthProvider();
32
+ const accessToken = await authProvider.getAccessToken();
33
+ const orgSlug = await promptForOrganizationSlug(options.org);
34
+ const response = await postJson({
35
+ baseUrl: local.baseUrl,
36
+ path: "/v1/cli/billing/status",
37
+ accessToken,
38
+ payload: {
39
+ orgSlug,
40
+ },
41
+ schema: BillingStatusResponseSchema,
42
+ });
43
+
44
+ if (options.json) {
45
+ toJsonOutput(true, response);
46
+ return;
47
+ }
48
+
49
+ console.log(`Tier: ${response.currentTier ?? "none"}`);
50
+ console.log(`Product: ${response.currentProductId ?? "none"}`);
51
+ console.log(`Can manage billing: ${response.canManageBilling ? "yes" : "no"}`);
52
+ }
53
+
54
+ export function registerBillingCommands(program: Command): void {
55
+ const billing = program.command("billing").description("Billing information");
56
+
57
+ billing
58
+ .command("catalog")
59
+ .description("Show the public billing catalog")
60
+ .option("--json", "Machine-readable output", false)
61
+ .action(async (options: { json?: boolean }) => {
62
+ await runBillingCatalog(options);
63
+ });
64
+
65
+ billing
66
+ .command("status")
67
+ .description("Show billing status for an organization")
68
+ .option("--org <slug>", "Organization slug")
69
+ .option("--json", "Machine-readable output", false)
70
+ .action(async (options: EnvTargetOptions & { json?: boolean }) => {
71
+ await runBillingStatus(options);
72
+ });
73
+ }