@tiny-fish/cli 0.1.8-next.72 → 0.2.0-next.77

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.
@@ -1,7 +1,7 @@
1
1
  import { InvalidArgumentError } from "commander";
2
2
  import { getApiKey } from "../lib/auth.js";
3
3
  import { fetchContentGet } from "../lib/client.js";
4
- import { handleApiError, out, outLine } from "../lib/output.js";
4
+ import { err, handleApiError, out, outLine } from "../lib/output.js";
5
5
  const MIN_PER_URL_TIMEOUT_MS = 1;
6
6
  const MAX_PER_URL_TIMEOUT_MS = 110000;
7
7
  function parsePerUrlTimeoutMs(value) {
@@ -26,6 +26,12 @@ function printPrettyFetch(response) {
26
26
  outLine(` Title: ${result.title}`);
27
27
  if (result.final_url && result.final_url !== result.url)
28
28
  outLine(` Final URL: ${result.final_url}`);
29
+ if (result.not_modified)
30
+ outLine(` Not Modified: true`);
31
+ if (result.etag)
32
+ outLine(` ETag: ${result.etag}`);
33
+ if (result.last_modified)
34
+ outLine(` Last-Modified: ${result.last_modified}`);
29
35
  outLine("");
30
36
  }
31
37
  }
@@ -55,8 +61,18 @@ export function registerFetch(program) {
55
61
  .option("--links", "Include extracted links")
56
62
  .option("--image-links", "Include extracted image links")
57
63
  .option("--per-url-timeout-ms <milliseconds>", "Per-URL timeout budget in milliseconds", parsePerUrlTimeoutMs)
64
+ .option("--if-none-match <etag>", "ETag validator for a conditional GET (single URL only)")
65
+ .option("--if-modified-since <http-date>", "Last-Modified validator for a conditional GET (single URL only)")
66
+ .option("--include-etag-and-last-modified", "Include etag / last_modified validators on each result")
58
67
  .option("--pretty", "Human-readable output")
59
68
  .action(async (urls, opts) => {
69
+ if ((opts.ifNoneMatch !== undefined || opts.ifModifiedSince !== undefined) &&
70
+ urls.length > 1) {
71
+ err({
72
+ error: "--if-none-match and --if-modified-since can only be used with a single URL, not a batch",
73
+ });
74
+ process.exit(1);
75
+ }
60
76
  const apiKey = getApiKey();
61
77
  try {
62
78
  const response = await fetchContentGet({
@@ -67,6 +83,13 @@ export function registerFetch(program) {
67
83
  ...(opts.perUrlTimeoutMs !== undefined
68
84
  ? { per_url_timeout_ms: opts.perUrlTimeoutMs }
69
85
  : {}),
86
+ ...(opts.ifNoneMatch !== undefined ? { if_none_match: opts.ifNoneMatch } : {}),
87
+ ...(opts.ifModifiedSince !== undefined
88
+ ? { if_modified_since: opts.ifModifiedSince }
89
+ : {}),
90
+ ...(opts.includeEtagAndLastModified !== undefined
91
+ ? { include_etag_and_last_modified: opts.includeEtagAndLastModified }
92
+ : {}),
70
93
  }, apiKey);
71
94
  if (opts.pretty) {
72
95
  printPrettyFetch(response);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiny-fish/cli",
3
- "version": "0.1.8-next.72",
3
+ "version": "0.2.0-next.77",
4
4
  "description": "TinyFish CLI — run web automations from your terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,7 +32,7 @@
32
32
  "prepublishOnly": "npm run build"
33
33
  },
34
34
  "dependencies": {
35
- "@tiny-fish/sdk": "^0.0.7",
35
+ "@tiny-fish/sdk": "^0.0.11",
36
36
  "chrome-cookies-secure": "^3.0.2",
37
37
  "commander": "^12.0.0",
38
38
  "globals": "^17.4.0",