@engini/cli 0.23.0 → 0.24.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 +57 -9
  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.23.0" : "0.0.0";
445
+ var VERSION = true ? "0.24.0" : "0.0.0";
446
446
 
447
447
  // src/http.ts
448
448
  var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
@@ -809,7 +809,7 @@ async function chooseAuth(methods, auth, application) {
809
809
  resume: `engini connect ${application} --auth <id>`
810
810
  });
811
811
  }
812
- async function collectFields(method, application, provided, oauthState) {
812
+ async function collectFields(method, application, provided, oauthState, fieldOptions) {
813
813
  async function readSecretField(label) {
814
814
  const { value, truncated } = await promptHidden(label);
815
815
  if (truncated) {
@@ -822,9 +822,25 @@ async function collectFields(method, application, provided, oauthState) {
822
822
  return value;
823
823
  }
824
824
  const schema = method.connectionFields.filter((f) => !f.isHidden);
825
+ const resumeHint = oauthState ? `Resume with: engini connect ${application} --auth ${method.authenticationId} --oauth-state ${oauthState}` : void 0;
825
826
  for (const [k, v] of Object.entries(provided)) {
826
827
  if (v === PLACEHOLDER) delete provided[k];
827
828
  }
829
+ for (const f of schema) {
830
+ const opts = fieldOptions?.[f.fieldName];
831
+ const val = provided[f.fieldName];
832
+ if (!opts || Object.keys(opts).length === 0 || val === void 0) continue;
833
+ if (!Object.hasOwn(opts, val)) {
834
+ fail(
835
+ 2 /* USAGE */,
836
+ `'${val}' is not a legal ${f.fieldName} for this org. Legal values: ${Object.keys(opts).join(", ")}`,
837
+ // A TTY caller who just completed the inline browser sign-in and then supplied this bad
838
+ // value must recover the same way a mistyped picker digit does (below) - not with a
839
+ // hard fail that has no resume hint and forces a full re-auth.
840
+ resumeHint
841
+ );
842
+ }
843
+ }
828
844
  const required = schema.filter((f) => f.isRequired);
829
845
  const missing = required.filter((f) => !(f.fieldName in provided));
830
846
  if (missing.length === 0) return provided;
@@ -832,7 +848,8 @@ async function collectFields(method, application, provided, oauthState) {
832
848
  for (const f of schema) {
833
849
  if (f.fieldName in provided) continue;
834
850
  const label = fieldLabel(f);
835
- const value = f.isPassword ? await readSecretField(label) : await promptText(label, clean(f.defaultValue) ?? "");
851
+ const options = fieldOptions?.[f.fieldName];
852
+ const value = options && Object.keys(options).length > 0 ? await promptFieldOption(label, options, f.isRequired, resumeHint) : f.isPassword ? await readSecretField(label) : await promptText(label, clean(f.defaultValue) ?? "");
836
853
  if (value) provided[f.fieldName] = value;
837
854
  }
838
855
  return provided;
@@ -848,10 +865,27 @@ async function collectFields(method, application, provided, oauthState) {
848
865
  need: "fields",
849
866
  application,
850
867
  authentication_id: method.authenticationId,
851
- fields: schema.map(fieldSummary),
868
+ fields: schema.map((f) => fieldSummary(f, fieldOptions?.[f.fieldName])),
852
869
  resume: resumeParts.join(" ")
853
870
  });
854
871
  }
872
+ async function promptFieldOption(label, options, isRequired, resumeHint) {
873
+ const entries = Object.entries(options);
874
+ entries.forEach(([value, optionLabel], i) => {
875
+ console.error(` ${i + 1}: ${optionLabel} (${value})`);
876
+ });
877
+ const range = `1-${entries.length}`;
878
+ const answer = await promptText(
879
+ isRequired ? `Choose ${label} (${range})` : `Choose ${label} (${range}, blank to skip)`
880
+ );
881
+ if (answer.trim() === "" && !isRequired) return "";
882
+ const index = Number(answer);
883
+ const chosen = entries[index - 1];
884
+ if (!chosen) {
885
+ fail(2 /* USAGE */, `Choose a number between 1 and ${entries.length} for ${label}.`, resumeHint);
886
+ }
887
+ return chosen[0];
888
+ }
855
889
  async function resolveName(name, application) {
856
890
  if (name) return name;
857
891
  const fallback = `${application} connection`;
@@ -892,7 +926,10 @@ async function oauthFieldsFor(client, application, method, oauthState, field, ti
892
926
  if (oauthState) {
893
927
  const token = await pollAccessToken(client, oauthState, timing);
894
928
  const merged = { ...cliFields, ...oauthFields(token) };
895
- return { fields: await collectFields(method, application, merged, oauthState), state: oauthState };
929
+ return {
930
+ fields: await collectFields(method, application, merged, oauthState, token.fieldOptions),
931
+ state: oauthState
932
+ };
896
933
  }
897
934
  const resp = await client.connections.getSignInUrl(application, method.authenticationId, {
898
935
  fields: field && field.length > 0 ? cliFields : void 0
@@ -902,7 +939,10 @@ async function oauthFieldsFor(client, application, method, oauthState, field, ti
902
939
  progress(`Opened ${resp.signInUrl} \u2014 complete the sign-in in your browser.`);
903
940
  const token = await pollAccessToken(client, resp.state, timing);
904
941
  const merged = { ...cliFields, ...oauthFields(token) };
905
- return { fields: await collectFields(method, application, merged, resp.state), state: resp.state };
942
+ return {
943
+ fields: await collectFields(method, application, merged, resp.state, token.fieldOptions),
944
+ state: resp.state
945
+ };
906
946
  }
907
947
  const secretFields = new Set(
908
948
  method.connectionFields.filter(isSecretField).map((f) => f.fieldName)
@@ -963,20 +1003,28 @@ function methodSummary(m) {
963
1003
  is_default: Boolean(m.isDefault),
964
1004
  help_url: methodHelpUrl(m),
965
1005
  requires_oauth: m.requiresOAuthSignIn,
966
- fields: m.connectionFields.map(fieldSummary)
1006
+ // No fieldOptions here - this listing runs before any sign-in, so there is no org yet
1007
+ // to have discovered them from. Each field's `options` therefore comes back `null` in
1008
+ // this `need: "auth"` payload specifically because it's not knowable yet, not because
1009
+ // the field has none - that's a distinct case (`{}`, once a sign-in has run - see
1010
+ // `fieldSummary` and the `AccessTokenResponse.fieldOptions` doc in @engini/sdk). Worth
1011
+ // calling out explicitly wherever step 5 documents this payload, since the two look the
1012
+ // same on the wire (both fall out here as `options: null`) but mean different things.
1013
+ fields: m.connectionFields.map((f) => fieldSummary(f))
967
1014
  };
968
1015
  }
969
1016
  function methodHelpUrl(m) {
970
1017
  return typeof m.helpUrl === "string" && m.helpUrl.trim() !== "" ? m.helpUrl : null;
971
1018
  }
972
- function fieldSummary(f) {
1019
+ function fieldSummary(f, options) {
973
1020
  return {
974
1021
  field_name: f.fieldName,
975
1022
  is_required: f.isRequired,
976
1023
  is_password: f.isPassword,
977
1024
  description: clean(f.fieldDescription),
978
1025
  default: clean(f.defaultValue),
979
- list_values: clean(f.listValues)
1026
+ list_values: clean(f.listValues),
1027
+ options: options && Object.keys(options).length > 0 ? options : null
980
1028
  };
981
1029
  }
982
1030
  function objectSummary(o) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/cli",
3
- "version": "0.23.0",
3
+ "version": "0.24.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.23.0",
29
+ "@engini/sdk": "^0.24.0",
30
30
  "commander": "^12.1.0",
31
31
  "smol-toml": "^1.3.0"
32
32
  },