@engini/cli 0.15.0 → 0.17.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 +359 -32
- package/package.json +4 -2
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { realpathSync } from "fs";
|
|
5
|
+
import { pathToFileURL } from "url";
|
|
6
|
+
|
|
3
7
|
// src/prompt.ts
|
|
4
8
|
import { spawn } from "child_process";
|
|
5
9
|
import { createInterface } from "readline";
|
|
@@ -243,6 +247,9 @@ function setOutputContext(ctx) {
|
|
|
243
247
|
function dryRun() {
|
|
244
248
|
return context.dryRun;
|
|
245
249
|
}
|
|
250
|
+
function outputFlags() {
|
|
251
|
+
return { forceJson: context.forceJson, quiet: context.quiet };
|
|
252
|
+
}
|
|
246
253
|
function formatValue(value) {
|
|
247
254
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
248
255
|
}
|
|
@@ -430,19 +437,28 @@ function saveConfig(config, path = configPath()) {
|
|
|
430
437
|
if (process.platform !== "win32") chmodSync(path, 384);
|
|
431
438
|
}
|
|
432
439
|
|
|
440
|
+
// src/version.ts
|
|
441
|
+
var VERSION = true ? "0.17.0" : "0.0.0";
|
|
442
|
+
|
|
433
443
|
// src/http.ts
|
|
444
|
+
var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
|
|
434
445
|
function buildClient(overrides = {}) {
|
|
435
446
|
const config = loadConfig();
|
|
436
447
|
const key = overrides.apiKey ?? process.env[ENV_API_KEY_VAR] ?? config.api_key;
|
|
437
448
|
if (key) {
|
|
438
|
-
return new Engini({ apiKey: key, baseUrl: config.api_url });
|
|
449
|
+
return new Engini({ apiKey: key, baseUrl: config.api_url, userAgentPrefix: USER_AGENT_PREFIX });
|
|
439
450
|
}
|
|
440
451
|
const token = overrides.apiToken ?? process.env[ENV_TOKEN_VAR] ?? config.api_token;
|
|
441
452
|
const company = overrides.companyToken ?? process.env[ENV_COMPANY_TOKEN_VAR] ?? config.company_token;
|
|
442
453
|
if (!token) {
|
|
443
454
|
fail(3 /* AUTH */, "No credentials found. Run `engini login`.");
|
|
444
455
|
}
|
|
445
|
-
return new Engini({
|
|
456
|
+
return new Engini({
|
|
457
|
+
token,
|
|
458
|
+
companyToken: company,
|
|
459
|
+
baseUrl: config.api_url,
|
|
460
|
+
userAgentPrefix: USER_AGENT_PREFIX
|
|
461
|
+
});
|
|
446
462
|
}
|
|
447
463
|
function exitForError(err) {
|
|
448
464
|
if (err instanceof EnginiAuthError) return 3 /* AUTH */;
|
|
@@ -986,6 +1002,71 @@ function registerConnectionsCreate(connections) {
|
|
|
986
1002
|
});
|
|
987
1003
|
}
|
|
988
1004
|
|
|
1005
|
+
// src/connections/defaults.ts
|
|
1006
|
+
function summarize2(d) {
|
|
1007
|
+
return {
|
|
1008
|
+
application_slug: clean(d.applicationSlug),
|
|
1009
|
+
connection_id: clean(d.connectionId),
|
|
1010
|
+
connection_name: clean(d.connectionName)
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
async function listBody2() {
|
|
1014
|
+
const rows = await apiErrors(async () => {
|
|
1015
|
+
const client = buildClient();
|
|
1016
|
+
return client.connections.defaults();
|
|
1017
|
+
});
|
|
1018
|
+
printOutput(rows.map(summarize2));
|
|
1019
|
+
}
|
|
1020
|
+
async function setBody(idRaw) {
|
|
1021
|
+
const connectionId = parseId(idRaw);
|
|
1022
|
+
if (dryRun()) {
|
|
1023
|
+
printOutput({ would_set_default: { connection_id: connectionId } });
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
await apiErrors(async () => {
|
|
1027
|
+
const client = buildClient();
|
|
1028
|
+
return client.connections.setDefault(connectionId);
|
|
1029
|
+
});
|
|
1030
|
+
printOutput({ set_default: { connection_id: connectionId } });
|
|
1031
|
+
}
|
|
1032
|
+
async function clearBody(application) {
|
|
1033
|
+
if (!application) fail(2 /* USAGE */, "Missing required argument 'application'.");
|
|
1034
|
+
if (dryRun()) {
|
|
1035
|
+
printOutput({ would_clear_default: { application_slug: application } });
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
await apiErrors(async () => {
|
|
1039
|
+
const client = buildClient();
|
|
1040
|
+
return client.connections.clearDefault(application);
|
|
1041
|
+
});
|
|
1042
|
+
printOutput({ cleared_default: { application_slug: application } });
|
|
1043
|
+
}
|
|
1044
|
+
function registerConnectionsDefaults(connections) {
|
|
1045
|
+
const list = connections.command("defaults").description("List your per-application default connections.");
|
|
1046
|
+
list.addHelpText(
|
|
1047
|
+
"after",
|
|
1048
|
+
"\nExamples:\n engini connections defaults --json\n engini connections defaults | jq -r '.[].application_slug'"
|
|
1049
|
+
);
|
|
1050
|
+
addUniversalOptions(list);
|
|
1051
|
+
list.action(async (opts, command) => {
|
|
1052
|
+
await runCommand(command, opts, false, () => listBody2());
|
|
1053
|
+
});
|
|
1054
|
+
const set = connections.command("set-default").description("Make a connection the default for its application.").argument("[connection_id]", "Connection id");
|
|
1055
|
+
set.addHelpText("after", "\nExamples:\n engini connections set-default 481");
|
|
1056
|
+
addUniversalOptions(set, { mutating: true });
|
|
1057
|
+
set.action(async (idRaw, opts, command) => {
|
|
1058
|
+
await runCommand(command, opts, true, () => setBody(idRaw));
|
|
1059
|
+
});
|
|
1060
|
+
const clear = connections.command("clear-default").description("Clear an application's default connection.").argument("[application]", "Application slug (NOT a connection id)");
|
|
1061
|
+
clear.addHelpText("after", "\nExamples:\n engini connections clear-default monday");
|
|
1062
|
+
addUniversalOptions(clear, { mutating: true });
|
|
1063
|
+
clear.action(
|
|
1064
|
+
async (application, opts, command) => {
|
|
1065
|
+
await runCommand(command, opts, true, () => clearBody(application));
|
|
1066
|
+
}
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1069
|
+
|
|
989
1070
|
// src/connections/delete.ts
|
|
990
1071
|
async function deleteBody(connectionId, opts) {
|
|
991
1072
|
const id = parseId(connectionId);
|
|
@@ -1054,33 +1135,39 @@ function registerConnectionsGet(connections) {
|
|
|
1054
1135
|
}
|
|
1055
1136
|
|
|
1056
1137
|
// src/connections/list.ts
|
|
1057
|
-
function
|
|
1138
|
+
function summarize3(c) {
|
|
1058
1139
|
return {
|
|
1059
1140
|
connection_id: c.connectionId,
|
|
1060
1141
|
connection_name: c.connectionName,
|
|
1061
1142
|
application_slug: c.applicationSlug,
|
|
1062
1143
|
application_name: clean(c.applicationName),
|
|
1063
1144
|
description: clean(c.description),
|
|
1145
|
+
kind: clean(c.kind),
|
|
1064
1146
|
is_public: c.isPublic,
|
|
1065
1147
|
created_date: c.createdDate
|
|
1066
1148
|
};
|
|
1067
1149
|
}
|
|
1068
|
-
async function
|
|
1150
|
+
async function listBody3(opts) {
|
|
1069
1151
|
const conns = await apiErrors(async () => {
|
|
1070
1152
|
const client = buildClient();
|
|
1071
|
-
return client.connections.list(opts.application);
|
|
1153
|
+
return client.connections.list(opts.application, opts.kind);
|
|
1072
1154
|
});
|
|
1073
|
-
printOutput(conns.map(
|
|
1155
|
+
printOutput(conns.map(summarize3));
|
|
1074
1156
|
}
|
|
1075
1157
|
function registerConnectionsList(connections) {
|
|
1076
|
-
const cmd = connections.command("list").description("List your connections, optionally filtered by application.").option("--application <slug>", "Filter by application slug");
|
|
1158
|
+
const cmd = connections.command("list").description("List your connections, optionally filtered by application.").option("--application <slug>", "Filter by application slug").option("--kind <kind>", "Filter by kind: Regular | Key | OPA | MCPClient (case-insensitive)");
|
|
1077
1159
|
cmd.addHelpText(
|
|
1078
1160
|
"after",
|
|
1079
|
-
|
|
1161
|
+
`
|
|
1162
|
+
Examples:
|
|
1163
|
+
engini connections list --json
|
|
1164
|
+
engini connections list --application monday
|
|
1165
|
+
engini connections list --kind Key # the web UI's "Keys" tab
|
|
1166
|
+
engini connections list | jq -r '.[].connection_id'`
|
|
1080
1167
|
);
|
|
1081
1168
|
addUniversalOptions(cmd);
|
|
1082
1169
|
cmd.action(async (opts, command) => {
|
|
1083
|
-
await runCommand(command, opts, false, () =>
|
|
1170
|
+
await runCommand(command, opts, false, () => listBody3(opts));
|
|
1084
1171
|
});
|
|
1085
1172
|
}
|
|
1086
1173
|
|
|
@@ -1191,6 +1278,45 @@ function registerConnectionsRefresh(connections) {
|
|
|
1191
1278
|
});
|
|
1192
1279
|
}
|
|
1193
1280
|
|
|
1281
|
+
// src/connections/replace.ts
|
|
1282
|
+
function requireInt(raw, flag) {
|
|
1283
|
+
if (raw === void 0) fail(2 /* USAGE */, `Missing required option '${flag}'.`);
|
|
1284
|
+
const value = Number(raw);
|
|
1285
|
+
if (!Number.isInteger(value)) fail(2 /* USAGE */, `${flag} must be an integer.`);
|
|
1286
|
+
return value;
|
|
1287
|
+
}
|
|
1288
|
+
async function replaceBody(opts) {
|
|
1289
|
+
const workflowId = requireInt(opts.workflow, "--workflow");
|
|
1290
|
+
const originalConnectionId = requireInt(opts.from, "--from");
|
|
1291
|
+
const newConnectionId = requireInt(opts.to, "--to");
|
|
1292
|
+
if (dryRun()) {
|
|
1293
|
+
printOutput({
|
|
1294
|
+
would_replace: {
|
|
1295
|
+
workflow_id: workflowId,
|
|
1296
|
+
original_connection_id: originalConnectionId,
|
|
1297
|
+
new_connection_id: newConnectionId
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
const result = await apiErrors(async () => {
|
|
1303
|
+
const client = buildClient();
|
|
1304
|
+
return client.connections.replace({ workflowId, originalConnectionId, newConnectionId });
|
|
1305
|
+
});
|
|
1306
|
+
printOutput(result);
|
|
1307
|
+
}
|
|
1308
|
+
function registerConnectionsReplace(connections) {
|
|
1309
|
+
const cmd = connections.command("replace").description("Point one workflow at a different connection.").option("--workflow <id>", "Workflow id whose connection is being replaced").option("--from <id>", "Connection id the workflow uses today").option("--to <id>", "Connection id to use instead");
|
|
1310
|
+
cmd.addHelpText(
|
|
1311
|
+
"after",
|
|
1312
|
+
"\nExamples:\n engini connections replace --workflow 903 --from 481 --to 482 --dry-run\n engini connections replace --workflow 903 --from 481 --to 482\n\nScoped to ONE workflow \u2014 other workflows using --from are untouched.\nFails if an activity cannot be remapped onto the target connection."
|
|
1313
|
+
);
|
|
1314
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
1315
|
+
cmd.action(async (opts, command) => {
|
|
1316
|
+
await runCommand(command, opts, true, () => replaceBody(opts));
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1194
1320
|
// src/connections/select-objects.ts
|
|
1195
1321
|
async function selectBody(connectionId, opts) {
|
|
1196
1322
|
const id = parseId(connectionId);
|
|
@@ -1262,13 +1388,80 @@ function registerConnectionsSignInUrl(connections) {
|
|
|
1262
1388
|
});
|
|
1263
1389
|
}
|
|
1264
1390
|
|
|
1391
|
+
// src/connections/update.ts
|
|
1392
|
+
function summary4(c) {
|
|
1393
|
+
return {
|
|
1394
|
+
connection_id: c.connectionId,
|
|
1395
|
+
connection_name: c.connectionName,
|
|
1396
|
+
application_slug: c.applicationSlug,
|
|
1397
|
+
kind: clean(c.kind),
|
|
1398
|
+
description: clean(c.description),
|
|
1399
|
+
is_alive: clean(c.isAlive)
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
async function updateBody(idRaw, opts) {
|
|
1403
|
+
const connectionId = parseId(idRaw);
|
|
1404
|
+
const patch = {};
|
|
1405
|
+
if (opts.name !== void 0) patch.name = opts.name;
|
|
1406
|
+
if (opts.description !== void 0) patch.description = opts.description;
|
|
1407
|
+
if (opts.field !== void 0) patch.fields = parseFields(opts.field);
|
|
1408
|
+
if (opts.metadata !== void 0) patch.metadata = parseFields(opts.metadata);
|
|
1409
|
+
if (Object.keys(patch).length === 0) {
|
|
1410
|
+
fail(
|
|
1411
|
+
2 /* USAGE */,
|
|
1412
|
+
"Nothing to update. Supply at least one of --name, --description, --field, --metadata."
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
if (dryRun()) {
|
|
1416
|
+
printOutput({
|
|
1417
|
+
would_update: {
|
|
1418
|
+
connection_id: connectionId,
|
|
1419
|
+
name: patch.name ?? null,
|
|
1420
|
+
description: patch.description ?? null,
|
|
1421
|
+
fields: patch.fields === void 0 ? null : Object.fromEntries(
|
|
1422
|
+
Object.entries(patch.fields).map(([k, v]) => [k, maskSecret(v)])
|
|
1423
|
+
),
|
|
1424
|
+
metadata: patch.metadata ?? null,
|
|
1425
|
+
// Loud on purpose: this is the field-loss trap.
|
|
1426
|
+
replaces_entire_fields_map: patch.fields !== void 0,
|
|
1427
|
+
replaces_entire_metadata_map: patch.metadata !== void 0
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
const conn = await apiErrors(async () => {
|
|
1433
|
+
const client = buildClient();
|
|
1434
|
+
return client.connections.update(connectionId, patch);
|
|
1435
|
+
});
|
|
1436
|
+
printOutput(summary4(conn));
|
|
1437
|
+
}
|
|
1438
|
+
function registerConnectionsUpdate(connections) {
|
|
1439
|
+
const cmd = connections.command("update").description("Update a connection's name, description, credential fields, or metadata.").argument("[connection_id]", "Connection id").option("--name <name>", "New connection name").option("--description <text>", "New description").option("--field <spec>", "Credential field: key=value (repeatable)", collect).option("--metadata <spec>", "Metadata entry: key=value (repeatable)", collect);
|
|
1440
|
+
cmd.addHelpText(
|
|
1441
|
+
"after",
|
|
1442
|
+
"\nExamples:\n engini connections update 481 --name 'prod key'\n engini connections update 481 --field apiKey=sk-new --dry-run\n engini connections update 481 --field apiKey=sk-new\n\nWARNING: --field and --metadata REPLACE the entire map \u2014 they do not merge.\nPassing one --field clears every other field on the connection. Read the\ncurrent values with `engini connections get <id>` and pass them all, or\npreview with --dry-run first (secrets are masked in the preview)."
|
|
1443
|
+
);
|
|
1444
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
1445
|
+
cmd.action(async (idRaw, opts, command) => {
|
|
1446
|
+
await runCommand(
|
|
1447
|
+
command,
|
|
1448
|
+
opts,
|
|
1449
|
+
true,
|
|
1450
|
+
() => updateBody(idRaw, opts)
|
|
1451
|
+
);
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1265
1455
|
// src/connections/index.ts
|
|
1266
1456
|
function registerConnections(program) {
|
|
1267
1457
|
const connections = program.command("connections").description("List, inspect, create, and remove connections.");
|
|
1268
1458
|
registerConnectionsList(connections);
|
|
1269
1459
|
registerConnectionsGet(connections);
|
|
1270
1460
|
registerConnectionsCreate(connections);
|
|
1461
|
+
registerConnectionsUpdate(connections);
|
|
1271
1462
|
registerConnectionsDelete(connections);
|
|
1463
|
+
registerConnectionsReplace(connections);
|
|
1464
|
+
registerConnectionsDefaults(connections);
|
|
1272
1465
|
registerConnectionsCheck(connections);
|
|
1273
1466
|
registerConnectionsRefresh(connections);
|
|
1274
1467
|
registerConnectionsObjects(connections);
|
|
@@ -1337,10 +1530,21 @@ CONNECTIONS
|
|
|
1337
1530
|
agent-resumable when piped (prints {need, resume}).
|
|
1338
1531
|
Resume with --oauth-state <state> (OAuth) or
|
|
1339
1532
|
--connection <id> (object selection). No app \u2192 web page.
|
|
1340
|
-
connections list [--application <slug>]
|
|
1533
|
+
connections list [--application <slug>] [--kind <kind>]
|
|
1534
|
+
List your connections. --kind filters on
|
|
1535
|
+
Regular | Key | OPA | MCPClient. The web UI's
|
|
1536
|
+
"Keys" tab is --kind Key.
|
|
1341
1537
|
connections get <id> Inspect a connection.
|
|
1342
1538
|
connections create <app> --auth <id> --name <n> --field k=v
|
|
1343
1539
|
Create a direct-credential connection.
|
|
1540
|
+
connections update <id> [--name <n>] [--description <t>] [--field k=v] [--metadata k=v]
|
|
1541
|
+
Update a connection. --field/--metadata REPLACE
|
|
1542
|
+
their whole map \u2014 preview with --dry-run first.
|
|
1543
|
+
connections replace --workflow <id> --from <id> --to <id>
|
|
1544
|
+
Point ONE workflow at a different connection.
|
|
1545
|
+
connections defaults List your per-application default connections.
|
|
1546
|
+
connections set-default <id> Make a connection its application's default.
|
|
1547
|
+
connections clear-default <app> Clear an application's default (takes a slug).
|
|
1344
1548
|
connections sign-in-url <app> --auth <id> Start an OAuth2 sign-in (returns URL + state).
|
|
1345
1549
|
connections oauth-complete <app> --auth <id> --state <state>
|
|
1346
1550
|
Finish an OAuth2 sign-in and create the connection.
|
|
@@ -1377,6 +1581,7 @@ FILES & ENVIRONMENT
|
|
|
1377
1581
|
Re-run \`engini login\` to change it.
|
|
1378
1582
|
Env: ENGINI_API_KEY (preferred) or ENGINI_API_TOKEN, plus ENGINI_COMPANY_TOKEN.
|
|
1379
1583
|
Resolution order: flags > environment > config.
|
|
1584
|
+
ENGINI_NO_UPDATE_CHECK=1 skips the "update available" check on a TTY.
|
|
1380
1585
|
|
|
1381
1586
|
EXAMPLES
|
|
1382
1587
|
# Authenticate (or set ENGINI_API_KEY)
|
|
@@ -1582,20 +1787,20 @@ async function loginBody(opts) {
|
|
|
1582
1787
|
}
|
|
1583
1788
|
config.api_key = apiKey;
|
|
1584
1789
|
config.auth_kind = "api-key";
|
|
1585
|
-
const
|
|
1790
|
+
const summary6 = {
|
|
1586
1791
|
auth_kind: "api-key",
|
|
1587
1792
|
credential: maskSecret(apiKey),
|
|
1588
1793
|
api_url: config.api_url
|
|
1589
1794
|
};
|
|
1590
1795
|
if (dryRun()) {
|
|
1591
|
-
printOutput({ would_store:
|
|
1796
|
+
printOutput({ would_store: summary6 });
|
|
1592
1797
|
return;
|
|
1593
1798
|
}
|
|
1594
1799
|
if (hadCredentials) {
|
|
1595
1800
|
await confirmOrFail("Credentials already exist. Overwrite?", { force: Boolean(opts.force) });
|
|
1596
1801
|
}
|
|
1597
1802
|
saveConfig(config);
|
|
1598
|
-
printOutput({ stored:
|
|
1803
|
+
printOutput({ stored: summary6 });
|
|
1599
1804
|
}
|
|
1600
1805
|
function registerLogin(program) {
|
|
1601
1806
|
const cmd = program.command("login").description("Store an opaque Engini API key.").option("--api-key <key>", "Opaque Engini key (eng_\u2026)").option("--api-url <url>", "API base URL to persist (e.g. a staging host)").option("--identity-url <url>", "Dashboard base URL to persist (hosts the keys page)").option("--force", "Overwrite existing credentials without confirming");
|
|
@@ -2072,7 +2277,7 @@ function registerToolsGet(tools) {
|
|
|
2072
2277
|
}
|
|
2073
2278
|
|
|
2074
2279
|
// src/tools/list.ts
|
|
2075
|
-
function
|
|
2280
|
+
function summarize4(schema) {
|
|
2076
2281
|
return {
|
|
2077
2282
|
tool_slug: schema.toolSlug,
|
|
2078
2283
|
tool_name: clean(schema.toolName),
|
|
@@ -2090,7 +2295,7 @@ function parseLimit2(value) {
|
|
|
2090
2295
|
}
|
|
2091
2296
|
return limit;
|
|
2092
2297
|
}
|
|
2093
|
-
async function
|
|
2298
|
+
async function listBody4(opts) {
|
|
2094
2299
|
if (opts.application && opts.toolset) {
|
|
2095
2300
|
fail(2 /* USAGE */, "Pass only one of --application / --toolset.");
|
|
2096
2301
|
}
|
|
@@ -2107,13 +2312,13 @@ async function listBody3(opts) {
|
|
|
2107
2312
|
limit
|
|
2108
2313
|
});
|
|
2109
2314
|
});
|
|
2110
|
-
printOutput(schemas.map(
|
|
2315
|
+
printOutput(schemas.map(summarize4));
|
|
2111
2316
|
}
|
|
2112
2317
|
function registerToolsList(tools) {
|
|
2113
2318
|
const cmd = tools.command("list").description("List available tools, optionally filtered.").option("--application <slug>", "Filter by application slug (e.g. monday)").option("--toolset <id>", "List the tools of a server toolset (by id)").option("--limit <n>", "Cap the number of tools returned");
|
|
2114
2319
|
addUniversalOptions(cmd);
|
|
2115
2320
|
cmd.action(async (opts, command) => {
|
|
2116
|
-
await runCommand(command, opts, false, () =>
|
|
2321
|
+
await runCommand(command, opts, false, () => listBody4(opts));
|
|
2117
2322
|
});
|
|
2118
2323
|
}
|
|
2119
2324
|
|
|
@@ -2477,7 +2682,7 @@ function registerToolsetsGet(toolsets) {
|
|
|
2477
2682
|
}
|
|
2478
2683
|
|
|
2479
2684
|
// src/toolsets/list.ts
|
|
2480
|
-
async function
|
|
2685
|
+
async function listBody5() {
|
|
2481
2686
|
const toolsets = await apiErrors(async () => {
|
|
2482
2687
|
const client = buildClient();
|
|
2483
2688
|
return client.toolsets.list();
|
|
@@ -2492,7 +2697,7 @@ function registerToolsetsList(toolsets) {
|
|
|
2492
2697
|
);
|
|
2493
2698
|
addUniversalOptions(cmd);
|
|
2494
2699
|
cmd.action(async (opts, command) => {
|
|
2495
|
-
await runCommand(command, opts, false, () =>
|
|
2700
|
+
await runCommand(command, opts, false, () => listBody5());
|
|
2496
2701
|
});
|
|
2497
2702
|
}
|
|
2498
2703
|
|
|
@@ -2527,7 +2732,7 @@ async function previewDryRun(toolsetId, body) {
|
|
|
2527
2732
|
}
|
|
2528
2733
|
});
|
|
2529
2734
|
}
|
|
2530
|
-
async function
|
|
2735
|
+
async function updateBody2(toolsetId, opts) {
|
|
2531
2736
|
const id = parseToolsetId(toolsetId);
|
|
2532
2737
|
const body = buildRequestBody2(opts);
|
|
2533
2738
|
if (body.name === void 0 && body.connections === void 0 && body.workflows === void 0) {
|
|
@@ -2564,7 +2769,7 @@ function registerToolsetsUpdate(toolsets) {
|
|
|
2564
2769
|
);
|
|
2565
2770
|
addUniversalOptions(cmd, { mutating: true });
|
|
2566
2771
|
cmd.action(async (id, opts, command) => {
|
|
2567
|
-
await runCommand(command, opts, true, () =>
|
|
2772
|
+
await runCommand(command, opts, true, () => updateBody2(id, opts));
|
|
2568
2773
|
});
|
|
2569
2774
|
}
|
|
2570
2775
|
|
|
@@ -2579,7 +2784,7 @@ function registerToolsets(program) {
|
|
|
2579
2784
|
}
|
|
2580
2785
|
|
|
2581
2786
|
// src/whoami.ts
|
|
2582
|
-
function
|
|
2787
|
+
function summary5(me) {
|
|
2583
2788
|
return {
|
|
2584
2789
|
full_name: clean(me.fullName),
|
|
2585
2790
|
email: clean(me.email),
|
|
@@ -2593,7 +2798,7 @@ async function whoamiBody() {
|
|
|
2593
2798
|
const client = buildClient();
|
|
2594
2799
|
return client.auth.whoami();
|
|
2595
2800
|
});
|
|
2596
|
-
printOutput(
|
|
2801
|
+
printOutput(summary5(me));
|
|
2597
2802
|
}
|
|
2598
2803
|
function registerWhoami(program) {
|
|
2599
2804
|
const cmd = program.command("whoami").description("Report the authenticated user/company.");
|
|
@@ -2604,9 +2809,6 @@ function registerWhoami(program) {
|
|
|
2604
2809
|
});
|
|
2605
2810
|
}
|
|
2606
2811
|
|
|
2607
|
-
// src/version.ts
|
|
2608
|
-
var VERSION = true ? "0.15.0" : "0.0.0";
|
|
2609
|
-
|
|
2610
2812
|
// src/main.ts
|
|
2611
2813
|
function buildProgram() {
|
|
2612
2814
|
const program = new Command();
|
|
@@ -2623,6 +2825,114 @@ function buildProgram() {
|
|
|
2623
2825
|
return program;
|
|
2624
2826
|
}
|
|
2625
2827
|
|
|
2828
|
+
// src/update-notice.ts
|
|
2829
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
2830
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
2831
|
+
var REGISTRY_DIST_TAGS_URL = "https://registry.npmjs.org/-/package/%40engini%2Fcli/dist-tags";
|
|
2832
|
+
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
2833
|
+
var FETCH_TIMEOUT_MS = 1500;
|
|
2834
|
+
var SEMVER_RE = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
|
|
2835
|
+
function defaultCachePath() {
|
|
2836
|
+
return join3(dirname2(configPath()), "update-check.json");
|
|
2837
|
+
}
|
|
2838
|
+
function readCache(path) {
|
|
2839
|
+
try {
|
|
2840
|
+
const data = JSON.parse(readFileSync5(path, "utf8"));
|
|
2841
|
+
if (typeof data.checked_at === "number" && typeof data.channel === "string" && (data.latest_version === null || typeof data.latest_version === "string")) {
|
|
2842
|
+
return data;
|
|
2843
|
+
}
|
|
2844
|
+
} catch {
|
|
2845
|
+
}
|
|
2846
|
+
return null;
|
|
2847
|
+
}
|
|
2848
|
+
function writeCache(path, cache) {
|
|
2849
|
+
mkdirSync3(dirname2(path), { recursive: true });
|
|
2850
|
+
writeFileSync3(path, JSON.stringify(cache));
|
|
2851
|
+
}
|
|
2852
|
+
async function fetchLatest(fetchImpl, channel) {
|
|
2853
|
+
try {
|
|
2854
|
+
const res = await fetchImpl(REGISTRY_DIST_TAGS_URL, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
2855
|
+
if (!res.ok) return null;
|
|
2856
|
+
const tags = await res.json();
|
|
2857
|
+
const tag = tags[channel];
|
|
2858
|
+
return typeof tag === "string" && SEMVER_RE.test(tag) ? tag : null;
|
|
2859
|
+
} catch {
|
|
2860
|
+
return null;
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
function parseVersion(v) {
|
|
2864
|
+
const m = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(v);
|
|
2865
|
+
if (!m) return null;
|
|
2866
|
+
return {
|
|
2867
|
+
core: [Number(m[1]), Number(m[2]), Number(m[3])],
|
|
2868
|
+
prerelease: m[4] ? m[4].split(".") : null
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
function compareCore(a, b) {
|
|
2872
|
+
for (let i = 0; i < 3; i++) {
|
|
2873
|
+
if (a[i] !== b[i]) return a[i] - b[i];
|
|
2874
|
+
}
|
|
2875
|
+
return 0;
|
|
2876
|
+
}
|
|
2877
|
+
function comparePrerelease(a, b) {
|
|
2878
|
+
const len = Math.max(a.length, b.length);
|
|
2879
|
+
for (let i = 0; i < len; i++) {
|
|
2880
|
+
if (i >= a.length) return -1;
|
|
2881
|
+
if (i >= b.length) return 1;
|
|
2882
|
+
const [ai, bi] = [a[i], b[i]];
|
|
2883
|
+
const [aNum, bNum] = [/^\d+$/.test(ai), /^\d+$/.test(bi)];
|
|
2884
|
+
if (aNum && bNum) {
|
|
2885
|
+
const diff = Number(ai) - Number(bi);
|
|
2886
|
+
if (diff !== 0) return diff;
|
|
2887
|
+
} else if (aNum !== bNum) {
|
|
2888
|
+
return aNum ? -1 : 1;
|
|
2889
|
+
} else if (ai !== bi) {
|
|
2890
|
+
return ai < bi ? -1 : 1;
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
return 0;
|
|
2894
|
+
}
|
|
2895
|
+
function isNewer(current, latest) {
|
|
2896
|
+
const a = parseVersion(current);
|
|
2897
|
+
const b = parseVersion(latest);
|
|
2898
|
+
if (!a || !b) return false;
|
|
2899
|
+
const coreCmp = compareCore(a.core, b.core);
|
|
2900
|
+
if (coreCmp !== 0) return coreCmp < 0;
|
|
2901
|
+
if (a.prerelease === null) return false;
|
|
2902
|
+
if (b.prerelease === null) return true;
|
|
2903
|
+
return comparePrerelease(a.prerelease, b.prerelease) < 0;
|
|
2904
|
+
}
|
|
2905
|
+
async function maybePrintUpdateNotice(deps = {}) {
|
|
2906
|
+
const version = deps.version ?? VERSION;
|
|
2907
|
+
const now = deps.now ?? (() => Date.now());
|
|
2908
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
2909
|
+
const cachePath = deps.cachePath ?? defaultCachePath();
|
|
2910
|
+
if (version === "0.0.0") return;
|
|
2911
|
+
if (!(process.stdout.isTTY && process.stderr.isTTY)) return;
|
|
2912
|
+
const { forceJson, quiet } = outputFlags();
|
|
2913
|
+
if (forceJson || quiet) return;
|
|
2914
|
+
if (process.env.CI) return;
|
|
2915
|
+
if (process.env.ENGINI_NO_UPDATE_CHECK) return;
|
|
2916
|
+
if (process.env.NO_UPDATE_NOTIFIER) return;
|
|
2917
|
+
try {
|
|
2918
|
+
const channel = version.includes("-") ? "beta" : "latest";
|
|
2919
|
+
const cached = readCache(cachePath);
|
|
2920
|
+
let latestVersion;
|
|
2921
|
+
if (cached && cached.channel === channel && now() - cached.checked_at < CACHE_TTL_MS) {
|
|
2922
|
+
latestVersion = cached.latest_version;
|
|
2923
|
+
} else {
|
|
2924
|
+
latestVersion = await fetchLatest(fetchImpl, channel);
|
|
2925
|
+
writeCache(cachePath, { checked_at: now(), channel, latest_version: latestVersion });
|
|
2926
|
+
}
|
|
2927
|
+
if (latestVersion !== null && isNewer(version, latestVersion)) {
|
|
2928
|
+
console.error(
|
|
2929
|
+
`Update available: ${version} -> ${latestVersion} Run: npm install -g @engini/cli@${channel}`
|
|
2930
|
+
);
|
|
2931
|
+
}
|
|
2932
|
+
} catch {
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2626
2936
|
// src/index.ts
|
|
2627
2937
|
function applyExitOverride(command) {
|
|
2628
2938
|
command.exitOverride();
|
|
@@ -2631,24 +2941,41 @@ function applyExitOverride(command) {
|
|
|
2631
2941
|
async function main(argv = process.argv.slice(2)) {
|
|
2632
2942
|
const program = buildProgram();
|
|
2633
2943
|
applyExitOverride(program);
|
|
2944
|
+
if (argv.length === 0) {
|
|
2945
|
+
program.outputHelp();
|
|
2946
|
+
await maybePrintUpdateNotice();
|
|
2947
|
+
process.exit(0);
|
|
2948
|
+
}
|
|
2634
2949
|
try {
|
|
2635
|
-
if (argv.length === 0) {
|
|
2636
|
-
program.outputHelp();
|
|
2637
|
-
process.exit(0);
|
|
2638
|
-
}
|
|
2639
2950
|
await program.parseAsync(argv, { from: "user" });
|
|
2951
|
+
await maybePrintUpdateNotice();
|
|
2640
2952
|
} catch (err) {
|
|
2641
2953
|
if (err instanceof CliError) {
|
|
2642
2954
|
process.exit(err.code);
|
|
2643
2955
|
}
|
|
2644
2956
|
if (err && typeof err === "object" && "exitCode" in err) {
|
|
2645
|
-
|
|
2957
|
+
const code = mapCommanderExitCode(err.exitCode);
|
|
2958
|
+
if (code === 0 /* OK */) {
|
|
2959
|
+
await maybePrintUpdateNotice();
|
|
2960
|
+
}
|
|
2961
|
+
process.exit(code);
|
|
2646
2962
|
}
|
|
2647
2963
|
console.error(err instanceof Error ? err.message : String(err));
|
|
2648
2964
|
process.exit(1);
|
|
2649
2965
|
}
|
|
2650
2966
|
}
|
|
2651
|
-
|
|
2967
|
+
function isMainModule(metaUrl, argv1) {
|
|
2968
|
+
if (argv1 === void 0) return false;
|
|
2969
|
+
try {
|
|
2970
|
+
return metaUrl === pathToFileURL(realpathSync(argv1)).href;
|
|
2971
|
+
} catch {
|
|
2972
|
+
return false;
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
if (isMainModule(import.meta.url, process.argv[1])) {
|
|
2976
|
+
main();
|
|
2977
|
+
}
|
|
2652
2978
|
export {
|
|
2979
|
+
isMainModule,
|
|
2653
2980
|
main
|
|
2654
2981
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@engini/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Engini CLI — machine-first command line over the Engini Public API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,12 +19,14 @@
|
|
|
19
19
|
"directory": "ts/packages/cli"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
+
"pretypecheck": "pnpm --filter @engini/sdk run generate-version",
|
|
23
|
+
"pretest": "pnpm --filter @engini/sdk run generate-version",
|
|
22
24
|
"typecheck": "tsc --noEmit",
|
|
23
25
|
"build": "tsup",
|
|
24
26
|
"test": "vitest run"
|
|
25
27
|
},
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@engini/sdk": "^0.
|
|
29
|
+
"@engini/sdk": "^0.17.0",
|
|
28
30
|
"commander": "^12.1.0",
|
|
29
31
|
"smol-toml": "^1.3.0"
|
|
30
32
|
},
|