@revturbine/cli 0.6.0 → 0.7.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.
- package/dist/cli.js +30 -13
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6678,19 +6678,35 @@ program.command("preview").description("The open draft's staged changes (runtime
|
|
|
6678
6678
|
if (!res.ok) httpFail(conn, "preview", res.status, json);
|
|
6679
6679
|
emit(json, true);
|
|
6680
6680
|
});
|
|
6681
|
-
program.command("evaluate").description("Run the live
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6681
|
+
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(
|
|
6682
|
+
async (opts) => {
|
|
6683
|
+
const [sel] = requireSelectors(opts, [], { count: 1, allowed: ["draft", "live", "release"], command: "evaluate" });
|
|
6684
|
+
const conn = connect(opts.url, opts.tenantId);
|
|
6685
|
+
if (!existsSync2(opts.user)) fail(EXIT.USAGE, `user file not found: ${opts.user}`);
|
|
6686
|
+
let ctx;
|
|
6687
|
+
try {
|
|
6688
|
+
ctx = JSON.parse(readFileSync2(opts.user, "utf8"));
|
|
6689
|
+
} catch (err) {
|
|
6690
|
+
fail(EXIT.VALIDATION, `invalid JSON in ${opts.user}: ${err.message}`);
|
|
6691
|
+
}
|
|
6692
|
+
const body = { ...ctx };
|
|
6693
|
+
if (opts.planHandle) body.plan_handle = opts.planHandle;
|
|
6694
|
+
if (opts.entitlement && opts.slot) fail(EXIT.USAGE, "pass exactly one of --entitlement or --slot (or neither for the ctx file lists).");
|
|
6695
|
+
if (opts.entitlement) {
|
|
6696
|
+
body.entitlement_handles = [opts.entitlement];
|
|
6697
|
+
body.placement_ids = [];
|
|
6698
|
+
}
|
|
6699
|
+
if (opts.slot) {
|
|
6700
|
+
body.placement_ids = [opts.slot];
|
|
6701
|
+
body.entitlement_handles = [];
|
|
6702
|
+
}
|
|
6703
|
+
if (sel.kind === "release") body.playbook_version_id = sel.id;
|
|
6704
|
+
if (sel.kind === "draft") body.playbook_version_id = await requireOpenDraft(conn);
|
|
6705
|
+
const { res, json } = await postJson(conn, "/api/sdk/evaluate", body);
|
|
6706
|
+
if (!res.ok) httpFail(conn, "evaluate", res.status, json);
|
|
6707
|
+
emit(json, true);
|
|
6689
6708
|
}
|
|
6690
|
-
|
|
6691
|
-
if (!res.ok) httpFail(conn, "evaluate", res.status, json);
|
|
6692
|
-
emit(json, true);
|
|
6693
|
-
});
|
|
6709
|
+
);
|
|
6694
6710
|
var COMMAND_EXAMPLES = {
|
|
6695
6711
|
download: [
|
|
6696
6712
|
"",
|
|
@@ -6722,7 +6738,8 @@ var COMMAND_EXAMPLES = {
|
|
|
6722
6738
|
evaluate: [
|
|
6723
6739
|
"",
|
|
6724
6740
|
"Example:",
|
|
6725
|
-
" revturbine evaluate --
|
|
6741
|
+
" revturbine evaluate --live --user ./ctx.json --entitlement seats",
|
|
6742
|
+
" revturbine evaluate --draft --user ./ctx.json --slot upgrade_banner --plan-handle pro",
|
|
6726
6743
|
' ctx.json: { "user_id": "u1", "plan_handle": "pro", "entitlement_handles": ["seats"] }'
|
|
6727
6744
|
].join("\n")
|
|
6728
6745
|
};
|
package/package.json
CHANGED