ardent-cli 0.0.17 → 0.0.18
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 +181 -10
- 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";
|
|
@@ -1440,9 +1440,174 @@ projectCommand.command("create <name>").description("Create a new project").acti
|
|
|
1440
1440
|
projectCommand.command("list").description("List your projects").action(listAction4);
|
|
1441
1441
|
projectCommand.command("switch <name>").description("Switch to a different project").action(switchAction3);
|
|
1442
1442
|
|
|
1443
|
-
// src/commands/
|
|
1443
|
+
// src/commands/settings/index.ts
|
|
1444
1444
|
import { Command as Command6 } from "commander";
|
|
1445
1445
|
|
|
1446
|
+
// src/lib/settings.ts
|
|
1447
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
1448
|
+
var SETTING_KEYS = ["default_db", "branch_sql"];
|
|
1449
|
+
function requireConnectorAndOrg() {
|
|
1450
|
+
const connectorId = getConfig("currentConnectorId");
|
|
1451
|
+
const user = getConfig("user");
|
|
1452
|
+
const orgId = user?.org_id;
|
|
1453
|
+
if (!connectorId) {
|
|
1454
|
+
console.error("\u2717 No connector selected. Run 'ardent connector switch' first.");
|
|
1455
|
+
process.exit(1);
|
|
1456
|
+
}
|
|
1457
|
+
if (!orgId) {
|
|
1458
|
+
console.error("\u2717 Not logged in. Run 'ardent login' first.");
|
|
1459
|
+
process.exit(1);
|
|
1460
|
+
}
|
|
1461
|
+
return {
|
|
1462
|
+
connectorId,
|
|
1463
|
+
connectorName: getConfig("currentConnectorName") ?? connectorId,
|
|
1464
|
+
orgId
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
function parseSettingKey(key) {
|
|
1468
|
+
if (!SETTING_KEYS.includes(key)) {
|
|
1469
|
+
console.error(`\u2717 Unknown setting '${key}'. Valid: ${SETTING_KEYS.join(", ")}`);
|
|
1470
|
+
process.exit(1);
|
|
1471
|
+
}
|
|
1472
|
+
return key;
|
|
1473
|
+
}
|
|
1474
|
+
var SETTING_DESCRIPTIONS = {
|
|
1475
|
+
default_db: "Default database in branch URLs",
|
|
1476
|
+
branch_sql: "SQL to run on every new branch after creation"
|
|
1477
|
+
};
|
|
1478
|
+
function settingKeyToPolicyType(key) {
|
|
1479
|
+
if (key === "default_db") return "connection_default_db";
|
|
1480
|
+
if (key === "branch_sql") return "branch_create_hook";
|
|
1481
|
+
throw new Error(`Unknown setting key: ${key}`);
|
|
1482
|
+
}
|
|
1483
|
+
function buildPolicyConfig(key, value) {
|
|
1484
|
+
if (key === "default_db") return { database: value };
|
|
1485
|
+
if (key === "branch_sql") return { sql: value };
|
|
1486
|
+
throw new Error(`Unknown setting key: ${key}`);
|
|
1487
|
+
}
|
|
1488
|
+
function readSettingValue(key, config) {
|
|
1489
|
+
if (key === "default_db") return String(config.database ?? "");
|
|
1490
|
+
if (key === "branch_sql") return String(config.sql ?? "");
|
|
1491
|
+
throw new Error(`Unknown setting key: ${key}`);
|
|
1492
|
+
}
|
|
1493
|
+
function resolveValueFromArg(value) {
|
|
1494
|
+
if (value.startsWith("@")) {
|
|
1495
|
+
const path = value.slice(1);
|
|
1496
|
+
try {
|
|
1497
|
+
return readFileSync3(path, "utf-8");
|
|
1498
|
+
} catch (err) {
|
|
1499
|
+
throw new Error(
|
|
1500
|
+
`Failed to read ${path}: ${err instanceof Error ? err.message : String(err)}`
|
|
1501
|
+
);
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
return value;
|
|
1505
|
+
}
|
|
1506
|
+
async function findPolicyForConnector(orgId, connectorId, policyType) {
|
|
1507
|
+
const policies = await api.get(
|
|
1508
|
+
`/v1/policies?org_id=${orgId}&connector_id=${connectorId}`
|
|
1509
|
+
);
|
|
1510
|
+
return policies.find((policy) => policy.type === policyType) ?? null;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
// src/commands/settings/list.ts
|
|
1514
|
+
async function listAction5() {
|
|
1515
|
+
const { connectorId, connectorName, orgId } = requireConnectorAndOrg();
|
|
1516
|
+
try {
|
|
1517
|
+
console.log(`Connector: ${connectorName}
|
|
1518
|
+
`);
|
|
1519
|
+
for (const key of SETTING_KEYS) {
|
|
1520
|
+
const policy = await findPolicyForConnector(
|
|
1521
|
+
orgId,
|
|
1522
|
+
connectorId,
|
|
1523
|
+
settingKeyToPolicyType(key)
|
|
1524
|
+
);
|
|
1525
|
+
if (policy) {
|
|
1526
|
+
const value = readSettingValue(key, policy.config);
|
|
1527
|
+
const display = value.length > 80 ? value.slice(0, 77) + "..." : value;
|
|
1528
|
+
console.log(` ${key.padEnd(12)} ${display}`);
|
|
1529
|
+
} else {
|
|
1530
|
+
console.log(` ${key.padEnd(12)} (not set) \u2014 ${SETTING_DESCRIPTIONS[key]}`);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
trackEvent("CLI: settings list succeeded");
|
|
1534
|
+
} catch (err) {
|
|
1535
|
+
trackEvent("CLI: settings list failed", { reason: "api_error" });
|
|
1536
|
+
console.error("\u2717 Failed:", err instanceof Error ? err.message : err);
|
|
1537
|
+
process.exit(1);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
// src/commands/settings/set.ts
|
|
1542
|
+
async function setAction(key, value) {
|
|
1543
|
+
const settingKey = parseSettingKey(key);
|
|
1544
|
+
const { connectorId, orgId } = requireConnectorAndOrg();
|
|
1545
|
+
let resolvedValue;
|
|
1546
|
+
try {
|
|
1547
|
+
resolvedValue = resolveValueFromArg(value);
|
|
1548
|
+
} catch (err) {
|
|
1549
|
+
console.error("\u2717", err instanceof Error ? err.message : err);
|
|
1550
|
+
process.exit(1);
|
|
1551
|
+
}
|
|
1552
|
+
const policyType = settingKeyToPolicyType(settingKey);
|
|
1553
|
+
const config = buildPolicyConfig(settingKey, resolvedValue);
|
|
1554
|
+
try {
|
|
1555
|
+
const existing = await findPolicyForConnector(orgId, connectorId, policyType);
|
|
1556
|
+
if (existing) {
|
|
1557
|
+
await api.patch(`/v1/policies/${existing.id}`, { config });
|
|
1558
|
+
console.log(`\u2713 Updated ${settingKey}`);
|
|
1559
|
+
trackEvent("CLI: settings set succeeded", { key: settingKey, op: "update" });
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
await api.post("/v1/policies", {
|
|
1563
|
+
org_id: orgId,
|
|
1564
|
+
name: settingKey,
|
|
1565
|
+
type: policyType,
|
|
1566
|
+
config,
|
|
1567
|
+
assign_to_scope: { scope_type: "connectors", scope_id: connectorId }
|
|
1568
|
+
});
|
|
1569
|
+
console.log(`\u2713 Set ${settingKey}`);
|
|
1570
|
+
trackEvent("CLI: settings set succeeded", { key: settingKey, op: "create" });
|
|
1571
|
+
} catch (err) {
|
|
1572
|
+
trackEvent("CLI: settings set failed", { key: settingKey });
|
|
1573
|
+
console.error("\u2717 Failed:", err instanceof Error ? err.message : err);
|
|
1574
|
+
process.exit(1);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
// src/commands/settings/remove.ts
|
|
1579
|
+
async function removeAction2(key) {
|
|
1580
|
+
const settingKey = parseSettingKey(key);
|
|
1581
|
+
const { connectorId, orgId } = requireConnectorAndOrg();
|
|
1582
|
+
const policyType = settingKeyToPolicyType(settingKey);
|
|
1583
|
+
try {
|
|
1584
|
+
const existing = await findPolicyForConnector(orgId, connectorId, policyType);
|
|
1585
|
+
if (!existing) {
|
|
1586
|
+
console.log(`${settingKey} is not set`);
|
|
1587
|
+
trackEvent("CLI: settings remove noop", { key: settingKey });
|
|
1588
|
+
return;
|
|
1589
|
+
}
|
|
1590
|
+
await api.delete(`/v1/policies/${existing.id}`);
|
|
1591
|
+
console.log(`\u2713 Removed ${settingKey}`);
|
|
1592
|
+
trackEvent("CLI: settings remove succeeded", { key: settingKey });
|
|
1593
|
+
} catch (err) {
|
|
1594
|
+
trackEvent("CLI: settings remove failed", { key: settingKey });
|
|
1595
|
+
console.error("\u2717 Failed:", err instanceof Error ? err.message : err);
|
|
1596
|
+
process.exit(1);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
// src/commands/settings/index.ts
|
|
1601
|
+
var settingsCommand = new Command6("settings").description("Manage settings for the current connector").showHelpAfterError("(run 'ardent settings --help' for valid keys)");
|
|
1602
|
+
settingsCommand.command("list").description("List current settings for the connector").action(listAction5);
|
|
1603
|
+
settingsCommand.command("set <key> <value>").description(
|
|
1604
|
+
"Set a setting. Keys: default_db, branch_sql. For branch_sql, prefix value with @ to read from file."
|
|
1605
|
+
).action(setAction);
|
|
1606
|
+
settingsCommand.command("remove <key>").description("Remove a setting. Keys: default_db, branch_sql.").action(removeAction2);
|
|
1607
|
+
|
|
1608
|
+
// src/commands/auth/index.ts
|
|
1609
|
+
import { Command as Command7 } from "commander";
|
|
1610
|
+
|
|
1446
1611
|
// src/commands/auth/login.ts
|
|
1447
1612
|
async function loginAction(options) {
|
|
1448
1613
|
if (options.token) {
|
|
@@ -1572,12 +1737,12 @@ function statusAction() {
|
|
|
1572
1737
|
}
|
|
1573
1738
|
|
|
1574
1739
|
// src/commands/auth/index.ts
|
|
1575
|
-
var loginCommand = new
|
|
1576
|
-
var logoutCommand = new
|
|
1577
|
-
var statusCommand = new
|
|
1740
|
+
var loginCommand = new Command7("login").description("Login to Ardent").option("-t, --token <token>", "API token (skip browser login)").action(loginAction);
|
|
1741
|
+
var logoutCommand = new Command7("logout").description("Logout from Ardent").action(logoutAction);
|
|
1742
|
+
var statusCommand = new Command7("status").description("Show status").action(statusAction);
|
|
1578
1743
|
|
|
1579
1744
|
// src/lib/update-check.ts
|
|
1580
|
-
import { existsSync as existsSync2, readFileSync as
|
|
1745
|
+
import { existsSync as existsSync2, readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "fs";
|
|
1581
1746
|
import { join as join2 } from "path";
|
|
1582
1747
|
import { homedir as homedir2 } from "os";
|
|
1583
1748
|
var UPDATE_CHECK_FILE = join2(homedir2(), ".ardent", "update-check.json");
|
|
@@ -1586,7 +1751,7 @@ var PACKAGE_NAME = "ardent-cli";
|
|
|
1586
1751
|
function loadCache() {
|
|
1587
1752
|
try {
|
|
1588
1753
|
if (existsSync2(UPDATE_CHECK_FILE)) {
|
|
1589
|
-
return JSON.parse(
|
|
1754
|
+
return JSON.parse(readFileSync4(UPDATE_CHECK_FILE, "utf-8"));
|
|
1590
1755
|
}
|
|
1591
1756
|
} catch {
|
|
1592
1757
|
}
|
|
@@ -1679,6 +1844,11 @@ BRANCHES
|
|
|
1679
1844
|
branch delete Delete a branch
|
|
1680
1845
|
branch switch Switch to a different branch
|
|
1681
1846
|
|
|
1847
|
+
SETTINGS
|
|
1848
|
+
settings list List current settings for the connector
|
|
1849
|
+
settings set Set a setting (e.g. default_db testdb)
|
|
1850
|
+
settings remove Remove a setting
|
|
1851
|
+
|
|
1682
1852
|
TEAM
|
|
1683
1853
|
invite <email> Invite a user to your organization
|
|
1684
1854
|
invite list List pending invites
|
|
@@ -1699,11 +1869,11 @@ EXAMPLES
|
|
|
1699
1869
|
ardent org members
|
|
1700
1870
|
`;
|
|
1701
1871
|
var CLI_VERSION2 = getCliVersion2();
|
|
1702
|
-
var program = new
|
|
1872
|
+
var program = new Command8();
|
|
1703
1873
|
function getCliVersion2() {
|
|
1704
1874
|
try {
|
|
1705
1875
|
const packageUrl = new URL("../package.json", import.meta.url);
|
|
1706
|
-
const raw =
|
|
1876
|
+
const raw = readFileSync5(packageUrl, "utf-8");
|
|
1707
1877
|
const parsed = JSON.parse(raw);
|
|
1708
1878
|
return parsed.version ?? "unknown";
|
|
1709
1879
|
} catch {
|
|
@@ -1719,6 +1889,7 @@ program.addCommand(statusCommand);
|
|
|
1719
1889
|
program.addCommand(projectCommand);
|
|
1720
1890
|
program.addCommand(connectorCommand);
|
|
1721
1891
|
program.addCommand(branchCommand);
|
|
1892
|
+
program.addCommand(settingsCommand);
|
|
1722
1893
|
program.addCommand(inviteCommand);
|
|
1723
1894
|
program.addCommand(orgCommand);
|
|
1724
1895
|
program.on("command:*", (operands) => {
|