@screenshotscout/cli 0.3.0 → 0.5.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 +5 -3
- package/dist/capture.js +1 -10
- package/dist/help.js +1 -1
- package/dist/sdk.js +6 -16
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -55,7 +55,9 @@ $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, generated capture URLs and captures
|
|
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 are signed automatically, while the secret key stays local.
|
|
59
|
+
|
|
60
|
+
To send requests to another server, such as your own proxy or a mock server, set `SCREENSHOTSCOUT_BASE_URL` to its base URL. Captures then go to that URL plus `/v1/capture`, and generated capture URLs point there too.
|
|
59
61
|
|
|
60
62
|
## Commands
|
|
61
63
|
|
|
@@ -77,7 +79,7 @@ screenshotscout capture "https://example.com" \
|
|
|
77
79
|
--output screenshot.webp
|
|
78
80
|
```
|
|
79
81
|
|
|
80
|
-
`capture` accepts `--method get` or `--method post`.
|
|
82
|
+
`capture` accepts `--method get` or `--method post`. Without `--method`, it uses POST, or GET when `SCREENSHOTSCOUT_SECRET_KEY` is set. POST requests can't be signed, so `--method post` fails while the secret key is set.
|
|
81
83
|
|
|
82
84
|
```sh
|
|
83
85
|
screenshotscout capture "https://example.com" --method post --format webp --output screenshot.webp
|
|
@@ -225,7 +227,7 @@ More inline-flag, options-file, POSIX shell, PowerShell, and CI examples are in
|
|
|
225
227
|
|
|
226
228
|
- Run `screenshotscout --help` or `screenshotscout <command> --help` to check command syntax and current capture-option value shapes.
|
|
227
229
|
- 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
|
|
230
|
+
- If the API reports `signature_required`, set the matching `SCREENSHOTSCOUT_SECRET_KEY`. See [Signed requests](https://screenshotscout.com/docs/signed-requests).
|
|
229
231
|
- 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
232
|
- If an options file is rejected, confirm that it is a JSON object using exact API `snake_case` names and JSON value types.
|
|
231
233
|
- If a file write fails, confirm that its parent directory exists and is writable.
|
package/dist/capture.js
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import { CliUsageError } from "./cli-usage-error.js";
|
|
2
1
|
import { parseCaptureCommandInput } from "./input.js";
|
|
3
2
|
import { writeCaptureResult } from "./result.js";
|
|
4
|
-
import { captureWithScreenshotScoutClient, createScreenshotScoutClient,
|
|
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.";
|
|
3
|
+
import { captureWithScreenshotScoutClient, createScreenshotScoutClient, } from "./sdk.js";
|
|
6
4
|
/** Run one capture command as a direct input -> SDK -> result adapter. */
|
|
7
5
|
export async function runCaptureCommand(args, dependencies = {}) {
|
|
8
6
|
const input = dependencies.inputReader === undefined
|
|
9
7
|
? await parseCaptureCommandInput(args)
|
|
10
8
|
: 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
|
-
}
|
|
18
9
|
const client = dependencies.client ?? createScreenshotScoutClient();
|
|
19
10
|
const response = await captureWithScreenshotScoutClient(client, input.targetUrl, input.captureOptions, input.method);
|
|
20
11
|
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 request method (default post
|
|
29
|
+
--method <get|post> Select the request method (default post, or get when SCREENSHOTSCOUT_SECRET_KEY is set).
|
|
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
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
import { CaptureHttpMethod, ScreenshotScoutClient, } from "@screenshotscout/sdk";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const options = {
|
|
8
|
-
// Missing and invalid values deliberately reach the SDK's own validation.
|
|
9
|
-
accessKey: accessKey,
|
|
10
|
-
...(secretKey === undefined ? {} : { secretKey }),
|
|
11
|
-
};
|
|
12
|
-
return clientFactory(options);
|
|
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;
|
|
2
|
+
// The SDK reads SCREENSHOTSCOUT_ACCESS_KEY and SCREENSHOTSCOUT_SECRET_KEY itself.
|
|
3
|
+
const DEFAULT_CLIENT_FACTORY = () => new ScreenshotScoutClient();
|
|
4
|
+
/** Construct the official SDK client, which takes its keys from the environment. */
|
|
5
|
+
export function createScreenshotScoutClient(clientFactory = DEFAULT_CLIENT_FACTORY) {
|
|
6
|
+
return clientFactory();
|
|
17
7
|
}
|
|
18
|
-
/** Make one capture call with only an explicitly selected request method. */
|
|
8
|
+
/** Make one capture call with only an explicitly selected request method; the SDK picks the default. */
|
|
19
9
|
export function captureWithScreenshotScoutClient(client, targetUrl, captureOptions, method) {
|
|
20
10
|
if (method === undefined) {
|
|
21
11
|
return client.capture(targetUrl, captureOptions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@screenshotscout/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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.
|
|
52
|
+
"@screenshotscout/sdk": "0.6.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@eslint/js": "10.0.1",
|