oleander-cli 0.28.0 → 0.29.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/README.md CHANGED
@@ -103,6 +103,13 @@ oleander spark jobs submit entrypoint.py \
103
103
 
104
104
  ## Profiles
105
105
 
106
+ ```bash
107
+ oleander login
108
+ oleander login --profile acme
109
+ ```
110
+
111
+ `oleander login` opens your browser to approve the sign-in, then saves an API key for the organization you approved it in. Use `--no-browser` on a remote machine to print the link instead. To paste a key yourself, use `oleander configure`:
112
+
106
113
  ```bash
107
114
  oleander configure --profile acme
108
115
  oleander configure --profile sandbox
package/dist/index.cjs CHANGED
@@ -33207,7 +33207,7 @@ function currentOrganizationSelector() {
33207
33207
  return organizationOverride ?? envOrganization();
33208
33208
  }
33209
33209
  function applyCommandProfile(actionCommand) {
33210
- if (actionCommand.name() === "configure") {
33210
+ if (["configure", "login"].includes(actionCommand.name())) {
33211
33211
  return;
33212
33212
  }
33213
33213
  const profile = actionCommand.optsWithGlobals().profile;
@@ -45388,7 +45388,7 @@ async function polarsCommand(query, options) {
45388
45388
  printRowOutput(result.results, options.output);
45389
45389
  return;
45390
45390
  }
45391
- const where = result.compute?.distributed ? `Polars Cloud (${result.compute.instanceType ?? "?"} x${result.compute.clusterSize ?? "?"})` : "Daytona sandbox";
45391
+ const where = result.compute?.distributed ? `Polars Cloud (${result.compute.instanceType ?? "?"} x${result.compute.clusterSize ?? "?"})` : "oleander compute";
45392
45392
  spinner?.succeed(
45393
45393
  source_default.green(
45394
45394
  `Polars run complete on ${where}${result.execution_time ? ` (${result.execution_time})` : ""}`
@@ -45775,7 +45775,7 @@ var import_fs7 = require("fs");
45775
45775
  // package.json
45776
45776
  var package_default = {
45777
45777
  name: "oleander-cli",
45778
- version: "0.28.0",
45778
+ version: "0.29.0",
45779
45779
  description: "oleander CLI",
45780
45780
  keywords: [
45781
45781
  "cli",
@@ -47004,7 +47004,7 @@ var defaultSleep = (ms) => new Promise((resolve4) => setTimeout(resolve4, ms));
47004
47004
  async function waitForRun2(client, slug, runId, options = {}) {
47005
47005
  const interval = options.intervalMs ?? RUN_POLL_INTERVAL_MS;
47006
47006
  const timeout = options.timeoutMs ?? RUN_WAIT_TIMEOUT_MS;
47007
- const sleep = options.sleep ?? defaultSleep;
47007
+ const sleep2 = options.sleep ?? defaultSleep;
47008
47008
  const now = options.now ?? Date.now;
47009
47009
  const deadline = now() + timeout;
47010
47010
  for (; ; ) {
@@ -47014,7 +47014,7 @@ async function waitForRun2(client, slug, runId, options = {}) {
47014
47014
  return { detail, timedOut: false };
47015
47015
  }
47016
47016
  if (now() + interval > deadline) return { detail, timedOut: true };
47017
- await sleep(interval);
47017
+ await sleep2(interval);
47018
47018
  }
47019
47019
  }
47020
47020
  function isFailedRun(detail) {
@@ -48496,11 +48496,11 @@ function getSkillsStatus(options = {}) {
48496
48496
  };
48497
48497
  }
48498
48498
  function installSkills(options = {}) {
48499
- const spawn3 = options.spawn ?? ((command, args2, spawnOptions) => (0, import_node_child_process4.spawnSync)(command, args2, spawnOptions));
48499
+ const spawn4 = options.spawn ?? ((command, args2, spawnOptions) => (0, import_node_child_process4.spawnSync)(command, args2, spawnOptions));
48500
48500
  const home = options.homeDir ?? (0, import_node_os5.homedir)();
48501
48501
  const agentRoots = options.agentRoots ?? AGENT_SKILL_ROOTS;
48502
48502
  const env2 = options.homeDir ? { ...process.env, HOME: options.homeDir } : process.env;
48503
- const result = spawn3("npx", [...SKILLS_ADD_ARGS], {
48503
+ const result = spawn4("npx", [...SKILLS_ADD_ARGS], {
48504
48504
  encoding: "utf8",
48505
48505
  env: env2,
48506
48506
  shell: process.platform === "win32"
@@ -48728,12 +48728,130 @@ async function whoamiCommand(options) {
48728
48728
  printProfileIdentity(current);
48729
48729
  }
48730
48730
 
48731
+ // src/commands/login.ts
48732
+ var import_node_child_process5 = require("child_process");
48733
+ var import_node_os6 = require("os");
48734
+ var CLI_CLIENT_ID = "oleander-cli";
48735
+ var DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
48736
+ function registerLoginCommand(program3) {
48737
+ program3.command("login").description("Signs in from your browser and saves an API key").option("--profile <name>", PROFILE_OPTION_DESCRIPTION).option("--no-browser", "Print the sign-in link instead of opening it").addHelpText(
48738
+ "after",
48739
+ `
48740
+ Examples:
48741
+ oleander login
48742
+ oleander login --profile production
48743
+ `
48744
+ ).action(loginCommand);
48745
+ }
48746
+ async function postJson(url, body, headers = {}) {
48747
+ const response = await fetch(url, {
48748
+ method: "POST",
48749
+ headers: { "Content-Type": "application/json", ...headers },
48750
+ body: JSON.stringify(body)
48751
+ });
48752
+ const data = await response.json().catch(() => ({}));
48753
+ return { status: response.status, data };
48754
+ }
48755
+ function openInBrowser(url) {
48756
+ const [command, args2] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
48757
+ try {
48758
+ const child = (0, import_node_child_process5.spawn)(command, args2, { stdio: "ignore", detached: true });
48759
+ child.on("error", () => {
48760
+ });
48761
+ child.unref();
48762
+ } catch {
48763
+ }
48764
+ }
48765
+ var sleep = (ms) => new Promise((r2) => setTimeout(r2, ms));
48766
+ async function waitForApproval(endpoint, code, wait2 = sleep) {
48767
+ let intervalSeconds = Math.max(code.interval, 1);
48768
+ const deadline = Date.now() + code.expires_in * 1e3;
48769
+ while (Date.now() < deadline) {
48770
+ await wait2(intervalSeconds * 1e3);
48771
+ const { status, data } = await postJson(
48772
+ `${endpoint}/api/auth/device/token`,
48773
+ {
48774
+ grant_type: DEVICE_GRANT_TYPE,
48775
+ device_code: code.device_code,
48776
+ client_id: CLI_CLIENT_ID
48777
+ }
48778
+ );
48779
+ if (status === 200 && typeof data.access_token === "string") {
48780
+ return data.access_token;
48781
+ }
48782
+ switch (data.error) {
48783
+ case "authorization_pending":
48784
+ continue;
48785
+ case "slow_down":
48786
+ intervalSeconds += 5;
48787
+ continue;
48788
+ case "access_denied":
48789
+ throw new Error("Sign-in was denied in the browser.");
48790
+ case "expired_token":
48791
+ throw new Error("The sign-in code expired. Run oleander login again.");
48792
+ default:
48793
+ throw new Error(
48794
+ typeof data.error_description === "string" ? data.error_description : `Sign-in failed (HTTP ${status}).`
48795
+ );
48796
+ }
48797
+ }
48798
+ throw new Error("The sign-in code expired. Run oleander login again.");
48799
+ }
48800
+ async function loginCommand(options) {
48801
+ const endpoint = getEndpoint();
48802
+ const interactive = isInteractive2();
48803
+ if (interactive) Ie("Signing in to oleander");
48804
+ const requested = await postJson(`${endpoint}/api/auth/device/code`, {
48805
+ client_id: CLI_CLIENT_ID
48806
+ });
48807
+ if (requested.status !== 200) {
48808
+ logger.error(`Could not start sign-in (HTTP ${requested.status}).`);
48809
+ process.exit(1);
48810
+ }
48811
+ const code = requested.data;
48812
+ const message = `Open ${source_default.cyan(code.verification_uri)} and enter ${source_default.bold(code.user_code)}`;
48813
+ if (interactive) M2.step(message);
48814
+ else logger.info(message);
48815
+ if (options.browser) openInBrowser(code.verification_uri_complete);
48816
+ const waiting = interactive ? Y2() : null;
48817
+ waiting?.start("Waiting for approval in your browser");
48818
+ let accessToken;
48819
+ try {
48820
+ accessToken = await waitForApproval(endpoint, code);
48821
+ } catch (error) {
48822
+ waiting?.stop("Not signed in");
48823
+ logger.error(error instanceof Error ? error.message : String(error));
48824
+ process.exit(1);
48825
+ }
48826
+ const issued = await postJson(
48827
+ `${endpoint}/api/v1/cli/api-key`,
48828
+ { device: (0, import_node_os6.hostname)() },
48829
+ { Authorization: `Bearer ${accessToken}` }
48830
+ );
48831
+ if (issued.status !== 201) {
48832
+ waiting?.stop("Not signed in");
48833
+ logger.error(
48834
+ typeof issued.data.error === "string" ? issued.data.error : `Could not create an API key (HTTP ${issued.status}).`
48835
+ );
48836
+ process.exit(1);
48837
+ }
48838
+ const key = issued.data;
48839
+ waiting?.stop(`Signed in to ${key.organization.name || key.organization.id}`);
48840
+ const profile = options.profile?.trim() || await currentProfileName() || DEFAULT_PROFILE;
48841
+ await saveProfile(profile, {
48842
+ apiKey: key.api_key,
48843
+ interactive
48844
+ });
48845
+ if (interactive) Se("You're signed in.");
48846
+ }
48847
+
48731
48848
  // src/index.ts
48732
48849
  var program2 = new Command();
48733
48850
  var args = process.argv.slice(2);
48734
48851
  program2.name("oleander").description(`oleander CLI (v${VERSION})`).version(VERSION).enablePositionalOptions().option("--profile <name>", PROFILE_OPTION_DESCRIPTION).hook("preAction", (_thisCommand, actionCommand) => {
48735
48852
  applyCommandProfile(actionCommand);
48736
48853
  });
48854
+ registerLoginCommand(program2);
48737
48855
  registerConfigureCommand(program2);
48738
48856
  registerSwitchCommand(program2);
48739
48857
  registerWhoamiCommand(program2);
@@ -48794,7 +48912,7 @@ for (const command of program2.commands) {
48794
48912
  attachProfileOption(command);
48795
48913
  }
48796
48914
  function attachProfileOption(command) {
48797
- if (command.name() === "configure" || command.name() === "switch") {
48915
+ if (["configure", "login", "switch"].includes(command.name())) {
48798
48916
  return;
48799
48917
  }
48800
48918
  command.option("--profile <name>", PROFILE_OPTION_DESCRIPTION);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oleander-cli",
3
- "version": "0.28.0",
3
+ "version": "0.29.0",
4
4
  "description": "oleander CLI",
5
5
  "keywords": [
6
6
  "cli",