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