@gradual-so/cli 0.1.3 → 0.1.4
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/index.js +55 -40
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20112,16 +20112,17 @@ var envsCommand = new Command("envs").description("Manage environments").addComm
|
|
|
20112
20112
|
|
|
20113
20113
|
// src/commands/eval.ts
|
|
20114
20114
|
var import_ora2 = __toESM(require_ora(), 1);
|
|
20115
|
-
var evalCommand = new Command("eval").description("Evaluate a feature flag").argument("<flag-key>", "Flag key to evaluate").option("--env <environment>", "Environment slug (defaults to
|
|
20115
|
+
var evalCommand = new Command("eval").description("Evaluate a feature flag").argument("<flag-key>", "Flag key to evaluate").option("--env <environment>", "Environment slug (defaults to all environments)").option("--json", "Output as JSON").action(async (flagKey, options) => {
|
|
20116
20116
|
const { api } = requireAuth();
|
|
20117
20117
|
const project = requireProject();
|
|
20118
20118
|
const spinner = import_ora2.default("Evaluating flag...").start();
|
|
20119
20119
|
try {
|
|
20120
|
-
const
|
|
20120
|
+
const result = await api.query("featureFlags.getByKey", {
|
|
20121
20121
|
key: flagKey,
|
|
20122
20122
|
projectSlug: project.projectSlug,
|
|
20123
20123
|
organizationSlug: project.organizationSlug
|
|
20124
20124
|
});
|
|
20125
|
+
const { flag } = result;
|
|
20125
20126
|
const environments = await api.query("environment.list", {
|
|
20126
20127
|
organizationId: project.organizationId,
|
|
20127
20128
|
projectId: project.projectId,
|
|
@@ -20135,17 +20136,33 @@ var evalCommand = new Command("eval").description("Evaluate a feature flag").arg
|
|
|
20135
20136
|
process.exit(1);
|
|
20136
20137
|
}
|
|
20137
20138
|
}
|
|
20138
|
-
const
|
|
20139
|
-
const
|
|
20140
|
-
|
|
20141
|
-
|
|
20142
|
-
|
|
20143
|
-
|
|
20144
|
-
|
|
20145
|
-
|
|
20139
|
+
const evalResults = [];
|
|
20140
|
+
for (const env3 of targetEnvs) {
|
|
20141
|
+
try {
|
|
20142
|
+
const rules = await api.query("featureFlags.getTargetingRules", {
|
|
20143
|
+
flagId: flag.id,
|
|
20144
|
+
environmentSlug: env3.slug,
|
|
20145
|
+
projectSlug: project.projectSlug,
|
|
20146
|
+
organizationSlug: project.organizationSlug
|
|
20147
|
+
});
|
|
20148
|
+
evalResults.push({
|
|
20149
|
+
environment: env3.name,
|
|
20150
|
+
enabled: rules.enabled,
|
|
20151
|
+
value: rules.defaultVariation?.value ?? null,
|
|
20152
|
+
variation: rules.defaultVariation?.name ?? "-"
|
|
20153
|
+
});
|
|
20154
|
+
} catch {
|
|
20155
|
+
evalResults.push({
|
|
20156
|
+
environment: env3.name,
|
|
20157
|
+
enabled: false,
|
|
20158
|
+
value: null,
|
|
20159
|
+
variation: "not configured"
|
|
20160
|
+
});
|
|
20161
|
+
}
|
|
20162
|
+
}
|
|
20146
20163
|
spinner.stop();
|
|
20147
20164
|
if (options.json) {
|
|
20148
|
-
json({ flag: flagKey, evaluations });
|
|
20165
|
+
json({ flag: flagKey, evaluations: evalResults });
|
|
20149
20166
|
return;
|
|
20150
20167
|
}
|
|
20151
20168
|
console.log();
|
|
@@ -20155,13 +20172,12 @@ var evalCommand = new Command("eval").description("Evaluate a feature flag").arg
|
|
|
20155
20172
|
["Type", flag.type]
|
|
20156
20173
|
]);
|
|
20157
20174
|
console.log();
|
|
20158
|
-
for (const
|
|
20159
|
-
const env3 = targetEnvs.find((e) => e.id === evaluation.environmentId);
|
|
20175
|
+
for (const evalResult of evalResults) {
|
|
20160
20176
|
keyValue([
|
|
20161
|
-
["Environment",
|
|
20162
|
-
["
|
|
20163
|
-
["
|
|
20164
|
-
["
|
|
20177
|
+
["Environment", evalResult.environment],
|
|
20178
|
+
["Enabled", evalResult.enabled ? "ON" : "OFF"],
|
|
20179
|
+
["Value", String(evalResult.value)],
|
|
20180
|
+
["Variation", evalResult.variation]
|
|
20165
20181
|
]);
|
|
20166
20182
|
console.log();
|
|
20167
20183
|
}
|
|
@@ -20230,16 +20246,17 @@ var flagsGetCommand = new Command("get").description("Get details of a feature f
|
|
|
20230
20246
|
const project = requireProject();
|
|
20231
20247
|
const spinner = import_ora4.default("Fetching flag...").start();
|
|
20232
20248
|
try {
|
|
20233
|
-
const
|
|
20249
|
+
const result = await api.query("featureFlags.getByKey", {
|
|
20234
20250
|
key,
|
|
20235
20251
|
projectSlug: project.projectSlug,
|
|
20236
20252
|
organizationSlug: project.organizationSlug
|
|
20237
20253
|
});
|
|
20238
20254
|
spinner.stop();
|
|
20239
20255
|
if (options.json) {
|
|
20240
|
-
json(
|
|
20256
|
+
json(result);
|
|
20241
20257
|
return;
|
|
20242
20258
|
}
|
|
20259
|
+
const { flag, variations } = result;
|
|
20243
20260
|
console.log();
|
|
20244
20261
|
keyValue([
|
|
20245
20262
|
["Name", flag.name],
|
|
@@ -20250,9 +20267,9 @@ var flagsGetCommand = new Command("get").description("Get details of a feature f
|
|
|
20250
20267
|
["Created", new Date(flag.createdAt).toLocaleDateString()],
|
|
20251
20268
|
["Updated", new Date(flag.updatedAt).toLocaleDateString()]
|
|
20252
20269
|
]);
|
|
20253
|
-
if (
|
|
20270
|
+
if (variations.length > 0) {
|
|
20254
20271
|
console.log();
|
|
20255
|
-
table(["VARIATION", "VALUE", "DEFAULT"],
|
|
20272
|
+
table(["VARIATION", "VALUE", "DEFAULT"], variations.map((v) => [
|
|
20256
20273
|
v.name,
|
|
20257
20274
|
String(v.value),
|
|
20258
20275
|
v.isDefault ? "yes" : ""
|
|
@@ -20279,15 +20296,16 @@ var flagsListCommand = new Command("list").description("List feature flags").opt
|
|
|
20279
20296
|
search: options.search
|
|
20280
20297
|
});
|
|
20281
20298
|
spinner.stop();
|
|
20299
|
+
const flags = result.items.map((item) => item.featureFlag);
|
|
20282
20300
|
if (options.json) {
|
|
20283
|
-
json(
|
|
20301
|
+
json(flags);
|
|
20284
20302
|
return;
|
|
20285
20303
|
}
|
|
20286
|
-
if (
|
|
20304
|
+
if (flags.length === 0) {
|
|
20287
20305
|
info("No flags found");
|
|
20288
20306
|
return;
|
|
20289
20307
|
}
|
|
20290
|
-
table(["KEY", "NAME", "TYPE", "STATUS", "CREATED"],
|
|
20308
|
+
table(["KEY", "NAME", "TYPE", "STATUS", "CREATED"], flags.map((flag) => [
|
|
20291
20309
|
flag.key,
|
|
20292
20310
|
flag.name,
|
|
20293
20311
|
flag.type,
|
|
@@ -20307,20 +20325,20 @@ var flagsToggleCommand = new Command("toggle").description("Toggle a feature fla
|
|
|
20307
20325
|
const project = requireProject();
|
|
20308
20326
|
const spinner = import_ora6.default("Toggling flag...").start();
|
|
20309
20327
|
try {
|
|
20310
|
-
const
|
|
20328
|
+
const result = await api.query("featureFlags.getByKey", {
|
|
20311
20329
|
key,
|
|
20312
20330
|
projectSlug: project.projectSlug,
|
|
20313
20331
|
organizationSlug: project.organizationSlug
|
|
20314
20332
|
});
|
|
20315
20333
|
const rules = await api.query("featureFlags.getTargetingRules", {
|
|
20316
|
-
flagId: flag.id,
|
|
20334
|
+
flagId: result.flag.id,
|
|
20317
20335
|
environmentSlug: options.env,
|
|
20318
20336
|
projectSlug: project.projectSlug,
|
|
20319
20337
|
organizationSlug: project.organizationSlug
|
|
20320
20338
|
});
|
|
20321
20339
|
const newEnabled = !rules.enabled;
|
|
20322
20340
|
await api.mutate("featureFlags.saveTargetingRules", {
|
|
20323
|
-
flagId: flag.id,
|
|
20341
|
+
flagId: result.flag.id,
|
|
20324
20342
|
environmentSlug: options.env,
|
|
20325
20343
|
projectSlug: project.projectSlug,
|
|
20326
20344
|
organizationSlug: project.organizationSlug,
|
|
@@ -21623,23 +21641,20 @@ var esm_default3 = createPrompt((config, done) => {
|
|
|
21623
21641
|
var initCommand = new Command("init").description("Set up project context for the CLI").action(async () => {
|
|
21624
21642
|
const { api, dashboardUrl } = requireAuth();
|
|
21625
21643
|
try {
|
|
21626
|
-
const
|
|
21627
|
-
if (
|
|
21644
|
+
const results = await api.query("organization.getAllByUserId", undefined);
|
|
21645
|
+
if (results.length === 0) {
|
|
21628
21646
|
error("No organizations found. Create one in the dashboard first.");
|
|
21629
21647
|
process.exit(1);
|
|
21630
21648
|
}
|
|
21631
21649
|
const orgChoice = await esm_default3({
|
|
21632
21650
|
message: "Select an organization:",
|
|
21633
|
-
choices:
|
|
21634
|
-
name:
|
|
21635
|
-
value:
|
|
21636
|
-
description:
|
|
21651
|
+
choices: results.map((r) => ({
|
|
21652
|
+
name: r.organization.name,
|
|
21653
|
+
value: r,
|
|
21654
|
+
description: r.organization.slug
|
|
21637
21655
|
}))
|
|
21638
21656
|
});
|
|
21639
|
-
const projects =
|
|
21640
|
-
organizationId: orgChoice.id,
|
|
21641
|
-
organizationSlug: orgChoice.slug
|
|
21642
|
-
});
|
|
21657
|
+
const projects = orgChoice.projects;
|
|
21643
21658
|
if (projects.length === 0) {
|
|
21644
21659
|
error("No projects found in this organization. Create one in the dashboard first.");
|
|
21645
21660
|
process.exit(1);
|
|
@@ -21653,8 +21668,8 @@ var initCommand = new Command("init").description("Set up project context for th
|
|
|
21653
21668
|
}))
|
|
21654
21669
|
});
|
|
21655
21670
|
const ctx = {
|
|
21656
|
-
organizationSlug: orgChoice.slug,
|
|
21657
|
-
organizationId: orgChoice.id,
|
|
21671
|
+
organizationSlug: orgChoice.organization.slug,
|
|
21672
|
+
organizationId: orgChoice.organization.id,
|
|
21658
21673
|
projectSlug: projectChoice.slug,
|
|
21659
21674
|
projectId: projectChoice.id,
|
|
21660
21675
|
dashboardUrl
|
|
@@ -21674,7 +21689,7 @@ var initCommand = new Command("init").description("Set up project context for th
|
|
|
21674
21689
|
writeFileSync2(resolve2(process.cwd(), ".gradual.json"), `${JSON.stringify(localConfig, null, 2)}
|
|
21675
21690
|
`);
|
|
21676
21691
|
}
|
|
21677
|
-
success(`Project context set: ${orgChoice.slug}/${projectChoice.slug}`);
|
|
21692
|
+
success(`Project context set: ${orgChoice.organization.slug}/${projectChoice.slug}`);
|
|
21678
21693
|
} catch (err) {
|
|
21679
21694
|
if (err.name === "ExitPromptError") {
|
|
21680
21695
|
return;
|