@screenshotscout/cli 0.2.0 → 0.3.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
@@ -10,7 +10,7 @@ You need:
10
10
 
11
11
  - Node.js 22 or newer;
12
12
  - a Screenshot Scout [access key](https://screenshotscout.com/app/api-keys); and
13
- - the matching secret key only when you want automatic signing or the API key requires signed requests.
13
+ - the matching secret key only when you want signed capture URLs or the API key requires signed requests.
14
14
 
15
15
  ## Install
16
16
 
@@ -55,7 +55,7 @@ $env:SCREENSHOTSCOUT_ACCESS_KEY = "YOUR_ACCESS_KEY"
55
55
  $env:SCREENSHOTSCOUT_SECRET_KEY = "YOUR_SECRET_KEY"
56
56
  ```
57
57
 
58
- `SCREENSHOTSCOUT_ACCESS_KEY` is required. `SCREENSHOTSCOUT_SECRET_KEY` is optional; omit its assignment for unsigned requests. When the secret key is configured, capture requests and generated capture URLs are signed automatically, while the secret key stays local.
58
+ `SCREENSHOTSCOUT_ACCESS_KEY` is required. `SCREENSHOTSCOUT_SECRET_KEY` is optional; omit its assignment for unsigned requests. When the secret key is configured, generated capture URLs and captures sent with `--method get` are signed automatically, while the secret key stays local.
59
59
 
60
60
  ## Commands
61
61
 
@@ -77,7 +77,7 @@ screenshotscout capture "https://example.com" \
77
77
  --output screenshot.webp
78
78
  ```
79
79
 
80
- `capture` accepts `--method get` or `--method post`. You can omit `--method` unless you need to select one explicitly.
80
+ `capture` accepts `--method get` or `--method post`. You can omit `--method` unless you need to select one explicitly, such as `--method get` for signed requests.
81
81
 
82
82
  ```sh
83
83
  screenshotscout capture "https://example.com" --method post --format webp --output screenshot.webp
@@ -225,7 +225,7 @@ More inline-flag, options-file, POSIX shell, PowerShell, and CI examples are in
225
225
 
226
226
  - Run `screenshotscout --help` or `screenshotscout <command> --help` to check command syntax and current capture-option value shapes.
227
227
  - If the CLI reports that an access key is required, set `SCREENSHOTSCOUT_ACCESS_KEY` in the same process environment that runs the command.
228
- - If the API reports `signature_required`, set the matching `SCREENSHOTSCOUT_SECRET_KEY`; the CLI will sign the request automatically. See [Signed requests](https://screenshotscout.com/docs/signed-requests).
228
+ - If the API reports `signature_required`, set the matching `SCREENSHOTSCOUT_SECRET_KEY` and add `--method get`. See [Signed requests](https://screenshotscout.com/docs/signed-requests).
229
229
  - If an option is rejected with exit status `2`, check whether it uses CLI `kebab-case`, whether a boolean uses bare or inline syntax, and whether a singleton flag was repeated.
230
230
  - If an options file is rejected, confirm that it is a JSON object using exact API `snake_case` names and JSON value types.
231
231
  - If a file write fails, confirm that its parent directory exists and is writable.
package/dist/capture.js CHANGED
@@ -1,11 +1,20 @@
1
+ import { CliUsageError } from "./cli-usage-error.js";
1
2
  import { parseCaptureCommandInput } from "./input.js";
2
3
  import { writeCaptureResult } from "./result.js";
3
- import { captureWithScreenshotScoutClient, createScreenshotScoutClient, } from "./sdk.js";
4
+ import { captureWithScreenshotScoutClient, createScreenshotScoutClient, isSecretKeyConfigured, } from "./sdk.js";
5
+ const SIGNED_POST_MESSAGE = "SCREENSHOTSCOUT_SECRET_KEY is set, and POST requests can't be signed. Add --method get, or unset SCREENSHOTSCOUT_SECRET_KEY to send an unsigned POST request.";
4
6
  /** Run one capture command as a direct input -> SDK -> result adapter. */
5
7
  export async function runCaptureCommand(args, dependencies = {}) {
6
8
  const input = dependencies.inputReader === undefined
7
9
  ? await parseCaptureCommandInput(args)
8
10
  : await parseCaptureCommandInput(args, dependencies.inputReader);
11
+ const secretKeyConfigured = dependencies.client === undefined
12
+ ? isSecretKeyConfigured()
13
+ : dependencies.secretKeyConfigured === true;
14
+ // Only GET requests can be signed, and an omitted --method means POST
15
+ if (secretKeyConfigured && input.method !== "get") {
16
+ throw new CliUsageError(SIGNED_POST_MESSAGE);
17
+ }
9
18
  const client = dependencies.client ?? createScreenshotScoutClient();
10
19
  const response = await captureWithScreenshotScoutClient(client, input.targetUrl, input.captureOptions, input.method);
11
20
  if (dependencies.resultIo === undefined) {
package/dist/help.js CHANGED
@@ -26,7 +26,7 @@ export function captureCommandHelp() {
26
26
 
27
27
  CLI controls:
28
28
  --options <path|-> Read a snake_case JSON options object from a file or standard input.
29
- --method <get|post> Select the SDK capture request method.
29
+ --method <get|post> Select the request method (default post). Signed captures need get.
30
30
  -o, --output <path|-> Write the response to a file or standard output.
31
31
  --help Show this help.
32
32
 
package/dist/sdk.js CHANGED
@@ -11,6 +11,10 @@ export function createScreenshotScoutClient(environment = process.env, clientFac
11
11
  };
12
12
  return clientFactory(options);
13
13
  }
14
+ /** Whether the environment gives the client a secret key, as createScreenshotScoutClient passes it. */
15
+ export function isSecretKeyConfigured(environment = process.env) {
16
+ return environment.SCREENSHOTSCOUT_SECRET_KEY !== undefined;
17
+ }
14
18
  /** Make one capture call with only an explicitly selected request method. */
15
19
  export function captureWithScreenshotScoutClient(client, targetUrl, captureOptions, method) {
16
20
  if (method === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@screenshotscout/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Official command-line interface for the Screenshot Scout screenshot API.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -49,7 +49,7 @@
49
49
  "node": ">=22"
50
50
  },
51
51
  "dependencies": {
52
- "@screenshotscout/sdk": "0.3.0"
52
+ "@screenshotscout/sdk": "0.4.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@eslint/js": "10.0.1",