@engini/cli 0.20.0 → 0.21.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.
Files changed (2) hide show
  1. package/dist/cli.js +44 -11
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -442,7 +442,7 @@ function saveConfig(config, path = configPath()) {
442
442
  }
443
443
 
444
444
  // src/version.ts
445
- var VERSION = true ? "0.20.0" : "0.0.0";
445
+ var VERSION = true ? "0.21.0" : "0.0.0";
446
446
 
447
447
  // src/http.ts
448
448
  var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
@@ -711,13 +711,15 @@ async function connectBody(application, opts) {
711
711
  return;
712
712
  }
713
713
  const name = await resolveName(opts.name, application);
714
- const fields = method.requiresOAuthSignIn ? await oauthFieldsFor(client, application, method, opts.oauthState, timing) : await collectFields(method, application, opts.field);
714
+ const credentials = method.requiresOAuthSignIn ? await oauthFieldsFor(client, application, method, opts.oauthState, timing) : { fields: await collectFields(method, application, opts.field) };
715
715
  progress(`Creating connection '${name}'\u2026`);
716
716
  const created = await client.connections.create(
717
717
  application,
718
718
  name,
719
719
  method.authenticationId,
720
- fields
720
+ credentials.fields,
721
+ // Present only for OAuth methods; a non-OAuth create has no sign-in to point at.
722
+ credentials.state ? { oauthState: credentials.state } : {}
721
723
  );
722
724
  const connectionId = created.connectionId;
723
725
  progress(`Checking connection ${connectionId}\u2026`);
@@ -771,9 +773,22 @@ async function chooseAuth(methods, auth, application) {
771
773
  if (methods.length === 1) return methods[0];
772
774
  if (isInteractive()) {
773
775
  for (const m of methods) {
774
- console.error(` ${m.authenticationId}: ${m.authenticationName} (${m.authenticationType})`);
776
+ const marker = m.isDefault ? " [default]" : "";
777
+ console.error(
778
+ ` ${m.authenticationId}: ${m.authenticationName} (${m.authenticationType})${marker}`
779
+ );
780
+ const description = clean(m.description);
781
+ if (description) console.error(` ${description}`);
782
+ const helpUrl = methodHelpUrl(m);
783
+ if (helpUrl) console.error(` ${helpUrl}`);
775
784
  }
776
- const id = Number(await promptText("Choose an authentication method id"));
785
+ const preferred = methods.find((m) => m.isDefault);
786
+ const answer = await promptText(
787
+ "Choose an authentication method id",
788
+ preferred ? String(preferred.authenticationId) : ""
789
+ );
790
+ if (answer.trim() === "") fail(2 /* USAGE */, "Choose an authentication method id.");
791
+ const id = Number(answer);
777
792
  const chosen = byId.get(id);
778
793
  if (!chosen) fail(2 /* USAGE */, `No authentication method with id ${id}.`);
779
794
  return chosen;
@@ -858,14 +873,14 @@ async function resolveObjects(objs, connectionId, application) {
858
873
  async function oauthFieldsFor(client, application, method, oauthState, timing) {
859
874
  if (oauthState) {
860
875
  const token = await pollAccessToken(client, oauthState, timing);
861
- return oauthFields(token);
876
+ return { fields: oauthFields(token), state: oauthState };
862
877
  }
863
878
  const resp = await client.connections.getSignInUrl(application, method.authenticationId);
864
879
  if (isTty() && timing.wait) {
865
880
  openBrowser(resp.signInUrl);
866
881
  progress(`Opened ${resp.signInUrl} \u2014 complete the sign-in in your browser.`);
867
882
  const token = await pollAccessToken(client, resp.state, timing);
868
- return oauthFields(token);
883
+ return { fields: oauthFields(token), state: resp.state };
869
884
  }
870
885
  return need({
871
886
  need: "oauth",
@@ -886,10 +901,21 @@ function methodSummary(m) {
886
901
  authentication_id: m.authenticationId,
887
902
  authentication_type: m.authenticationType,
888
903
  authentication_name: m.authenticationName,
904
+ description: clean(m.description),
905
+ // Boolean(), not the raw value: the generated type declares isDefault non-optional and
906
+ // hey-api does no runtime validation, so against a server that omits it this is undefined -
907
+ // and JSON.stringify drops undefined keys entirely, leaving an agent parsing need:auth with
908
+ // description: null, help_url: null and no is_default key at all. All three normalise now.
909
+ is_default: Boolean(m.isDefault),
910
+ help_url: methodHelpUrl(m),
889
911
  requires_oauth: m.requiresOAuthSignIn,
890
912
  fields: m.connectionFields.map(fieldSummary)
891
913
  };
892
914
  }
915
+ function methodHelpUrl(m) {
916
+ const value = m.helpUrl;
917
+ return typeof value === "string" && value.trim() !== "" ? value : null;
918
+ }
893
919
  function fieldSummary(f) {
894
920
  return {
895
921
  field_name: f.fieldName,
@@ -1207,7 +1233,9 @@ async function oauthCompleteBody(application, opts) {
1207
1233
  interval: Number(opts.pollInterval ?? 2)
1208
1234
  });
1209
1235
  progress(`Creating connection '${name}'\u2026`);
1210
- return client.connections.create(application, name, auth, oauthFields(token));
1236
+ return client.connections.create(application, name, auth, oauthFields(token), {
1237
+ oauthState: opts.state
1238
+ });
1211
1239
  });
1212
1240
  printOutput(summary2(conn));
1213
1241
  }
@@ -1414,10 +1442,11 @@ async function updateBody(idRaw, opts) {
1414
1442
  if (opts.description !== void 0) patch.description = opts.description;
1415
1443
  if (opts.field !== void 0) patch.fields = parseFields(opts.field);
1416
1444
  if (opts.metadata !== void 0) patch.metadata = parseFields(opts.metadata);
1445
+ if (opts.oauthState !== void 0) patch.oauthState = opts.oauthState;
1417
1446
  if (Object.keys(patch).length === 0) {
1418
1447
  fail(
1419
1448
  2 /* USAGE */,
1420
- "Nothing to update. Supply at least one of --name, --description, --field, --metadata."
1449
+ "Nothing to update. Supply at least one of --name, --description, --field, --metadata, --oauth-state."
1421
1450
  );
1422
1451
  }
1423
1452
  if (dryRun()) {
@@ -1430,6 +1459,7 @@ async function updateBody(idRaw, opts) {
1430
1459
  Object.entries(patch.fields).map(([k, v]) => [k, maskSecret(v)])
1431
1460
  ),
1432
1461
  metadata: patch.metadata ?? null,
1462
+ oauth_state: patch.oauthState ?? null,
1433
1463
  // Loud on purpose: this is the field-loss trap.
1434
1464
  replaces_entire_fields_map: patch.fields !== void 0,
1435
1465
  replaces_entire_metadata_map: patch.metadata !== void 0
@@ -1444,10 +1474,13 @@ async function updateBody(idRaw, opts) {
1444
1474
  printOutput(summary4(conn));
1445
1475
  }
1446
1476
  function registerConnectionsUpdate(connections) {
1447
- 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);
1477
+ 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).option(
1478
+ "--oauth-state <state>",
1479
+ "Sign-in state proving a credential change on an OAuth2 connection"
1480
+ );
1448
1481
  cmd.addHelpText(
1449
1482
  "after",
1450
- "\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)."
1483
+ "\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 engini connections update 481 --field RefreshToken=rt-new --oauth-state st-1\n engini connections update 481 --oauth-state st-1 # re-authenticate in place,\n # no --field needed\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).\n\nOn an OAuth2 connection, changing ApiKey, RefreshToken or ExternalOrgId needs\n--oauth-state from a fresh `engini connect` sign-in: the server derives those\nfrom its own record and will not take them from a caller. Renames and edits to\nBaseUrl or any Key{N} setting need no state."
1451
1484
  );
1452
1485
  addUniversalOptions(cmd, { mutating: true });
1453
1486
  cmd.action(async (idRaw, opts, command) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/cli",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Engini CLI — machine-first command line over the Engini Public API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "test": "vitest run"
27
27
  },
28
28
  "dependencies": {
29
- "@engini/sdk": "^0.20.0",
29
+ "@engini/sdk": "^0.21.0",
30
30
  "commander": "^12.1.0",
31
31
  "smol-toml": "^1.3.0"
32
32
  },