@farthershore/cli 0.3.9 → 0.3.11
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 +49 -0
- package/dist/index.js +433 -94
- package/dist/mcp.js +201 -0
- package/package.json +17 -12
- package/dist/auth.d.ts +0 -1
- package/dist/auth.js +0 -17
- package/dist/build-info.d.ts +0 -1
- package/dist/build-info.js +0 -10
- package/dist/client.d.ts +0 -89
- package/dist/client.js +0 -82
- package/dist/commands/apply.d.ts +0 -3
- package/dist/commands/apply.js +0 -296
- package/dist/commands/billing.d.ts +0 -3
- package/dist/commands/billing.js +0 -99
- package/dist/commands/feature.d.ts +0 -3
- package/dist/commands/feature.js +0 -109
- package/dist/commands/helpers.d.ts +0 -15
- package/dist/commands/helpers.js +0 -93
- package/dist/commands/init.d.ts +0 -3
- package/dist/commands/init.js +0 -43
- package/dist/commands/login.d.ts +0 -2
- package/dist/commands/login.js +0 -144
- package/dist/commands/meter.d.ts +0 -3
- package/dist/commands/meter.js +0 -121
- package/dist/commands/plan-transition.d.ts +0 -40
- package/dist/commands/plan-transition.js +0 -504
- package/dist/commands/plan.d.ts +0 -3
- package/dist/commands/plan.js +0 -234
- package/dist/commands/product.d.ts +0 -3
- package/dist/commands/product.js +0 -137
- package/dist/commands/transition.d.ts +0 -3
- package/dist/commands/transition.js +0 -80
- package/dist/commands/validate.d.ts +0 -28
- package/dist/commands/validate.js +0 -216
- package/dist/config.d.ts +0 -6
- package/dist/config.js +0 -58
- package/dist/index.d.ts +0 -2
- package/dist/output.d.ts +0 -8
- package/dist/output.js +0 -28
- package/dist/remediation.d.ts +0 -6
- package/dist/remediation.js +0 -53
- package/dist/types.d.ts +0 -75
- package/dist/types.js +0 -23
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farthershore/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"description": "FartherShore CLI — create and configure API products",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"farthershore": "dist/index.js"
|
|
7
|
+
"farthershore": "dist/index.js",
|
|
8
|
+
"farthershore-mcp": "dist/mcp.js"
|
|
8
9
|
},
|
|
9
10
|
"files": [
|
|
10
|
-
"dist"
|
|
11
|
+
"dist/index.js",
|
|
12
|
+
"dist/mcp.js",
|
|
13
|
+
"README.md"
|
|
11
14
|
],
|
|
12
15
|
"engines": {
|
|
13
16
|
"node": ">=22"
|
|
@@ -21,8 +24,9 @@
|
|
|
21
24
|
},
|
|
22
25
|
"scripts": {
|
|
23
26
|
"dev": "tsx src/index.ts",
|
|
24
|
-
"build": "tsc",
|
|
25
|
-
"
|
|
27
|
+
"build": "tsc --noEmit && node scripts/build.mjs",
|
|
28
|
+
"pack:check": "node scripts/check-pack.mjs",
|
|
29
|
+
"prepublishOnly": "npm test -- --run && npm run build && npm run pack:check",
|
|
26
30
|
"test": "vitest run",
|
|
27
31
|
"lint": "prettier --check \"src/**/*.ts\" && eslint .",
|
|
28
32
|
"lint:fix": "eslint . --fix",
|
|
@@ -38,21 +42,22 @@
|
|
|
38
42
|
],
|
|
39
43
|
"author": "Farther Shore",
|
|
40
44
|
"license": "MIT",
|
|
41
|
-
"dependencies": {
|
|
45
|
+
"dependencies": {},
|
|
46
|
+
"devDependencies": {
|
|
42
47
|
"@farther-shore/shared-types": "^0.28.2",
|
|
48
|
+
"@modelcontextprotocol/sdk": "^1.18.0",
|
|
49
|
+
"@types/node": "^22.19.17",
|
|
43
50
|
"chalk": "^5.4.1",
|
|
44
51
|
"commander": "^13.1.0",
|
|
45
|
-
"
|
|
46
|
-
"zod": "^4.3.6"
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@types/node": "^22.19.17",
|
|
52
|
+
"esbuild": "^0.27.0",
|
|
50
53
|
"eslint": "^9.39.4",
|
|
51
54
|
"eslint-plugin-sonarjs": "^4.0.3",
|
|
52
55
|
"prettier": "^3.8.1",
|
|
53
56
|
"tsx": "^4.21.0",
|
|
54
57
|
"typescript": "^6.0.2",
|
|
55
58
|
"typescript-eslint": "^8.59.0",
|
|
56
|
-
"vitest": "^3.2.4"
|
|
59
|
+
"vitest": "^3.2.4",
|
|
60
|
+
"yaml": "^2.8.3",
|
|
61
|
+
"zod": "^4.3.6"
|
|
57
62
|
}
|
|
58
63
|
}
|
package/dist/auth.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function resolveToken(overrideToken?: string): string;
|
package/dist/auth.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Token resolution: env var → credentials file → error
|
|
2
|
-
import { loadCredentials } from "./config.js";
|
|
3
|
-
import { CliError } from "./types.js";
|
|
4
|
-
export function resolveToken(overrideToken) {
|
|
5
|
-
// 1. Explicit override (--token flag)
|
|
6
|
-
if (overrideToken)
|
|
7
|
-
return overrideToken;
|
|
8
|
-
// 2. Environment variable
|
|
9
|
-
const envToken = process.env.FARTHERSHORE_TOKEN;
|
|
10
|
-
if (envToken)
|
|
11
|
-
return envToken;
|
|
12
|
-
// 3. Stored credentials (from `farthershore login`)
|
|
13
|
-
const creds = loadCredentials();
|
|
14
|
-
if (creds?.token)
|
|
15
|
-
return creds.token;
|
|
16
|
-
throw new CliError("Not authenticated. Run `farthershore set-key` or set FARTHERSHORE_TOKEN environment variable.");
|
|
17
|
-
}
|
package/dist/build-info.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const BUILD_API_URL = "https://core.farthershore.com";
|
package/dist/build-info.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Build-time constants baked into the CLI binary at publish time.
|
|
2
|
-
//
|
|
3
|
-
// To publish a staging variant:
|
|
4
|
-
// 1. Change BUILD_API_URL below to the staging URL
|
|
5
|
-
// 2. Change the npm package name/tag in package.json
|
|
6
|
-
// 3. Run `npm publish`
|
|
7
|
-
//
|
|
8
|
-
// The CLI uses this as the default API URL — users don't need to set
|
|
9
|
-
// FARTHERSHORE_API_URL or pass --api-url for their target environment.
|
|
10
|
-
export const BUILD_API_URL = "https://core.farthershore.com";
|
package/dist/client.d.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { Product, InitProductResponse, CompileDiagnostic } from "./types.js";
|
|
2
|
-
export declare function createClient(opts: {
|
|
3
|
-
apiUrl: string;
|
|
4
|
-
token: string;
|
|
5
|
-
}): {
|
|
6
|
-
bootstrap: () => Promise<{
|
|
7
|
-
user: {
|
|
8
|
-
id: string;
|
|
9
|
-
clerkUserId: string;
|
|
10
|
-
};
|
|
11
|
-
activeOrganization: {
|
|
12
|
-
id: string;
|
|
13
|
-
name?: string;
|
|
14
|
-
slug?: string;
|
|
15
|
-
};
|
|
16
|
-
memberships: Array<{
|
|
17
|
-
organization: {
|
|
18
|
-
id: string;
|
|
19
|
-
name?: string;
|
|
20
|
-
slug?: string;
|
|
21
|
-
};
|
|
22
|
-
role: string;
|
|
23
|
-
}>;
|
|
24
|
-
}>;
|
|
25
|
-
listProducts: () => Promise<Product[]>;
|
|
26
|
-
createProduct: (data: {
|
|
27
|
-
name: string;
|
|
28
|
-
baseUrl?: string;
|
|
29
|
-
description?: string;
|
|
30
|
-
displayName?: string;
|
|
31
|
-
billingStrategy?: string;
|
|
32
|
-
subscriberChangePolicy?: unknown;
|
|
33
|
-
}) => Promise<Product>;
|
|
34
|
-
initProduct: (data: {
|
|
35
|
-
name: string;
|
|
36
|
-
baseUrl?: string;
|
|
37
|
-
description?: string;
|
|
38
|
-
displayName?: string;
|
|
39
|
-
billingStrategy?: string;
|
|
40
|
-
subscriberChangePolicy?: unknown;
|
|
41
|
-
}) => Promise<InitProductResponse>;
|
|
42
|
-
updateProduct: (productId: string, data: Record<string, unknown>, opts?: {
|
|
43
|
-
env?: string;
|
|
44
|
-
}) => Promise<Product>;
|
|
45
|
-
createPlan: (productId: string, data: unknown, opts?: {
|
|
46
|
-
env?: string;
|
|
47
|
-
}) => Promise<unknown>;
|
|
48
|
-
updatePlan: (productId: string, planId: string, data: unknown, opts?: {
|
|
49
|
-
env?: string;
|
|
50
|
-
}) => Promise<unknown>;
|
|
51
|
-
deletePlan: (productId: string, planId: string, opts?: {
|
|
52
|
-
env?: string;
|
|
53
|
-
}) => Promise<void>;
|
|
54
|
-
getProductConfig: (productId: string) => Promise<unknown>;
|
|
55
|
-
getProductConfigYaml: (productId: string) => Promise<string>;
|
|
56
|
-
getProductAttempts: (productId: string) => Promise<unknown>;
|
|
57
|
-
updateProductConfig: (productId: string, spec: unknown, opts?: {
|
|
58
|
-
dryRun?: boolean;
|
|
59
|
-
}) => Promise<unknown>;
|
|
60
|
-
compileProduct: (productId: string, opts?: {
|
|
61
|
-
branch?: string;
|
|
62
|
-
dryRun?: boolean;
|
|
63
|
-
}) => Promise<{
|
|
64
|
-
success: boolean;
|
|
65
|
-
errors?: CompileDiagnostic[];
|
|
66
|
-
warnings?: CompileDiagnostic[];
|
|
67
|
-
}>;
|
|
68
|
-
managementCompileSelf: (opts?: {
|
|
69
|
-
branch?: string;
|
|
70
|
-
dryRun?: boolean;
|
|
71
|
-
}) => Promise<{
|
|
72
|
-
success: boolean;
|
|
73
|
-
productId: string;
|
|
74
|
-
branch?: string | null;
|
|
75
|
-
errors?: CompileDiagnostic[];
|
|
76
|
-
warnings?: CompileDiagnostic[];
|
|
77
|
-
}>;
|
|
78
|
-
managementCompile: (productId: string, opts?: {
|
|
79
|
-
branch?: string;
|
|
80
|
-
dryRun?: boolean;
|
|
81
|
-
}) => Promise<{
|
|
82
|
-
success: boolean;
|
|
83
|
-
errors?: CompileDiagnostic[];
|
|
84
|
-
warnings?: CompileDiagnostic[];
|
|
85
|
-
}>;
|
|
86
|
-
managementListProducts: () => Promise<Product[]>;
|
|
87
|
-
isMakerToken: () => boolean;
|
|
88
|
-
};
|
|
89
|
-
export type ApiClient = ReturnType<typeof createClient>;
|
package/dist/client.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// Typed API client for the FartherShore platform
|
|
2
|
-
import { CliError } from "./types.js";
|
|
3
|
-
export function createClient(opts) {
|
|
4
|
-
async function request(method, path, body) {
|
|
5
|
-
const res = await fetch(`${opts.apiUrl}${path}`, {
|
|
6
|
-
method,
|
|
7
|
-
headers: {
|
|
8
|
-
Authorization: `Bearer ${opts.token}`,
|
|
9
|
-
"Content-Type": "application/json",
|
|
10
|
-
},
|
|
11
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
12
|
-
});
|
|
13
|
-
if (!res.ok) {
|
|
14
|
-
// Try the canonical Wave-4 envelope first; fall back to a string
|
|
15
|
-
// body or the bare statusText so the error path is robust to old
|
|
16
|
-
// server builds and HTML/text responses (e.g. Cloudflare 502s).
|
|
17
|
-
const parsed = (await res.json().catch(() => null));
|
|
18
|
-
const errEnvelope = parsed && typeof parsed === "object" && parsed.error;
|
|
19
|
-
let message = res.statusText;
|
|
20
|
-
let code;
|
|
21
|
-
let details;
|
|
22
|
-
if (typeof errEnvelope === "string") {
|
|
23
|
-
// Legacy { error: "..." } shape.
|
|
24
|
-
message = errEnvelope;
|
|
25
|
-
}
|
|
26
|
-
else if (errEnvelope && typeof errEnvelope === "object") {
|
|
27
|
-
message = errEnvelope.message ?? message;
|
|
28
|
-
code = errEnvelope.code;
|
|
29
|
-
details = errEnvelope.details;
|
|
30
|
-
}
|
|
31
|
-
throw new CliError(message, res.status, { code, details });
|
|
32
|
-
}
|
|
33
|
-
if (res.status === 204)
|
|
34
|
-
return undefined;
|
|
35
|
-
return res.json();
|
|
36
|
-
}
|
|
37
|
-
async function requestText(method, path) {
|
|
38
|
-
const res = await fetch(`${opts.apiUrl}${path}`, {
|
|
39
|
-
method,
|
|
40
|
-
headers: { Authorization: `Bearer ${opts.token}` },
|
|
41
|
-
});
|
|
42
|
-
if (!res.ok)
|
|
43
|
-
throw new CliError(res.statusText, res.status);
|
|
44
|
-
return res.text();
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
// --- Auth ---
|
|
48
|
-
bootstrap: () => request("POST", "/builder/context/bootstrap"),
|
|
49
|
-
// --- Products ---
|
|
50
|
-
listProducts: () => request("GET", "/products"),
|
|
51
|
-
createProduct: (data) => request("POST", "/products", data),
|
|
52
|
-
initProduct: (data) => request("POST", "/products/init", data),
|
|
53
|
-
updateProduct: (productId, data, opts) => request("PATCH", `/products/${productId}${opts?.env ? `?env=${encodeURIComponent(opts.env)}` : ""}`, data),
|
|
54
|
-
createPlan: (productId, data, opts) => request("POST", `/products/${productId}/plans${opts?.env ? `?env=${encodeURIComponent(opts.env)}` : ""}`, data),
|
|
55
|
-
updatePlan: (productId, planId, data, opts) => request("PATCH", `/products/${productId}/plans/${planId}${opts?.env ? `?env=${encodeURIComponent(opts.env)}` : ""}`, data),
|
|
56
|
-
deletePlan: (productId, planId, opts) => request("DELETE", `/products/${productId}/plans/${planId}${opts?.env ? `?env=${encodeURIComponent(opts.env)}` : ""}`),
|
|
57
|
-
getProductConfig: (productId) => request("GET", `/products/${productId}/config?format=json`),
|
|
58
|
-
getProductConfigYaml: (productId) => requestText("GET", `/products/${productId}/config?format=yaml`),
|
|
59
|
-
getProductAttempts: (productId) => request("GET", `/products/${productId}/config-attempts`),
|
|
60
|
-
updateProductConfig: (productId, spec, opts) => request("PATCH", `/products/${productId}/config`, {
|
|
61
|
-
spec,
|
|
62
|
-
dryRun: opts?.dryRun === true,
|
|
63
|
-
}),
|
|
64
|
-
// --- Compile ---
|
|
65
|
-
compileProduct: (productId, opts) => request("POST", `/products/${productId}/compile`, compileBody(opts)),
|
|
66
|
-
// --- Management (maker token) ---
|
|
67
|
-
// Compile the product associated with the token — no product ID needed.
|
|
68
|
-
// Pass `branch` to scope compilation to an env branch's plans.
|
|
69
|
-
managementCompileSelf: (opts) => request("POST", "/management/compile", compileBody(opts)),
|
|
70
|
-
managementCompile: (productId, opts) => request("POST", `/management/products/${productId}/compile`, compileBody(opts)),
|
|
71
|
-
managementListProducts: () => request("GET", "/management/products"),
|
|
72
|
-
isMakerToken: () => opts.token.startsWith("mk_"),
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function compileBody(opts) {
|
|
76
|
-
const body = {};
|
|
77
|
-
if (opts?.branch)
|
|
78
|
-
body.branch = opts.branch;
|
|
79
|
-
if (opts?.dryRun)
|
|
80
|
-
body.dryRun = true;
|
|
81
|
-
return Object.keys(body).length > 0 ? body : undefined;
|
|
82
|
-
}
|
package/dist/commands/apply.d.ts
DELETED
package/dist/commands/apply.js
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { execSync } from "node:child_process";
|
|
2
|
-
import { readFileSync, existsSync } from "node:fs";
|
|
3
|
-
import { resolve } from "node:path";
|
|
4
|
-
import YAML from "yaml";
|
|
5
|
-
import * as output from "../output.js";
|
|
6
|
-
import { loadProductYaml, validateProductYaml } from "./validate.js";
|
|
7
|
-
const CI = !!process.env.CI || !!process.env.GITHUB_ACTIONS;
|
|
8
|
-
/**
|
|
9
|
-
* Detect the git branch the compiler should scope to. Order of preference:
|
|
10
|
-
* 1. --branch CLI flag (explicit override)
|
|
11
|
-
* 2. GITHUB_HEAD_REF — pull_request source branch (the branch being proposed)
|
|
12
|
-
* 3. GITHUB_REF_NAME — push event branch
|
|
13
|
-
* 4. `git rev-parse --abbrev-ref HEAD` — local dev
|
|
14
|
-
* Returns undefined when nothing is detectable.
|
|
15
|
-
*/
|
|
16
|
-
function detectBranch(explicit) {
|
|
17
|
-
if (explicit)
|
|
18
|
-
return explicit;
|
|
19
|
-
const ghHead = process.env.GITHUB_HEAD_REF;
|
|
20
|
-
if (ghHead)
|
|
21
|
-
return ghHead;
|
|
22
|
-
const ghRef = process.env.GITHUB_REF_NAME;
|
|
23
|
-
if (ghRef)
|
|
24
|
-
return ghRef;
|
|
25
|
-
try {
|
|
26
|
-
const local = execSync("git rev-parse --abbrev-ref HEAD", {
|
|
27
|
-
encoding: "utf-8",
|
|
28
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
29
|
-
}).trim();
|
|
30
|
-
return local && local !== "HEAD" ? local : undefined;
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Read the product name/slug from product.yaml in the current directory.
|
|
38
|
-
*/
|
|
39
|
-
function readSlugFromProductYaml() {
|
|
40
|
-
const yamlPath = resolve("product.yaml");
|
|
41
|
-
if (!existsSync(yamlPath))
|
|
42
|
-
return null;
|
|
43
|
-
try {
|
|
44
|
-
const spec = YAML.parse(readFileSync(yamlPath, "utf-8"));
|
|
45
|
-
const product = spec.product;
|
|
46
|
-
return product?.name ?? null;
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function validateLocalProductYamlBeforeRemoteCompile(format) {
|
|
53
|
-
const filePath = resolve("product.yaml");
|
|
54
|
-
if (!existsSync(filePath))
|
|
55
|
-
return true;
|
|
56
|
-
const loaded = loadProductYaml(filePath);
|
|
57
|
-
if (!loaded.ok) {
|
|
58
|
-
const message = loaded.reason === "parse"
|
|
59
|
-
? `Local product.yaml failed to parse; remote compile was not started.\n${loaded.message}`
|
|
60
|
-
: `Local product.yaml could not be read; remote compile was not started.\n${loaded.message}`;
|
|
61
|
-
if (CI) {
|
|
62
|
-
console.log(`::error file=product.yaml::${message}`);
|
|
63
|
-
}
|
|
64
|
-
if (format === "json") {
|
|
65
|
-
console.log(output.json({
|
|
66
|
-
ok: false,
|
|
67
|
-
success: false,
|
|
68
|
-
phase: "local_validation",
|
|
69
|
-
errors: [{ message }],
|
|
70
|
-
warnings: [],
|
|
71
|
-
nextActions: ["Fix product.yaml and run apply again"],
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
output.error(message);
|
|
76
|
-
}
|
|
77
|
-
process.exitCode = 1;
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
const result = validateProductYaml(loaded.spec);
|
|
81
|
-
if (!result.valid) {
|
|
82
|
-
if (CI) {
|
|
83
|
-
for (const err of result.errors) {
|
|
84
|
-
console.log(`::error file=product.yaml::${err}`);
|
|
85
|
-
}
|
|
86
|
-
for (const warning of result.warnings) {
|
|
87
|
-
console.log(`::warning file=product.yaml::${warning}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (format === "json") {
|
|
91
|
-
console.log(output.json({
|
|
92
|
-
ok: false,
|
|
93
|
-
success: false,
|
|
94
|
-
phase: "local_validation",
|
|
95
|
-
errors: result.errors.map((message) => ({ message })),
|
|
96
|
-
warnings: result.warnings.map((message) => ({ message })),
|
|
97
|
-
nextActions: ["Fix product.yaml and run apply again"],
|
|
98
|
-
}));
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
output.error("Local product.yaml failed validation; remote compile was not started.\n");
|
|
102
|
-
for (const err of result.errors) {
|
|
103
|
-
console.log(` • ${err}`);
|
|
104
|
-
}
|
|
105
|
-
if (result.warnings.length > 0) {
|
|
106
|
-
console.log();
|
|
107
|
-
for (const warning of result.warnings) {
|
|
108
|
-
output.warn(warning);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
process.exitCode = 1;
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
if (format !== "json") {
|
|
116
|
-
output.success("Local product.yaml passed validation");
|
|
117
|
-
for (const warning of result.warnings) {
|
|
118
|
-
output.warn(warning);
|
|
119
|
-
}
|
|
120
|
-
output.info("Remote compile checks the pushed branch state; unpushed local edits are not included.");
|
|
121
|
-
}
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
function shouldValidateLocalProductYaml(productArg) {
|
|
125
|
-
const filePath = resolve("product.yaml");
|
|
126
|
-
if (!existsSync(filePath))
|
|
127
|
-
return false;
|
|
128
|
-
if (!productArg)
|
|
129
|
-
return true;
|
|
130
|
-
const localSlug = readSlugFromProductYaml();
|
|
131
|
-
return (typeof localSlug === "string" &&
|
|
132
|
-
localSlug.toLowerCase() === productArg.toLowerCase());
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Resolve a product identifier to an API product ID.
|
|
136
|
-
* If no arg, reads product.name from product.yaml in the current directory.
|
|
137
|
-
* If arg looks like a UUID, uses it directly. Otherwise treats it as a slug.
|
|
138
|
-
*/
|
|
139
|
-
async function resolveProductId(client, arg) {
|
|
140
|
-
const slug = arg ?? readSlugFromProductYaml();
|
|
141
|
-
if (!slug)
|
|
142
|
-
return null;
|
|
143
|
-
// UUID — use directly
|
|
144
|
-
if (slug.length === 36 &&
|
|
145
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(slug)) {
|
|
146
|
-
return slug;
|
|
147
|
-
}
|
|
148
|
-
// Slug — resolve via product list (use management API for maker tokens)
|
|
149
|
-
try {
|
|
150
|
-
const products = client.isMakerToken()
|
|
151
|
-
? await client.managementListProducts()
|
|
152
|
-
: await client.listProducts();
|
|
153
|
-
const match = products.find((p) => p.name === slug || p.name.toLowerCase() === slug.toLowerCase());
|
|
154
|
-
return match?.id ?? null;
|
|
155
|
-
}
|
|
156
|
-
catch (err) {
|
|
157
|
-
// Don't swallow network errors silently
|
|
158
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
159
|
-
process.stderr.write(`Warning: Failed to resolve product slug: ${msg}\n`);
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
function compileOptions(branch, dryRun) {
|
|
164
|
-
return {
|
|
165
|
-
...(branch ? { branch } : {}),
|
|
166
|
-
...(dryRun ? { dryRun: true } : {}),
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
// Render a diagnostic with an optional plan-key prefix so users can see which
|
|
170
|
-
// plan an error belongs to when the compiler scopes it. `compiledPlanId`
|
|
171
|
-
// itself is an internal pointer — `planKey` is the human-readable label.
|
|
172
|
-
function formatDiag(d) {
|
|
173
|
-
const prefix = d.code ? `[${d.code}] ` : "";
|
|
174
|
-
const planLabel = d.planKey ? `(plan: ${d.planKey}) ` : "";
|
|
175
|
-
return `${prefix}${planLabel}${d.message}`;
|
|
176
|
-
}
|
|
177
|
-
function handleResult(result, format) {
|
|
178
|
-
// GitHub Actions annotations
|
|
179
|
-
if (CI) {
|
|
180
|
-
for (const err of result.errors ?? []) {
|
|
181
|
-
console.log(`::error file=product.yaml::${formatDiag(err)}`);
|
|
182
|
-
}
|
|
183
|
-
for (const w of result.warnings ?? []) {
|
|
184
|
-
console.log(`::warning file=product.yaml::${formatDiag(w)}`);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (format === "json") {
|
|
188
|
-
console.log(output.json({
|
|
189
|
-
ok: result.success,
|
|
190
|
-
success: result.success,
|
|
191
|
-
errors: result.errors ?? [],
|
|
192
|
-
warnings: result.warnings ?? [],
|
|
193
|
-
nextActions: result.success
|
|
194
|
-
? ["Product config is valid for apply"]
|
|
195
|
-
: ["Fix errors and run farthershore apply --dry-run --format json"],
|
|
196
|
-
}));
|
|
197
|
-
if (!result.success)
|
|
198
|
-
process.exitCode = 1;
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
if (result.success) {
|
|
202
|
-
output.success("Remote compile passed");
|
|
203
|
-
if (result.warnings?.length) {
|
|
204
|
-
console.log();
|
|
205
|
-
for (const w of result.warnings) {
|
|
206
|
-
output.warn(formatDiag(w));
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
output.error("Remote compile failed\n");
|
|
212
|
-
for (const err of result.errors ?? []) {
|
|
213
|
-
console.log(` • ${formatDiag(err)}`);
|
|
214
|
-
}
|
|
215
|
-
process.exitCode = 1;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
export function registerApplyCommand(program, getClient) {
|
|
219
|
-
program
|
|
220
|
-
.command("apply [product]")
|
|
221
|
-
.description("Validate the current repo's product.yaml before remote compile when applying that repo's product, then run the server-side compiler against the pushed branch state for this product. " +
|
|
222
|
-
"Unpushed local edits are not included. Pass a product slug, or run inside a product repo to auto-detect from product.yaml. " +
|
|
223
|
-
"Automatically scopes to the current git branch so env branches compile against their own plans.")
|
|
224
|
-
.option("--branch <branch>", "Override the branch used for env-scoped compilation (default: auto-detected)")
|
|
225
|
-
.option("--dry-run", "Run local validation and remote compile without applying product state")
|
|
226
|
-
.addHelpText("after", `
|
|
227
|
-
Agent notes:
|
|
228
|
-
apply first validates local product.yaml when it matches the target product, then asks core to compile the pushed branch state.
|
|
229
|
-
Unpushed local edits are not included in remote compile. Push or use CLI config commands for API-backed changes.
|
|
230
|
-
Use --format json for stable output: ok, success, errors, warnings, nextActions.
|
|
231
|
-
|
|
232
|
-
Examples:
|
|
233
|
-
farthershore apply --dry-run --format json
|
|
234
|
-
farthershore apply my-weather-api --dry-run --format json
|
|
235
|
-
farthershore apply my-weather-api --branch feature/billing-change --dry-run --format json
|
|
236
|
-
`)
|
|
237
|
-
.action(async (productArg, opts) => {
|
|
238
|
-
const client = getClient();
|
|
239
|
-
const globalFormat = program.opts().format;
|
|
240
|
-
const format = globalFormat === "json" ? "json" : "table";
|
|
241
|
-
const branch = detectBranch(opts.branch);
|
|
242
|
-
const compileOpts = compileOptions(branch, opts.dryRun);
|
|
243
|
-
if (shouldValidateLocalProductYaml(productArg) &&
|
|
244
|
-
!validateLocalProductYamlBeforeRemoteCompile(format)) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
if (branch && CI) {
|
|
248
|
-
console.log(`::notice::Compiling against branch '${branch}'`);
|
|
249
|
-
}
|
|
250
|
-
// Fast path for CI: product-scoped maker token with no argument.
|
|
251
|
-
// Server auto-resolves product from the token — no product.yaml,
|
|
252
|
-
// no slug lookup, single API call.
|
|
253
|
-
if (client.isMakerToken() && !productArg) {
|
|
254
|
-
try {
|
|
255
|
-
const result = await client.managementCompileSelf(compileOpts);
|
|
256
|
-
handleResult(result, format);
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
catch (err) {
|
|
260
|
-
const msg = err instanceof Error ? err.message : "Compilation check failed";
|
|
261
|
-
if (CI)
|
|
262
|
-
console.log(`::error::${msg}`);
|
|
263
|
-
output.error(msg);
|
|
264
|
-
process.exitCode = 1;
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
const productId = await resolveProductId(client, productArg);
|
|
269
|
-
if (!productId) {
|
|
270
|
-
const hint = productArg
|
|
271
|
-
? `Product "${productArg}" not found. Check the name and try again.`
|
|
272
|
-
: "No product specified and no product.yaml found.\n" +
|
|
273
|
-
" Run from inside a product repo, or pass the slug: farthershore apply my-api";
|
|
274
|
-
output.error(hint);
|
|
275
|
-
process.exitCode = 1;
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
try {
|
|
279
|
-
const result = client.isMakerToken()
|
|
280
|
-
? await client.managementCompile(productId, {
|
|
281
|
-
...compileOpts,
|
|
282
|
-
})
|
|
283
|
-
: await client.compileProduct(productId, {
|
|
284
|
-
...compileOpts,
|
|
285
|
-
});
|
|
286
|
-
handleResult(result, format);
|
|
287
|
-
}
|
|
288
|
-
catch (err) {
|
|
289
|
-
const msg = err instanceof Error ? err.message : "Compilation check failed";
|
|
290
|
-
if (CI)
|
|
291
|
-
console.log(`::error::${msg}`);
|
|
292
|
-
output.error(msg);
|
|
293
|
-
process.exitCode = 1;
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
package/dist/commands/billing.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { loadAcceptedSpec, objectAt, printResult, resolveProductId, updateSpec, } from "./helpers.js";
|
|
2
|
-
export function registerBillingCommands(program, getClient) {
|
|
3
|
-
const billing = program
|
|
4
|
-
.command("billing")
|
|
5
|
-
.description("Manage product-level billing strategy and transition policy")
|
|
6
|
-
.addHelpText("after", `
|
|
7
|
-
Agent notes:
|
|
8
|
-
Billing strategy is product-level for paid plans. Paid plans should not mix strategies.
|
|
9
|
-
Strategies: free_trial, flat_subscription, included_usage, subscription_overage, pay_as_you_go, prepaid_credits.
|
|
10
|
-
Subscriber actions: preserve_current_period, switch_immediately, switch_immediately_prorate, new_subscribers_only.
|
|
11
|
-
|
|
12
|
-
Examples:
|
|
13
|
-
farthershore billing strategy get --format json
|
|
14
|
-
farthershore billing strategy set prepaid_credits --transition preserve_current_period --format json
|
|
15
|
-
farthershore billing policy set --default preserve_current_period --proration none --format json
|
|
16
|
-
`);
|
|
17
|
-
const strategy = billing
|
|
18
|
-
.command("strategy")
|
|
19
|
-
.description("Get or set the product-level billing strategy")
|
|
20
|
-
.addHelpText("after", `
|
|
21
|
-
Examples:
|
|
22
|
-
farthershore billing strategy get --format json
|
|
23
|
-
farthershore billing strategy set subscription_overage --format json
|
|
24
|
-
`);
|
|
25
|
-
strategy
|
|
26
|
-
.command("get")
|
|
27
|
-
.option("--product <product>", "Product id or name")
|
|
28
|
-
.addHelpText("after", `
|
|
29
|
-
Example:
|
|
30
|
-
farthershore billing strategy get --format json
|
|
31
|
-
`)
|
|
32
|
-
.action(async (opts) => {
|
|
33
|
-
const client = getClient();
|
|
34
|
-
const productId = await resolveProductId(client, opts.product);
|
|
35
|
-
const config = (await client.getProductConfig(productId));
|
|
36
|
-
printResult(program, "Billing strategy loaded", {
|
|
37
|
-
ok: true,
|
|
38
|
-
productId,
|
|
39
|
-
strategy: config.acceptedConfig?.billing?.strategy ?? null,
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
strategy
|
|
43
|
-
.command("set <strategy>")
|
|
44
|
-
.option("--product <product>", "Product id or name")
|
|
45
|
-
.option("--transition <action>", "Default subscriber transition action: preserve_current_period, switch_immediately, switch_immediately_prorate, new_subscribers_only", "preserve_current_period")
|
|
46
|
-
.option("--proration <mode>", "Proration mode", "none")
|
|
47
|
-
.option("--dry-run", "Validate without mutating")
|
|
48
|
-
.addHelpText("after", `
|
|
49
|
-
Examples:
|
|
50
|
-
farthershore billing strategy set prepaid_credits --transition preserve_current_period --format json
|
|
51
|
-
farthershore billing strategy set pay_as_you_go --dry-run --format json
|
|
52
|
-
`)
|
|
53
|
-
.action(async (nextStrategy, opts) => {
|
|
54
|
-
const client = getClient();
|
|
55
|
-
const productId = await resolveProductId(client, opts.product);
|
|
56
|
-
const spec = await loadAcceptedSpec(client, productId);
|
|
57
|
-
const billing = objectAt(spec, "billing");
|
|
58
|
-
billing.strategy = nextStrategy;
|
|
59
|
-
billing.subscriberChangePolicy = {
|
|
60
|
-
default: opts.transition,
|
|
61
|
-
proration: opts.proration,
|
|
62
|
-
};
|
|
63
|
-
await updateSpec(program, client, productId, spec, {
|
|
64
|
-
dryRun: opts.dryRun,
|
|
65
|
-
message: "Billing strategy updated",
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
const policy = billing
|
|
69
|
-
.command("policy")
|
|
70
|
-
.description("Set subscriber change policy defaults")
|
|
71
|
-
.addHelpText("after", `
|
|
72
|
-
Example:
|
|
73
|
-
farthershore billing policy set --default preserve_current_period --proration none --format json
|
|
74
|
-
`);
|
|
75
|
-
policy
|
|
76
|
-
.command("set")
|
|
77
|
-
.option("--product <product>", "Product id or name")
|
|
78
|
-
.option("--default <action>", "Default subscriber action: preserve_current_period, switch_immediately, switch_immediately_prorate, new_subscribers_only", "preserve_current_period")
|
|
79
|
-
.option("--proration <mode>", "Proration mode", "none")
|
|
80
|
-
.option("--dry-run", "Validate without mutating")
|
|
81
|
-
.addHelpText("after", `
|
|
82
|
-
Example:
|
|
83
|
-
farthershore billing policy set --default preserve_current_period --proration none --format json
|
|
84
|
-
`)
|
|
85
|
-
.action(async (opts) => {
|
|
86
|
-
const client = getClient();
|
|
87
|
-
const productId = await resolveProductId(client, opts.product);
|
|
88
|
-
const spec = await loadAcceptedSpec(client, productId);
|
|
89
|
-
const billing = objectAt(spec, "billing");
|
|
90
|
-
billing.subscriberChangePolicy = {
|
|
91
|
-
default: opts.default,
|
|
92
|
-
proration: opts.proration,
|
|
93
|
-
};
|
|
94
|
-
await updateSpec(program, client, productId, spec, {
|
|
95
|
-
dryRun: opts.dryRun,
|
|
96
|
-
message: "Billing policy updated",
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
}
|