@arbol-ai/cli 3.73.0 → 3.73.1

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 +16 -5
  2. package/dist/index.js +111 -28
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -65,8 +65,8 @@ and discovers how to sign in from it, as an MCP client does:
65
65
 
66
66
  Login then opens the system browser (Authorization Code with S256 PKCE and the loopback callback,
67
67
  `http://127.0.0.1:43817/callback`). When you belong to several organizations, the sign-in page asks
68
- which one after you sign in. `arbol auth switch` lists the organizations you belong to: one you used
69
- before switches at once, any other signs in again through single sign-on, which asks for no password.
68
+ which one after you sign in. `arbol auth switch` lists the organizations you belong to. It switches
69
+ at once when a saved session is still usable. For other sessions it signs in again through single sign-on.
70
70
  `arbol auth switch <name|org_…>` does the same without asking, for scripts. The session is for the
71
71
  organization the verified ID token names.
72
72
 
@@ -116,6 +116,17 @@ ARBOL_API_KEY="$(cat /secure/path/arbol-key)" arbol visoft connections list
116
116
  arbol sura appointments lookup --api-key-stdin < /secure/path/arbol-key
117
117
  ```
118
118
 
119
+ An Auth0 application configured for `client_credentials` and `client_secret_post` can also run
120
+ commands. Set `ARBOL_M2M_CLIENT_ID` and `ARBOL_M2M_CLIENT_SECRET` through your runtime's secret
121
+ store and specify `--organization` with the exact organization ID. The application's grant must
122
+ include that organization and the API scopes the operation requires. Each command requests a fresh
123
+ token for that organization and the selected API. `auth status` reports local configuration.
124
+
125
+ ```sh
126
+ arbol auth status --organization org_example --json
127
+ arbol account organization get --organization org_example
128
+ ```
129
+
119
130
  Commands are `arbol <service> <resource> <verb> [id]`, the operation's public name. A service is one
120
131
  word: its published id without hyphens, so `salud-total.affiliations.lookup` is
121
132
  `arbol saludtotal affiliations lookup` (and `policia-colombia` is `policiacolombia`). The published id
@@ -132,9 +143,9 @@ response's data is printed as JSON; a failure prints its code and the request id
132
143
  that got no answer, that its outcome is unknown, and exits nonzero. Nothing is retried, even after 401
133
144
  or 403; reconcile an uncertain write before repeating it.
134
145
 
135
- `ARBOL_API_URL` selects a trusted nonproduction deployment for new profiles and for an API key given
136
- to a command; it must be an HTTPS origin. Everything else about signing in is discovered from it, and a
137
- profile keeps the API it was created for.
146
+ `ARBOL_API_URL` selects a trusted HTTPS origin for new profiles and for machine credentials.
147
+ For a machine application, use a deployment whose advertised issuer is authorized to receive its
148
+ secret. A saved profile keeps the API it was created for.
138
149
 
139
150
  ## Your organization's own servers
140
151
 
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ import Ajv2020 from "ajv/dist/2020.js";
12
12
 
13
13
  // src/config.ts
14
14
  var DEFAULT_API = "https://api.getarbol.com";
15
+ var ORGANIZATION_ID = /^org_[A-Za-z0-9]+$/;
15
16
  function origin(raw) {
16
17
  const value = new URL(raw);
17
18
  if (value.protocol !== "https:" || value.username || value.password || value.pathname !== "/" || value.search || value.hash) {
@@ -505,6 +506,9 @@ function sealedStore(directory, keys = systemKeyStore(), root = dirname(director
505
506
  }
506
507
 
507
508
  // src/credentials.ts
509
+ function sessionRequiresLogin(session) {
510
+ return Boolean(session.refreshing || !session.refreshToken && session.expiresAt <= Date.now());
511
+ }
508
512
  function isKnownLogin(value) {
509
513
  if (!value || typeof value !== "object") {
510
514
  return false;
@@ -569,7 +573,10 @@ class Credentials {
569
573
  return known;
570
574
  }
571
575
  async use(login) {
572
- await this.session(login);
576
+ const session = await this.session(login);
577
+ if (sessionRequiresLogin(session)) {
578
+ throw new Error("Saved session requires sign-in");
579
+ }
573
580
  await this.#write("active.json", {
574
581
  key: login.key,
575
582
  subject: login.subject,
@@ -709,11 +716,8 @@ function loopback(value) {
709
716
  return false;
710
717
  }
711
718
  }
712
- async function discover(api, env = process.env, fetcher = fetch) {
713
- const [resource, client] = await Promise.all([
714
- document(`${api}${RESOURCE_METADATA}`, fetcher),
715
- document(`${api}${CLIENT_METADATA}`, fetcher)
716
- ]);
719
+ async function discoverResource(api, fetcher = fetch) {
720
+ const resource = await document(`${api}${RESOURCE_METADATA}`, fetcher);
717
721
  if (resource.resource !== api) {
718
722
  throw new Error(`${api}${RESOURCE_METADATA} describes another resource`);
719
723
  }
@@ -721,6 +725,13 @@ async function discover(api, env = process.env, fetcher = fetch) {
721
725
  if (!httpsUrl(issuer)) {
722
726
  throw new Error(`${api} names no HTTPS authorization server`);
723
727
  }
728
+ return { issuer, audience: api };
729
+ }
730
+ async function discover(api, env = process.env, fetcher = fetch) {
731
+ const [resource, client] = await Promise.all([
732
+ discoverResource(api, fetcher),
733
+ document(`${api}${CLIENT_METADATA}`, fetcher)
734
+ ]);
724
735
  const clientId = client.client_id;
725
736
  if (typeof clientId !== "string" || !(/^[\w.-]{1,128}$/.test(clientId) || httpsUrl(clientId))) {
726
737
  throw new Error(`${api}${CLIENT_METADATA} names no client`);
@@ -736,7 +747,7 @@ async function discover(api, env = process.env, fetcher = fetch) {
736
747
  if (typeof scopes !== "string" || !scopes.split(" ").includes("openid")) {
737
748
  throw new Error("The scopes to ask for must include openid");
738
749
  }
739
- return { issuer, clientId, audience: api, scopes, api, redirectUri };
750
+ return { ...resource, clientId, scopes, api, redirectUri };
740
751
  }
741
752
 
742
753
  // src/generated/commands.ts
@@ -266863,13 +266874,40 @@ import { once as once2 } from "node:events";
266863
266874
  import { createServer } from "node:http";
266864
266875
  import { win32 as win322 } from "node:path";
266865
266876
  import * as oauth from "oauth4webapi";
266866
- async function authority(config) {
266867
- const issuer = new URL(config.issuer);
266877
+ async function authority(address) {
266878
+ const issuer = new URL(address);
266868
266879
  return oauth.processDiscoveryResponse(issuer, await oauth.discoveryRequest(issuer, { signal: AbortSignal.timeout(15000) }));
266869
266880
  }
266870
266881
  function client(config) {
266871
266882
  return { client_id: config.clientId, id_token_signed_response_alg: "RS256" };
266872
266883
  }
266884
+ async function machineAccessToken(resource, credentials) {
266885
+ const server = await authority(resource.issuer);
266886
+ if (!server.token_endpoint || new URL(server.token_endpoint).origin !== new URL(resource.issuer).origin) {
266887
+ throw new Error("The machine token endpoint must belong to the configured issuer");
266888
+ }
266889
+ const machine = { client_id: credentials.clientId };
266890
+ const response = await oauth.clientCredentialsGrantRequest(server, machine, oauth.ClientSecretPost(credentials.clientSecret), { audience: resource.audience, organization: credentials.organizationId }, { signal: AbortSignal.timeout(15000) });
266891
+ if (!response.ok) {
266892
+ await response.body?.cancel();
266893
+ throw new Error(`The authorization server refused the machine token request (HTTP ${response.status})`);
266894
+ }
266895
+ let accessToken;
266896
+ let claims;
266897
+ try {
266898
+ ({ access_token: accessToken } = await oauth.processClientCredentialsResponse(server, machine, response));
266899
+ const segments = accessToken.split(".");
266900
+ if (segments.length === 3 && segments[1]) {
266901
+ claims = JSON.parse(Buffer.from(segments[1], "base64url").toString("utf-8"));
266902
+ }
266903
+ } catch {
266904
+ throw new Error("The authorization server returned an invalid machine access token");
266905
+ }
266906
+ if (claims?.org_id !== credentials.organizationId) {
266907
+ throw new Error("The machine token does not match the requested organization");
266908
+ }
266909
+ return accessToken;
266910
+ }
266873
266911
  function browserCommand(url) {
266874
266912
  if (process.platform === "darwin") {
266875
266913
  return ["open", [url]];
@@ -266889,14 +266927,13 @@ function openBrowser(url) {
266889
266927
  `));
266890
266928
  child.unref();
266891
266929
  }
266892
- var ORGANIZATION = /^org_[A-Za-z0-9]+$/;
266893
266930
  async function signIn(config, { noBrowser = false, organizationId, nameOrganization = () => Promise.resolve(null), preflight } = {}) {
266894
266931
  await preflight?.();
266895
266932
  const redirect = new URL(config.redirectUri);
266896
266933
  if (redirect.protocol !== "http:" || redirect.hostname !== "127.0.0.1" || !redirect.port) {
266897
266934
  throw new Error("The CLI can only receive a login on a 127.0.0.1 loopback address");
266898
266935
  }
266899
- const as = await authority(config);
266936
+ const as = await authority(config.issuer);
266900
266937
  if (!as.authorization_endpoint) {
266901
266938
  throw new Error("Issuer has no authorization endpoint");
266902
266939
  }
@@ -266959,7 +266996,7 @@ ${authorization.href}
266959
266996
  await oauth.validateApplicationLevelSignature(as, response, { signal: AbortSignal.timeout(15000) });
266960
266997
  const claims = oauth.getValidatedIdTokenClaims(tokens);
266961
266998
  const organization = claims?.org_id;
266962
- if (!claims || typeof organization !== "string" || !ORGANIZATION.test(organization)) {
266999
+ if (!claims || typeof organization !== "string" || !ORGANIZATION_ID.test(organization)) {
266963
267000
  throw new Error("This login selected no organization; ask your organization to give you access to Arbol");
266964
267001
  }
266965
267002
  if (organizationId !== undefined && organization !== organizationId) {
@@ -266998,7 +267035,8 @@ async function login(credentials, options = {}) {
266998
267035
  }
266999
267036
  async function revoke(config, refreshToken) {
267000
267037
  try {
267001
- const response = await oauth.revocationRequest(await authority(config), client(config), oauth.None(), refreshToken, {
267038
+ const server = await authority(config.issuer);
267039
+ const response = await oauth.revocationRequest(server, client(config), oauth.None(), refreshToken, {
267002
267040
  signal: AbortSignal.timeout(15000)
267003
267041
  });
267004
267042
  await response.body?.cancel();
@@ -267029,13 +267067,14 @@ async function accessToken(credentials) {
267029
267067
  if (session.refreshing) {
267030
267068
  throw new Error(`A previous refresh has an unknown outcome; ${again}`);
267031
267069
  }
267032
- if (session.expiresAt > Date.now() + 60000) {
267070
+ const refreshWindow = session.refreshToken ? 60000 : 0;
267071
+ if (session.expiresAt > Date.now() + refreshWindow) {
267033
267072
  return session.accessToken;
267034
267073
  }
267035
267074
  if (!session.refreshToken) {
267036
267075
  throw new Error(`The session expired; ${again}`);
267037
267076
  }
267038
- const as = await authority(credentials.config);
267077
+ const as = await authority(credentials.config.issuer);
267039
267078
  await credentials.store.set(login.key, JSON.stringify({ ...session, refreshing: true }));
267040
267079
  try {
267041
267080
  const response = await oauth.refreshTokenGrantRequest(as, client(credentials.config), oauth.None(), session.refreshToken, { signal: AbortSignal.timeout(30000) });
@@ -267070,7 +267109,7 @@ async function logout(credentials) {
267070
267109
  let revokeFailed = false;
267071
267110
  try {
267072
267111
  if (session.refreshToken) {
267073
- const as = await authority(credentials.config);
267112
+ const as = await authority(credentials.config.issuer);
267074
267113
  const response = await oauth.revocationRequest(as, client(credentials.config), oauth.None(), session.refreshToken, { signal: AbortSignal.timeout(15000) });
267075
267114
  if (!response.ok) {
267076
267115
  revokeFailed = true;
@@ -268724,7 +268763,7 @@ ${name}`);
268724
268763
  }
268725
268764
 
268726
268765
  // src/index.ts
268727
- var VERSION = "3.73.0";
268766
+ var VERSION = "3.73.1";
268728
268767
  var RELEASE = generation_default.release;
268729
268768
  var commands2 = { ...commands, ...accountOperatorCommands };
268730
268769
  var SDK_PATHS = new Map(Object.values(commands2).map((command) => [command.operation, command.sdkPath]));
@@ -268766,6 +268805,7 @@ Flags
268766
268805
  --profile <name> The profile to use or save (default: ARBOL_PROFILE, then the default)
268767
268806
  --input <file|-> JSON input (- reads stdin); flags override its fields
268768
268807
  --api-key-stdin Read an API key (arb_live_…) from stdin, for this command only
268808
+ --organization <org_…> Name the organization for machine credentials
268769
268809
  --json Machine-readable output for auth status and auth profiles
268770
268810
  --dry-run Show the request without sending it
268771
268811
  -y, --yes Confirm a deletion without asking
@@ -268779,10 +268819,11 @@ Examples
268779
268819
  arbol visoft connections list --profile ci
268780
268820
  ARBOL_API_KEY=… arbol sura appointments lookup --help
268781
268821
 
268782
- Credentials, in order: an API key from --api-key-stdin or ARBOL_API_KEY (scripts, servers, CI), then
268783
- the profile --profile or ARBOL_PROFILE names, then the default profile. A login's session and a saved
268784
- API key are sealed on this machine; a login renews by itself. Sign-in is discovered from the API
268785
- (ARBOL_API_URL, else https://api.getarbol.com). Requests are never retried.
268822
+ Machine commands take an API key from --api-key-stdin or ARBOL_API_KEY, or Auth0 credentials
268823
+ from ARBOL_M2M_CLIENT_ID and ARBOL_M2M_CLIENT_SECRET with --organization. Without either,
268824
+ commands use the profile --profile or ARBOL_PROFILE names, then the default profile.
268825
+ A login's session and a saved API key are sealed on this machine. Sign-in is discovered from
268826
+ the API (ARBOL_API_URL, else https://api.getarbol.com). Requests are never retried.
268786
268827
  More at https://github.com/getarbol/project-arbol-cli
268787
268828
  `;
268788
268829
 
@@ -268799,7 +268840,8 @@ var GLOBAL = {
268799
268840
  "no-browser": { type: "boolean" },
268800
268841
  "api-key-stdin": { type: "boolean" },
268801
268842
  input: { type: "string" },
268802
- profile: { type: "string" }
268843
+ profile: { type: "string" },
268844
+ organization: { type: "string" }
268803
268845
  };
268804
268846
  async function stdin(limit) {
268805
268847
  const chunks = [];
@@ -268982,10 +269024,30 @@ Run arbol --help.`);
268982
269024
  }
268983
269025
  return chosen;
268984
269026
  };
268985
- const machine = Boolean(values["api-key-stdin"] || process.env.ARBOL_API_KEY);
269027
+ const apiKeySelected = Boolean(values["api-key-stdin"] || process.env.ARBOL_API_KEY);
269028
+ const clientId = process.env.ARBOL_M2M_CLIENT_ID;
269029
+ const clientSecret = process.env.ARBOL_M2M_CLIENT_SECRET;
269030
+ const m2mSelected = clientId !== undefined || clientSecret !== undefined;
269031
+ const machine = apiKeySelected || m2mSelected;
269032
+ if (apiKeySelected && m2mSelected) {
269033
+ throw new UsageError("Choose either an Arbol API key or Auth0 machine credentials");
269034
+ }
268986
269035
  if (machine && values.profile) {
268987
- throw new UsageError("An API key from --api-key-stdin or ARBOL_API_KEY and --profile both name a credential");
269036
+ throw new UsageError("A machine credential and --profile both name a credential");
269037
+ }
269038
+ const organizationId = values.organization;
269039
+ if (organizationId !== undefined && !m2mSelected) {
269040
+ throw new UsageError("--organization requires Auth0 machine credentials");
268988
269041
  }
269042
+ const machineCredentials = () => {
269043
+ if (!clientId || !/^[\w-]+$/.test(clientId) || !clientSecret?.trim()) {
269044
+ throw new UsageError("Set both ARBOL_M2M_CLIENT_ID and ARBOL_M2M_CLIENT_SECRET");
269045
+ }
269046
+ if (!organizationId || !ORGANIZATION_ID.test(organizationId)) {
269047
+ throw new UsageError("Machine authentication requires --organization with an exact Auth0 organization id");
269048
+ }
269049
+ return { clientId, clientSecret, organizationId };
269050
+ };
268989
269051
  if (servers) {
268990
269052
  const flags = {
268991
269053
  arguments: values.arguments,
@@ -269013,6 +269075,22 @@ Run arbol --help.`);
269013
269075
  throw new UsageError("--no-browser applies only to arbol auth login and arbol auth switch");
269014
269076
  }
269015
269077
  const json = Boolean(values.json) || !process.stdout.isTTY;
269078
+ if (m2mSelected) {
269079
+ if (action !== "status" || positionals.length !== 2) {
269080
+ throw new UsageError("Auth0 machine credentials support auth status. Unset them to manage a user login.");
269081
+ }
269082
+ const credentials = machineCredentials();
269083
+ const status = {
269084
+ credential: "auth0-m2m",
269085
+ clientId: credentials.clientId,
269086
+ organizationId: credentials.organizationId,
269087
+ configured: true
269088
+ };
269089
+ process.stdout.write(json ? `${JSON.stringify(status)}
269090
+ ` : `Auth0 machine credentials configured for ${status.organizationId} (client ${status.clientId}).
269091
+ `);
269092
+ return;
269093
+ }
269016
269094
  if (action === "status" && positionals.length === 2 && process.env.ARBOL_API_KEY) {
269017
269095
  const key = API_KEY.exec(process.env.ARBOL_API_KEY.trim());
269018
269096
  const status = {
@@ -269215,7 +269293,7 @@ Run arbol --help.`);
269215
269293
  organizationId: active.organizationId,
269216
269294
  organizationName,
269217
269295
  expiresAt: new Date(session.expiresAt).toISOString(),
269218
- requiresLogin: !!session.refreshing || !session.refreshToken && session.expiresAt <= Date.now()
269296
+ requiresLogin: sessionRequiresLogin(session)
269219
269297
  };
269220
269298
  process.stdout.write(json ? `${JSON.stringify(status)}
269221
269299
  ` : `Profile ${name}: signed in to ${organizationName ? `${organizationName} (${active.organizationId})` : active.organizationId} as ${active.subject}.
@@ -269311,7 +269389,7 @@ Services: ${SERVICES.join(", ")}. Run arbol --help.`);
269311
269389
  const operator = isAccountOperator(command.operation);
269312
269390
  if (operator && machine)
269313
269391
  throw new UsageError("Account administration requires a staff user login");
269314
- if (machine) {
269392
+ if (apiKeySelected) {
269315
269393
  if (values["api-key-stdin"] && process.env.ARBOL_API_KEY) {
269316
269394
  throw new UsageError("Provide one API key source");
269317
269395
  }
@@ -269322,6 +269400,11 @@ Services: ${SERVICES.join(", ")}. Run arbol --help.`);
269322
269400
  }
269323
269401
  token = key;
269324
269402
  api = chosenApi();
269403
+ } else if (m2mSelected) {
269404
+ const credentials = machineCredentials();
269405
+ api = chosenApi();
269406
+ const resource = await discoverResource(api);
269407
+ token = await machineAccessToken(resource, credentials);
269325
269408
  } else {
269326
269409
  const { name, profile } = await required();
269327
269410
  if (operator && profile.kind !== "login")
@@ -269348,7 +269431,7 @@ Services: ${SERVICES.join(", ")}. Run arbol --help.`);
269348
269431
  `);
269349
269432
  }
269350
269433
  }
269351
- var PERSON_ONLY = "Organization servers take a person's login (arbol auth login): the API refuses API keys on these routes";
269434
+ var PERSON_ONLY = "Organization servers require a person's login (arbol auth login)";
269352
269435
  var CONNECTIONS_USAGE = `Usage:
269353
269436
  arbol connections tools list <connectionId>
269354
269437
  arbol connections tools run <connectionId> <tool> [--arguments <json> | --input <file|->]
@@ -269387,7 +269470,7 @@ async function connectionCommand(positionals, flags, access) {
269387
269470
  throw new UsageError("--no-browser applies only to arbol auth login and arbol auth switch");
269388
269471
  }
269389
269472
  if (access.machine) {
269390
- throw new UsageError(`${PERSON_ONLY}; unset ARBOL_API_KEY or drop --api-key-stdin`);
269473
+ throw new UsageError(`${PERSON_ONLY}. Remove the machine credential from this command.`);
269391
269474
  }
269392
269475
  if (list && (flags.arguments !== undefined || flags.input !== undefined)) {
269393
269476
  throw new UsageError("arbol connections tools list takes no arguments");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arbol-ai/cli",
3
- "version": "3.73.0",
3
+ "version": "3.73.1",
4
4
  "description": "The Arbol CLI: the Arbol API from your terminal, with commands generated by Cloudflare Forge from the public OpenAPI.",
5
5
  "keywords": [
6
6
  "arbol",