ardent-cli 0.0.17 → 0.0.19
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 +189 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { readFileSync as
|
|
5
|
-
import { Command as
|
|
4
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
5
|
+
import { Command as Command8 } from "commander";
|
|
6
6
|
|
|
7
7
|
// src/commands/branch/index.ts
|
|
8
8
|
import { Command } from "commander";
|
|
@@ -712,6 +712,7 @@ async function createAction2(type, url, options) {
|
|
|
712
712
|
if (!options.awsRoleArn) missing.push("--aws-role-arn");
|
|
713
713
|
if (!options.awsExternalId) missing.push("--aws-external-id");
|
|
714
714
|
if (!options.awsRegion) missing.push("--aws-region");
|
|
715
|
+
if (!options.awsClusterName) missing.push("--aws-cluster-name");
|
|
715
716
|
if (missing.length > 0) {
|
|
716
717
|
console.error(
|
|
717
718
|
`\u2717 ${missing.join(", ")} required when --deployment-model=customer-cloud`
|
|
@@ -719,10 +720,10 @@ async function createAction2(type, url, options) {
|
|
|
719
720
|
process.exit(1);
|
|
720
721
|
}
|
|
721
722
|
} else {
|
|
722
|
-
const stray = options.awsRoleArn || options.awsExternalId || options.awsRegion;
|
|
723
|
+
const stray = options.awsRoleArn || options.awsExternalId || options.awsRegion || options.awsClusterName;
|
|
723
724
|
if (stray) {
|
|
724
725
|
console.error(
|
|
725
|
-
"\u2717 --aws-role-arn / --aws-external-id / --aws-region require --deployment-model=customer-cloud"
|
|
726
|
+
"\u2717 --aws-role-arn / --aws-external-id / --aws-region / --aws-cluster-name require --deployment-model=customer-cloud"
|
|
726
727
|
);
|
|
727
728
|
process.exit(1);
|
|
728
729
|
}
|
|
@@ -793,7 +794,8 @@ async function createAction2(type, url, options) {
|
|
|
793
794
|
createPayload.byoc_access_credentials = {
|
|
794
795
|
role_arn: options.awsRoleArn,
|
|
795
796
|
external_id: options.awsExternalId,
|
|
796
|
-
region: options.awsRegion
|
|
797
|
+
region: options.awsRegion,
|
|
798
|
+
cluster_name: options.awsClusterName
|
|
797
799
|
};
|
|
798
800
|
}
|
|
799
801
|
const created = await api.post("/v1/connectors", createPayload);
|
|
@@ -1064,6 +1066,9 @@ connectorCommand.command("create <type> [url]").description("Create a new connec
|
|
|
1064
1066
|
).option(
|
|
1065
1067
|
"--aws-region <region>",
|
|
1066
1068
|
"AWS region of the customer data plane (required with --deployment-model=customer-cloud)"
|
|
1069
|
+
).option(
|
|
1070
|
+
"--aws-cluster-name <name>",
|
|
1071
|
+
"EKS cluster name in the customer account where pgstream pods run (required with --deployment-model=customer-cloud)"
|
|
1067
1072
|
).action(createAction2);
|
|
1068
1073
|
connectorCommand.command("list").description("List your connectors").action(listAction2);
|
|
1069
1074
|
connectorCommand.command("switch <name>").description("Switch to a different connector").action(switchAction2);
|
|
@@ -1440,9 +1445,174 @@ projectCommand.command("create <name>").description("Create a new project").acti
|
|
|
1440
1445
|
projectCommand.command("list").description("List your projects").action(listAction4);
|
|
1441
1446
|
projectCommand.command("switch <name>").description("Switch to a different project").action(switchAction3);
|
|
1442
1447
|
|
|
1443
|
-
// src/commands/
|
|
1448
|
+
// src/commands/settings/index.ts
|
|
1444
1449
|
import { Command as Command6 } from "commander";
|
|
1445
1450
|
|
|
1451
|
+
// src/lib/settings.ts
|
|
1452
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
1453
|
+
var SETTING_KEYS = ["default_db", "branch_sql"];
|
|
1454
|
+
function requireConnectorAndOrg() {
|
|
1455
|
+
const connectorId = getConfig("currentConnectorId");
|
|
1456
|
+
const user = getConfig("user");
|
|
1457
|
+
const orgId = user?.org_id;
|
|
1458
|
+
if (!connectorId) {
|
|
1459
|
+
console.error("\u2717 No connector selected. Run 'ardent connector switch' first.");
|
|
1460
|
+
process.exit(1);
|
|
1461
|
+
}
|
|
1462
|
+
if (!orgId) {
|
|
1463
|
+
console.error("\u2717 Not logged in. Run 'ardent login' first.");
|
|
1464
|
+
process.exit(1);
|
|
1465
|
+
}
|
|
1466
|
+
return {
|
|
1467
|
+
connectorId,
|
|
1468
|
+
connectorName: getConfig("currentConnectorName") ?? connectorId,
|
|
1469
|
+
orgId
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
function parseSettingKey(key) {
|
|
1473
|
+
if (!SETTING_KEYS.includes(key)) {
|
|
1474
|
+
console.error(`\u2717 Unknown setting '${key}'. Valid: ${SETTING_KEYS.join(", ")}`);
|
|
1475
|
+
process.exit(1);
|
|
1476
|
+
}
|
|
1477
|
+
return key;
|
|
1478
|
+
}
|
|
1479
|
+
var SETTING_DESCRIPTIONS = {
|
|
1480
|
+
default_db: "Default database in branch URLs",
|
|
1481
|
+
branch_sql: "SQL to run on every new branch after creation"
|
|
1482
|
+
};
|
|
1483
|
+
function settingKeyToPolicyType(key) {
|
|
1484
|
+
if (key === "default_db") return "connection_default_db";
|
|
1485
|
+
if (key === "branch_sql") return "branch_create_hook";
|
|
1486
|
+
throw new Error(`Unknown setting key: ${key}`);
|
|
1487
|
+
}
|
|
1488
|
+
function buildPolicyConfig(key, value) {
|
|
1489
|
+
if (key === "default_db") return { database: value };
|
|
1490
|
+
if (key === "branch_sql") return { sql: value };
|
|
1491
|
+
throw new Error(`Unknown setting key: ${key}`);
|
|
1492
|
+
}
|
|
1493
|
+
function readSettingValue(key, config) {
|
|
1494
|
+
if (key === "default_db") return String(config.database ?? "");
|
|
1495
|
+
if (key === "branch_sql") return String(config.sql ?? "");
|
|
1496
|
+
throw new Error(`Unknown setting key: ${key}`);
|
|
1497
|
+
}
|
|
1498
|
+
function resolveValueFromArg(value) {
|
|
1499
|
+
if (value.startsWith("@")) {
|
|
1500
|
+
const path = value.slice(1);
|
|
1501
|
+
try {
|
|
1502
|
+
return readFileSync3(path, "utf-8");
|
|
1503
|
+
} catch (err) {
|
|
1504
|
+
throw new Error(
|
|
1505
|
+
`Failed to read ${path}: ${err instanceof Error ? err.message : String(err)}`
|
|
1506
|
+
);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
return value;
|
|
1510
|
+
}
|
|
1511
|
+
async function findPolicyForConnector(orgId, connectorId, policyType) {
|
|
1512
|
+
const policies = await api.get(
|
|
1513
|
+
`/v1/policies?org_id=${orgId}&connector_id=${connectorId}`
|
|
1514
|
+
);
|
|
1515
|
+
return policies.find((policy) => policy.type === policyType) ?? null;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
// src/commands/settings/list.ts
|
|
1519
|
+
async function listAction5() {
|
|
1520
|
+
const { connectorId, connectorName, orgId } = requireConnectorAndOrg();
|
|
1521
|
+
try {
|
|
1522
|
+
console.log(`Connector: ${connectorName}
|
|
1523
|
+
`);
|
|
1524
|
+
for (const key of SETTING_KEYS) {
|
|
1525
|
+
const policy = await findPolicyForConnector(
|
|
1526
|
+
orgId,
|
|
1527
|
+
connectorId,
|
|
1528
|
+
settingKeyToPolicyType(key)
|
|
1529
|
+
);
|
|
1530
|
+
if (policy) {
|
|
1531
|
+
const value = readSettingValue(key, policy.config);
|
|
1532
|
+
const display = value.length > 80 ? value.slice(0, 77) + "..." : value;
|
|
1533
|
+
console.log(` ${key.padEnd(12)} ${display}`);
|
|
1534
|
+
} else {
|
|
1535
|
+
console.log(` ${key.padEnd(12)} (not set) \u2014 ${SETTING_DESCRIPTIONS[key]}`);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
trackEvent("CLI: settings list succeeded");
|
|
1539
|
+
} catch (err) {
|
|
1540
|
+
trackEvent("CLI: settings list failed", { reason: "api_error" });
|
|
1541
|
+
console.error("\u2717 Failed:", err instanceof Error ? err.message : err);
|
|
1542
|
+
process.exit(1);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
// src/commands/settings/set.ts
|
|
1547
|
+
async function setAction(key, value) {
|
|
1548
|
+
const settingKey = parseSettingKey(key);
|
|
1549
|
+
const { connectorId, orgId } = requireConnectorAndOrg();
|
|
1550
|
+
let resolvedValue;
|
|
1551
|
+
try {
|
|
1552
|
+
resolvedValue = resolveValueFromArg(value);
|
|
1553
|
+
} catch (err) {
|
|
1554
|
+
console.error("\u2717", err instanceof Error ? err.message : err);
|
|
1555
|
+
process.exit(1);
|
|
1556
|
+
}
|
|
1557
|
+
const policyType = settingKeyToPolicyType(settingKey);
|
|
1558
|
+
const config = buildPolicyConfig(settingKey, resolvedValue);
|
|
1559
|
+
try {
|
|
1560
|
+
const existing = await findPolicyForConnector(orgId, connectorId, policyType);
|
|
1561
|
+
if (existing) {
|
|
1562
|
+
await api.patch(`/v1/policies/${existing.id}`, { config });
|
|
1563
|
+
console.log(`\u2713 Updated ${settingKey}`);
|
|
1564
|
+
trackEvent("CLI: settings set succeeded", { key: settingKey, op: "update" });
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
await api.post("/v1/policies", {
|
|
1568
|
+
org_id: orgId,
|
|
1569
|
+
name: settingKey,
|
|
1570
|
+
type: policyType,
|
|
1571
|
+
config,
|
|
1572
|
+
assign_to_scope: { scope_type: "connectors", scope_id: connectorId }
|
|
1573
|
+
});
|
|
1574
|
+
console.log(`\u2713 Set ${settingKey}`);
|
|
1575
|
+
trackEvent("CLI: settings set succeeded", { key: settingKey, op: "create" });
|
|
1576
|
+
} catch (err) {
|
|
1577
|
+
trackEvent("CLI: settings set failed", { key: settingKey });
|
|
1578
|
+
console.error("\u2717 Failed:", err instanceof Error ? err.message : err);
|
|
1579
|
+
process.exit(1);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// src/commands/settings/remove.ts
|
|
1584
|
+
async function removeAction2(key) {
|
|
1585
|
+
const settingKey = parseSettingKey(key);
|
|
1586
|
+
const { connectorId, orgId } = requireConnectorAndOrg();
|
|
1587
|
+
const policyType = settingKeyToPolicyType(settingKey);
|
|
1588
|
+
try {
|
|
1589
|
+
const existing = await findPolicyForConnector(orgId, connectorId, policyType);
|
|
1590
|
+
if (!existing) {
|
|
1591
|
+
console.log(`${settingKey} is not set`);
|
|
1592
|
+
trackEvent("CLI: settings remove noop", { key: settingKey });
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
await api.delete(`/v1/policies/${existing.id}`);
|
|
1596
|
+
console.log(`\u2713 Removed ${settingKey}`);
|
|
1597
|
+
trackEvent("CLI: settings remove succeeded", { key: settingKey });
|
|
1598
|
+
} catch (err) {
|
|
1599
|
+
trackEvent("CLI: settings remove failed", { key: settingKey });
|
|
1600
|
+
console.error("\u2717 Failed:", err instanceof Error ? err.message : err);
|
|
1601
|
+
process.exit(1);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
// src/commands/settings/index.ts
|
|
1606
|
+
var settingsCommand = new Command6("settings").description("Manage settings for the current connector").showHelpAfterError("(run 'ardent settings --help' for valid keys)");
|
|
1607
|
+
settingsCommand.command("list").description("List current settings for the connector").action(listAction5);
|
|
1608
|
+
settingsCommand.command("set <key> <value>").description(
|
|
1609
|
+
"Set a setting. Keys: default_db, branch_sql. For branch_sql, prefix value with @ to read from file."
|
|
1610
|
+
).action(setAction);
|
|
1611
|
+
settingsCommand.command("remove <key>").description("Remove a setting. Keys: default_db, branch_sql.").action(removeAction2);
|
|
1612
|
+
|
|
1613
|
+
// src/commands/auth/index.ts
|
|
1614
|
+
import { Command as Command7 } from "commander";
|
|
1615
|
+
|
|
1446
1616
|
// src/commands/auth/login.ts
|
|
1447
1617
|
async function loginAction(options) {
|
|
1448
1618
|
if (options.token) {
|
|
@@ -1572,12 +1742,12 @@ function statusAction() {
|
|
|
1572
1742
|
}
|
|
1573
1743
|
|
|
1574
1744
|
// src/commands/auth/index.ts
|
|
1575
|
-
var loginCommand = new
|
|
1576
|
-
var logoutCommand = new
|
|
1577
|
-
var statusCommand = new
|
|
1745
|
+
var loginCommand = new Command7("login").description("Login to Ardent").option("-t, --token <token>", "API token (skip browser login)").action(loginAction);
|
|
1746
|
+
var logoutCommand = new Command7("logout").description("Logout from Ardent").action(logoutAction);
|
|
1747
|
+
var statusCommand = new Command7("status").description("Show status").action(statusAction);
|
|
1578
1748
|
|
|
1579
1749
|
// src/lib/update-check.ts
|
|
1580
|
-
import { existsSync as existsSync2, readFileSync as
|
|
1750
|
+
import { existsSync as existsSync2, readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "fs";
|
|
1581
1751
|
import { join as join2 } from "path";
|
|
1582
1752
|
import { homedir as homedir2 } from "os";
|
|
1583
1753
|
var UPDATE_CHECK_FILE = join2(homedir2(), ".ardent", "update-check.json");
|
|
@@ -1586,7 +1756,7 @@ var PACKAGE_NAME = "ardent-cli";
|
|
|
1586
1756
|
function loadCache() {
|
|
1587
1757
|
try {
|
|
1588
1758
|
if (existsSync2(UPDATE_CHECK_FILE)) {
|
|
1589
|
-
return JSON.parse(
|
|
1759
|
+
return JSON.parse(readFileSync4(UPDATE_CHECK_FILE, "utf-8"));
|
|
1590
1760
|
}
|
|
1591
1761
|
} catch {
|
|
1592
1762
|
}
|
|
@@ -1679,6 +1849,11 @@ BRANCHES
|
|
|
1679
1849
|
branch delete Delete a branch
|
|
1680
1850
|
branch switch Switch to a different branch
|
|
1681
1851
|
|
|
1852
|
+
SETTINGS
|
|
1853
|
+
settings list List current settings for the connector
|
|
1854
|
+
settings set Set a setting (e.g. default_db testdb)
|
|
1855
|
+
settings remove Remove a setting
|
|
1856
|
+
|
|
1682
1857
|
TEAM
|
|
1683
1858
|
invite <email> Invite a user to your organization
|
|
1684
1859
|
invite list List pending invites
|
|
@@ -1699,11 +1874,11 @@ EXAMPLES
|
|
|
1699
1874
|
ardent org members
|
|
1700
1875
|
`;
|
|
1701
1876
|
var CLI_VERSION2 = getCliVersion2();
|
|
1702
|
-
var program = new
|
|
1877
|
+
var program = new Command8();
|
|
1703
1878
|
function getCliVersion2() {
|
|
1704
1879
|
try {
|
|
1705
1880
|
const packageUrl = new URL("../package.json", import.meta.url);
|
|
1706
|
-
const raw =
|
|
1881
|
+
const raw = readFileSync5(packageUrl, "utf-8");
|
|
1707
1882
|
const parsed = JSON.parse(raw);
|
|
1708
1883
|
return parsed.version ?? "unknown";
|
|
1709
1884
|
} catch {
|
|
@@ -1719,6 +1894,7 @@ program.addCommand(statusCommand);
|
|
|
1719
1894
|
program.addCommand(projectCommand);
|
|
1720
1895
|
program.addCommand(connectorCommand);
|
|
1721
1896
|
program.addCommand(branchCommand);
|
|
1897
|
+
program.addCommand(settingsCommand);
|
|
1722
1898
|
program.addCommand(inviteCommand);
|
|
1723
1899
|
program.addCommand(orgCommand);
|
|
1724
1900
|
program.on("command:*", (operands) => {
|