@revturbine/cli 0.6.0 → 0.7.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/dist/cli.js +44 -16
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6671,26 +6671,53 @@ program.command("history").description("The Release Version Log: recent Releases
|
|
|
6671
6671
|
)
|
|
6672
6672
|
);
|
|
6673
6673
|
});
|
|
6674
|
-
program.command("preview").description("The open draft's
|
|
6674
|
+
program.command("preview").description("The open draft's Runtime Impact summary (objects affected, billing impact) + field-level changes.").option("-u, --url <url>", "RevTurbine instance URL", DEFAULT_URL).option("-t, --tenant-id <id>", "x-tenant-id (defaults to the stored token tenant)").option("--json", "Machine-readable output").action(async (opts) => {
|
|
6675
6675
|
const conn = connect(opts.url, opts.tenantId);
|
|
6676
6676
|
const playbookVersionId = await requireOpenDraft(conn);
|
|
6677
|
-
const { res, json } = await getJson(conn, `/api/
|
|
6677
|
+
const { res, json } = await getJson(conn, `/api/optimization/drafts/${playbookVersionId}/changes`);
|
|
6678
6678
|
if (!res.ok) httpFail(conn, "preview", res.status, json);
|
|
6679
|
-
|
|
6679
|
+
const impact = json?.impact ?? {};
|
|
6680
|
+
const changes = Array.isArray(json?.changes) ? json.changes : [];
|
|
6681
|
+
const data = { playbook_version_id: playbookVersionId, impact, changes };
|
|
6682
|
+
const billingObjects = impact.billing?.objects ?? [];
|
|
6683
|
+
const text = [
|
|
6684
|
+
`Runtime impact (draft ${playbookVersionId}):`,
|
|
6685
|
+
table((impact.byCategory ?? []).map((c) => [c.label, `${c.count}`])),
|
|
6686
|
+
`Billing impact: ${billingObjects.length === 0 ? "(none)" : billingObjects.join(", ")}`,
|
|
6687
|
+
`Changes (${changes.length}):`,
|
|
6688
|
+
table(changes.map((c) => [String(c.action ?? ""), String(c.objectType ?? ""), String(c.objectName ?? ""), String(c.summary ?? "")]))
|
|
6689
|
+
].join("\n");
|
|
6690
|
+
emit(data, Boolean(opts.json), text);
|
|
6680
6691
|
});
|
|
6681
|
-
program.command("evaluate").description("Run the live
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6692
|
+
program.command("evaluate").description("Run placement/entitlement decisions for a user context against a config version. Requires --live, --draft, or --release <id>.").option("--live", "Evaluate the live configuration").option("--draft", "Evaluate the tenant's open draft (clean-room: no suppression/cap history)").option("--release <id>", "Evaluate a past release (from its frozen snapshot)").option("--entitlement <handle>", "Check one entitlement (the checkEntitlement result)").option("--slot <id>", "Evaluate one placement/slot (the getPlacement decision)").option("--plan-handle <handle>", "Evaluate as if the user were on this plan (overrides the ctx file)").option("-u, --url <url>", "RevTurbine instance URL", DEFAULT_URL).requiredOption("--user <file>", "JSON file: { user_id, customer_id?, plan_handle?, traits?, now_iso? }").option("-t, --tenant-id <id>", "x-tenant-id (defaults to the stored token tenant)").action(
|
|
6693
|
+
async (opts) => {
|
|
6694
|
+
const [sel] = requireSelectors(opts, [], { count: 1, allowed: ["draft", "live", "release"], command: "evaluate" });
|
|
6695
|
+
const conn = connect(opts.url, opts.tenantId);
|
|
6696
|
+
if (!existsSync2(opts.user)) fail(EXIT.USAGE, `user file not found: ${opts.user}`);
|
|
6697
|
+
let ctx;
|
|
6698
|
+
try {
|
|
6699
|
+
ctx = JSON.parse(readFileSync2(opts.user, "utf8"));
|
|
6700
|
+
} catch (err) {
|
|
6701
|
+
fail(EXIT.VALIDATION, `invalid JSON in ${opts.user}: ${err.message}`);
|
|
6702
|
+
}
|
|
6703
|
+
const body = { ...ctx };
|
|
6704
|
+
if (opts.planHandle) body.plan_handle = opts.planHandle;
|
|
6705
|
+
if (opts.entitlement && opts.slot) fail(EXIT.USAGE, "pass exactly one of --entitlement or --slot (or neither for the ctx file lists).");
|
|
6706
|
+
if (opts.entitlement) {
|
|
6707
|
+
body.entitlement_handles = [opts.entitlement];
|
|
6708
|
+
body.placement_ids = [];
|
|
6709
|
+
}
|
|
6710
|
+
if (opts.slot) {
|
|
6711
|
+
body.placement_ids = [opts.slot];
|
|
6712
|
+
body.entitlement_handles = [];
|
|
6713
|
+
}
|
|
6714
|
+
if (sel.kind === "release") body.playbook_version_id = sel.id;
|
|
6715
|
+
if (sel.kind === "draft") body.playbook_version_id = await requireOpenDraft(conn);
|
|
6716
|
+
const { res, json } = await postJson(conn, "/api/sdk/evaluate", body);
|
|
6717
|
+
if (!res.ok) httpFail(conn, "evaluate", res.status, json);
|
|
6718
|
+
emit(json, true);
|
|
6689
6719
|
}
|
|
6690
|
-
|
|
6691
|
-
if (!res.ok) httpFail(conn, "evaluate", res.status, json);
|
|
6692
|
-
emit(json, true);
|
|
6693
|
-
});
|
|
6720
|
+
);
|
|
6694
6721
|
var COMMAND_EXAMPLES = {
|
|
6695
6722
|
download: [
|
|
6696
6723
|
"",
|
|
@@ -6722,7 +6749,8 @@ var COMMAND_EXAMPLES = {
|
|
|
6722
6749
|
evaluate: [
|
|
6723
6750
|
"",
|
|
6724
6751
|
"Example:",
|
|
6725
|
-
" revturbine evaluate --
|
|
6752
|
+
" revturbine evaluate --live --user ./ctx.json --entitlement seats",
|
|
6753
|
+
" revturbine evaluate --draft --user ./ctx.json --slot upgrade_banner --plan-handle pro",
|
|
6726
6754
|
' ctx.json: { "user_id": "u1", "plan_handle": "pro", "entitlement_handles": ["seats"] }'
|
|
6727
6755
|
].join("\n")
|
|
6728
6756
|
};
|
package/package.json
CHANGED