@engini/cli 0.26.0 → 0.27.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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +35 -38
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -100,7 +100,7 @@ engini connect monday --auth 0 --field ApiKey=<key> # creates → checks → r
100
100
  engini connect outlook --json # → {need:"oauth", sign_in_url, state, state_expires_in_seconds, resume:"engini connect outlook --auth 0 --oauth-state <state>"}
101
101
  # show sign_in_url to the user - they must sign in within state_expires_in_seconds of
102
102
  # minting; past that the server has purged the state and the resume below fails fast, not hangs:
103
- engini connect outlook --auth 0 --oauth-state <state> # polls token → creates → checks → refreshes
103
+ engini connect outlook --auth 0 --oauth-state <state> # polls sign-in status → creates → checks → refreshes
104
104
 
105
105
  # re-authenticate an EXISTING OAuth2 connection in place — same sign-in flow,
106
106
  # but --oauth-state alone (no --field/--name/--metadata) is a valid edit and
package/dist/cli.js CHANGED
@@ -450,7 +450,7 @@ function saveConfig(config, path = configPath()) {
450
450
  }
451
451
 
452
452
  // src/version.ts
453
- var VERSION = true ? "0.26.0" : "0.0.0";
453
+ var VERSION = true ? "0.27.0" : "0.0.0";
454
454
 
455
455
  // src/http.ts
456
456
  var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
@@ -642,8 +642,6 @@ async function safeTrigger(action, what) {
642
642
  throw err;
643
643
  }
644
644
  }
645
- var OAUTH_DONE = /* @__PURE__ */ new Set(["completed", "complete", "success", "succeeded"]);
646
- var OAUTH_FAILED = /* @__PURE__ */ new Set(["failed", "error", "cancelled", "canceled", "denied"]);
647
645
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
648
646
  var OAUTH_STATE_TTL_SECONDS = 300;
649
647
  function collect(value, previous = []) {
@@ -695,24 +693,31 @@ async function pollRefresh(client, connectionId, opts) {
695
693
  }
696
694
  return "completed";
697
695
  }
698
- async function pollAccessToken(client, state, opts) {
696
+ async function pollSignInStatus(client, state, opts) {
699
697
  progress(
700
698
  `Waiting for you to finish signing in (up to ${Math.round(opts.timeout)}s, Ctrl-C to abort)\u2026`
701
699
  );
702
700
  const deadline = Date.now() + opts.timeout * 1e3;
703
701
  for (; ; ) {
704
- const resp = await client.connections.getAccessToken(state);
705
- if (resp == null) {
706
- fail(
707
- 4 /* NOT_FOUND */,
708
- `OAuth sign-in state not found - it may have expired (states are purged ${OAUTH_STATE_TTL_SECONDS} seconds after they're minted) or never existed.`,
709
- "Start over: `engini connect <app>` mints a fresh sign_in_url + state."
710
- );
711
- }
712
- const status = (resp.status ?? "").toLowerCase();
713
- if (OAUTH_DONE.has(status)) return resp;
714
- if (OAUTH_FAILED.has(status)) {
715
- fail(1 /* GENERIC */, clean(resp.error_message) ?? "OAuth sign-in failed.");
702
+ const resp = await client.connections.getSignInStatus(state);
703
+ switch (resp.status) {
704
+ case "signed_in":
705
+ return resp;
706
+ case "expired":
707
+ fail(
708
+ 4 /* NOT_FOUND */,
709
+ `OAuth sign-in state not found - it may have expired (states are purged ${OAUTH_STATE_TTL_SECONDS} seconds after they're minted) or never existed.`,
710
+ "Start over: `engini connect <app>` mints a fresh sign_in_url + state."
711
+ );
712
+ break;
713
+ case "failed":
714
+ case "cancelled":
715
+ fail(
716
+ 1 /* GENERIC */,
717
+ `OAuth sign-in ${resp.status}.`,
718
+ "Start over: `engini connect <app>` mints a fresh sign_in_url + state."
719
+ );
720
+ break;
716
721
  }
717
722
  if (Date.now() >= deadline) {
718
723
  fail(124 /* TIMEOUT */, "OAuth sign-in did not complete in time.");
@@ -720,14 +725,6 @@ async function pollAccessToken(client, state, opts) {
720
725
  await sleep(opts.interval * 1e3);
721
726
  }
722
727
  }
723
- function oauthFields(token) {
724
- const fields = {};
725
- for (const [key, value] of Object.entries(token.connectionData ?? {})) {
726
- if (value === null || value === void 0 || value === "") continue;
727
- fields[key] = typeof value === "string" ? value : JSON.stringify(value);
728
- }
729
- return fields;
730
- }
731
728
 
732
729
  // src/connect.ts
733
730
  var PLACEHOLDER = "<value>";
@@ -887,7 +884,7 @@ async function chooseAuth(methods, auth, application, provider) {
887
884
  resume: `engini connect ${application} --auth <id>${providerResumeFlag(provider)}`
888
885
  });
889
886
  }
890
- async function collectFields(method, application, provided, oauthState, fieldOptions, provider) {
887
+ async function collectFields(method, application, provided, oauthState, fieldOptions, provider, derived) {
891
888
  async function readSecretField(label) {
892
889
  const { value, truncated } = await promptHidden(label);
893
890
  if (truncated) {
@@ -922,12 +919,14 @@ async function collectFields(method, application, provided, oauthState, fieldOpt
922
919
  );
923
920
  }
924
921
  }
922
+ for (const k of derived ?? []) delete provided[k];
923
+ const isSatisfied = (name) => name in provided || (derived?.has(name) ?? false);
925
924
  const required = schema.filter((f) => f.isRequired);
926
- const missing = required.filter((f) => !(f.fieldName in provided));
925
+ const missing = required.filter((f) => !isSatisfied(f.fieldName));
927
926
  if (missing.length === 0) return provided;
928
927
  if (isInteractive()) {
929
928
  for (const f of schema) {
930
- if (f.fieldName in provided) continue;
929
+ if (isSatisfied(f.fieldName)) continue;
931
930
  const label = fieldLabel(f);
932
931
  const options = fieldOptions?.[f.fieldName];
933
932
  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) ?? "");
@@ -1006,10 +1005,9 @@ async function resolveObjects(objs, connectionId, application) {
1006
1005
  async function oauthFieldsFor(client, application, method, oauthState, field, timing, provider) {
1007
1006
  const cliFields = parseFields(field);
1008
1007
  if (oauthState) {
1009
- const token = await pollAccessToken(client, oauthState, timing);
1010
- const merged = { ...cliFields, ...oauthFields(token) };
1008
+ const status = await pollSignInStatus(client, oauthState, timing);
1011
1009
  return {
1012
- fields: await collectFields(method, application, merged, oauthState, token.fieldOptions, provider),
1010
+ fields: await collectFields(method, application, cliFields, oauthState, status.fieldOptions, provider, new Set(status.derivedFields)),
1013
1011
  state: oauthState
1014
1012
  };
1015
1013
  }
@@ -1020,10 +1018,9 @@ async function oauthFieldsFor(client, application, method, oauthState, field, ti
1020
1018
  if (isTty() && timing.wait) {
1021
1019
  openBrowser(resp.signInUrl);
1022
1020
  progress(`Opened ${resp.signInUrl} \u2014 complete the sign-in in your browser.`);
1023
- const token = await pollAccessToken(client, resp.state, timing);
1024
- const merged = { ...cliFields, ...oauthFields(token) };
1021
+ const status = await pollSignInStatus(client, resp.state, timing);
1025
1022
  return {
1026
- fields: await collectFields(method, application, merged, resp.state, token.fieldOptions, provider),
1023
+ fields: await collectFields(method, application, cliFields, resp.state, status.fieldOptions, provider, new Set(status.derivedFields)),
1027
1024
  state: resp.state
1028
1025
  };
1029
1026
  }
@@ -1096,7 +1093,7 @@ function methodSummary(m) {
1096
1093
  // to have discovered them from. Each field's `options` therefore comes back `null` in
1097
1094
  // this `need: "auth"` payload specifically because it's not knowable yet, not because
1098
1095
  // the field has none - that's a distinct case (`{}`, once a sign-in has run - see
1099
- // `fieldSummary` and the `AccessTokenResponse.fieldOptions` doc in @engini/sdk). Worth
1096
+ // `fieldSummary` and the `SignInStatusResponse.fieldOptions` doc in @engini/sdk). Worth
1100
1097
  // calling out explicitly wherever step 5 documents this payload, since the two look the
1101
1098
  // same on the wire (both fall out here as `options: null`) but mean different things.
1102
1099
  fields: m.connectionFields.map((f) => fieldSummary(f))
@@ -1829,12 +1826,12 @@ async function oauthCompleteBody(application, opts) {
1829
1826
  }
1830
1827
  const conn = await apiErrors(async () => {
1831
1828
  const client = buildClient();
1832
- const token = await pollAccessToken(client, opts.state, {
1829
+ await pollSignInStatus(client, opts.state, {
1833
1830
  timeout: Number(opts.timeout ?? 300),
1834
1831
  interval: Number(opts.pollInterval ?? 2)
1835
1832
  });
1836
1833
  progress(`Creating connection '${name}'\u2026`);
1837
- return client.connections.create(application, name, auth, oauthFields(token), {
1834
+ return client.connections.create(application, name, auth, {}, {
1838
1835
  oauthState: opts.state
1839
1836
  });
1840
1837
  });
@@ -2121,7 +2118,7 @@ function registerConnections(program) {
2121
2118
  // src/help.ts
2122
2119
  import { Help } from "commander";
2123
2120
  var REPO_URL = "https://github.com/engini/engini-sdk";
2124
- var KEYS_URL = "https://app.engini.io/users";
2121
+ var KEYS_URL = "https://app.engini.io/api-keys";
2125
2122
  var EXIT_LABELS = {
2126
2123
  [0 /* OK */]: "success",
2127
2124
  [1 /* GENERIC */]: "general error",
@@ -2431,7 +2428,7 @@ function installHelp(program) {
2431
2428
 
2432
2429
  // src/login.ts
2433
2430
  function keysUrl(config) {
2434
- return `${config.identity_url.replace(/\/+$/, "")}/users`;
2431
+ return `${config.identity_url.replace(/\/+$/, "")}/api-keys`;
2435
2432
  }
2436
2433
  var MAX_KEY_ATTEMPTS = 3;
2437
2434
  function charCount(key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/cli",
3
- "version": "0.26.0",
3
+ "version": "0.27.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.26.0",
29
+ "@engini/sdk": "^0.27.0",
30
30
  "commander": "^12.1.0",
31
31
  "smol-toml": "^1.3.0"
32
32
  },