@hardfin/cli 0.1.0-dev.32 → 0.1.0-dev.33

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
@@ -208,6 +208,21 @@ On WSL the browser is opened through Windows, by `wslview`, then PowerShell, the
208
208
  The port changes every time, so Hardfin matches a loopback redirect by everything except its
209
209
  port, which is what RFC 8252 asks of an authorization server.
210
210
 
211
+ ### When an agent signs you in
212
+
213
+ An agent that runs `hardfin login` reads its stderr, and you only see what the agent passes
214
+ on. So when output is JSON, which it is whenever stdout is not a terminal, the command writes
215
+ one line of JSON on stderr before it starts waiting.
216
+
217
+ | `event` | Also carries | The agent should |
218
+ | ------------- | -------------------------------------------------------------------- | --------------------------------------------------- |
219
+ | `sign_in_url` | `url`, `browserOpened`, `waitSeconds` | Show you `url`, saying whether a browser tab opened |
220
+ | `device_code` | `userCode`, `verificationUri`, `url`, `browserOpened`, `waitSeconds` | Show you the code and where to enter it |
221
+
222
+ The command then waits up to `waitSeconds` for you to approve, so the agent has to let it run
223
+ that long. An agent with no way to open your browser, such as one in a cloud sandbox, signs
224
+ in with `--device`.
225
+
211
226
  ### Signing in from a machine with no browser
212
227
 
213
228
  `hardfin login --device` prints a short code and a page to enter it on, and waits. Approve
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="62437fed-ab84-53c5-9984-9bbadc0f2e15")}catch(e){}}();
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3f5ddeb4-6ae9-5ded-b447-15c8483fc583")}catch(e){}}();
4
4
  import module from "node:module";
5
5
  //#region src/cli.ts
6
6
  module.enableCompileCache?.();
@@ -14,7 +14,7 @@ process.on("unhandledRejection", (error) => void toCrash(error));
14
14
  try {
15
15
  const answer = await toQuickAnswer(process.argv.slice(2));
16
16
  if (answer === void 0) {
17
- const { toCli, toParseExitCode, wasReportAttempted } = await import("./program-B02z-kNH.js");
17
+ const { toCli, toParseExitCode, wasReportAttempted } = await import("./program-ByvcKNri.js");
18
18
  try {
19
19
  await toCli().parseAsync(process.argv);
20
20
  } catch (error) {
@@ -33,7 +33,7 @@ async function toCrash(error) {
33
33
  isCrashing = true;
34
34
  process.stderr.write(`error: ${error instanceof Error ? error.message : String(error)}\n`);
35
35
  try {
36
- const { toReported } = await import("./program-B02z-kNH.js");
36
+ const { toReported } = await import("./program-ByvcKNri.js");
37
37
  await toReported(error, false, void 0, "fatal");
38
38
  } finally {
39
39
  process.exit(1);
@@ -51,4 +51,4 @@ async function toQuickAnswer(args) {
51
51
  export {};
52
52
 
53
53
  //# sourceMappingURL=cli.js.map
54
- //# debugId=62437fed-ab84-53c5-9984-9bbadc0f2e15
54
+ //# debugId=3f5ddeb4-6ae9-5ded-b447-15c8483fc583
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b1928379-e7e3-5a7e-9ade-d45695e05814")}catch(e){}}();
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="93b4bc8d-ebeb-59ca-967b-9fd10484e4a5")}catch(e){}}();
4
4
  import { a as defineCommand, i as GLOBAL_FLAGS, r as ExitCode, t as toInvocation } from "./scrub-BN3gyBpR.js";
5
5
  import { n as toCompletion, t as toAnswer$1 } from "./completion-tree-rR_Rmeij.js";
6
6
  import { createRequire } from "node:module";
@@ -987,6 +987,7 @@ function toGuide(commands, version) {
987
987
  "## Before calling",
988
988
  "",
989
989
  "- Authenticate with `--api-key`, by setting `HARDFIN_API_KEY`, or by running `hardfin login`",
990
+ "- `hardfin login` writes one JSON line on stderr before it waits. Show the person its `url`, or its `userCode` and `verificationUri`, and let the command run for `waitSeconds`",
990
991
  "- Every command prints JSON on stdout and diagnostics on stderr",
991
992
  "- Output is JSON whenever stdout is not a terminal, so no flag is needed when calling from code",
992
993
  "",
@@ -2154,7 +2155,13 @@ async function runLogin(input) {
2154
2155
  challenge: pkce.challenge
2155
2156
  });
2156
2157
  const opened = input.flags["noBrowser"] !== true && !process.env["HARDFIN_NO_BROWSER"] && openBrowser(url);
2157
- process.stderr.write(opened ? `Opening your browser to sign in. If it did not open:\n\n${url}\n\n` : `Open this URL to sign in:\n\n${url}\n\n`);
2158
+ if (input.isJSON) writeEvent({
2159
+ event: "sign_in_url",
2160
+ url,
2161
+ browserOpened: opened,
2162
+ waitSeconds: WAIT_MS / 1e3
2163
+ });
2164
+ else process.stderr.write(opened ? `Opening your browser to sign in. If it did not open:\n\n${url}\n\n` : `Open this URL to sign in:\n\n${url}\n\n`);
2158
2165
  const prompt = toPrompt(url);
2159
2166
  if (process.stdin.isTTY) process.stderr.write("Press c to copy the URL, or paste the code or redirect URL here: ");
2160
2167
  let callback;
@@ -2164,7 +2171,7 @@ async function runLogin(input) {
2164
2171
  listener.close();
2165
2172
  prompt.close();
2166
2173
  }
2167
- process.stderr.write(callback.error ? "\n" : "\nApproved, finishing the sign in\n");
2174
+ if (!input.isJSON) process.stderr.write(callback.error ? "\n" : "\nApproved, finishing the sign in\n");
2168
2175
  if (callback.error) {
2169
2176
  writeFailure("sign_in_failed", `sign in was refused: ${callback.error}${callback.errorDescription ? `, ${callback.errorDescription}` : ""}`, input.isJSON);
2170
2177
  return ExitCode.ERROR;
@@ -2200,7 +2207,15 @@ async function runDeviceLogin(input, metadata, scope) {
2200
2207
  const device = await toDeviceAuthorization(metadata.device_authorization_endpoint, settings.clientId, scope);
2201
2208
  const url = device.verificationUriComplete ?? device.verificationUri;
2202
2209
  const opened = input.flags["noBrowser"] !== true && !process.env["HARDFIN_NO_BROWSER"] && openBrowser(url);
2203
- process.stderr.write([
2210
+ if (input.isJSON) writeEvent({
2211
+ event: "device_code",
2212
+ userCode: device.userCode,
2213
+ verificationUri: device.verificationUri,
2214
+ url,
2215
+ browserOpened: opened,
2216
+ waitSeconds: Math.max(0, Math.round((device.expiresAt - Date.now()) / 1e3))
2217
+ });
2218
+ else process.stderr.write([
2204
2219
  "",
2205
2220
  ` Code ${device.userCode}`,
2206
2221
  ` At ${device.verificationUri}`,
@@ -2252,6 +2267,10 @@ async function toSignedIn(input, metadata, tokens) {
2252
2267
  ].join("\n"));
2253
2268
  return ExitCode.OK;
2254
2269
  }
2270
+ /** writeEvent tells a program what a sign in is waiting on, as one line of JSON on stderr. */
2271
+ function writeEvent(event) {
2272
+ process.stderr.write(`${JSON.stringify(event)}\n`);
2273
+ }
2255
2274
  /** toAuthorizationUrl builds the URL the person approves this CLI at. */
2256
2275
  function toAuthorizationUrl(endpoint, request) {
2257
2276
  const url = new URL(endpoint);
@@ -6168,5 +6187,5 @@ async function toReported(error, isJSON, resolved, level = "error") {
6168
6187
  //#endregion
6169
6188
  export { toCli, toParseExitCode, toReported, wasReportAttempted };
6170
6189
 
6171
- //# sourceMappingURL=program-B02z-kNH.js.map
6172
- //# debugId=b1928379-e7e3-5a7e-9ade-d45695e05814
6190
+ //# sourceMappingURL=program-ByvcKNri.js.map
6191
+ //# debugId=93b4bc8d-ebeb-59ca-967b-9fd10484e4a5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hardfin/cli",
3
- "version": "0.1.0-dev.32",
3
+ "version": "0.1.0-dev.33",
4
4
  "description": "Command line interface for the Hardfin API",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Hardfin, Inc.",