stophy 1.4.2 → 1.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/dist/index.cjs CHANGED
@@ -106,9 +106,6 @@ var Surface = class {
106
106
  }
107
107
  };
108
108
 
109
- // package.json
110
- var version = "1.4.2";
111
-
112
109
  // src/errors.ts
113
110
  var StophyError = class extends Error {
114
111
  code;
@@ -129,6 +126,9 @@ var StophyError = class extends Error {
129
126
  }
130
127
  };
131
128
 
129
+ // package.json
130
+ var version = "1.5.0";
131
+
132
132
  // src/json.ts
133
133
  function tagOf(value) {
134
134
  return Object.prototype.toString.call(value);
@@ -302,17 +302,12 @@ async function send2(baseFetch, url, init, signal, retry, plan) {
302
302
  }
303
303
  }
304
304
  }
305
- function withDeadline(signal, timeoutMs) {
305
+ function withDeadline(signal, timeoutMs, reason = () => new DOMException(`Stophy request timed out after ${timeoutMs} ms`, "TimeoutError")) {
306
306
  const controller = new AbortController();
307
307
  const abort = () => controller.abort(signal?.reason);
308
308
  if (signal?.aborted) abort();
309
309
  else signal?.addEventListener("abort", abort, { once: true });
310
- const timer = setTimeout(
311
- () => controller.abort(
312
- new DOMException(`Stophy request timed out after ${timeoutMs} ms`, "TimeoutError")
313
- ),
314
- timeoutMs
315
- );
310
+ const timer = setTimeout(() => controller.abort(reason()), timeoutMs);
316
311
  return {
317
312
  signal: controller.signal,
318
313
  clear: () => {
@@ -421,6 +416,73 @@ function sleep(ms, signal) {
421
416
  });
422
417
  }
423
418
 
419
+ // src/results.ts
420
+ var START = "ck_start";
421
+ var ENDED = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
422
+ var DEFAULT_POLL_MS = 2e3;
423
+ var DEFAULT_TIMEOUT_MS2 = 15 * 6e4;
424
+ async function* checkpointResults(readPage, options = {}) {
425
+ const { signal, onCheckpoint } = options;
426
+ const pollMs = options.pollIntervalMs ?? DEFAULT_POLL_MS;
427
+ const deadline = performance.now() + (options.timeoutMs ?? DEFAULT_TIMEOUT_MS2);
428
+ let checkpoint = options.checkpoint ?? START;
429
+ for (; ; ) {
430
+ signal?.throwIfAborted();
431
+ const remaining = deadline - performance.now();
432
+ if (remaining <= 0) throw resultsTimeout(checkpoint);
433
+ const page = await readWithinBudget(readPage, checkpoint, remaining, signal);
434
+ if (performance.now() >= deadline) throw resultsTimeout(checkpoint);
435
+ if (page.checkpoint === void 0) {
436
+ throw new StophyError("The job's answer carried no checkpoint to resume from.", {
437
+ status: 0,
438
+ code: "checkpointMissing",
439
+ retryable: false
440
+ });
441
+ }
442
+ const results = page.data ?? [];
443
+ yield* results;
444
+ checkpoint = page.checkpoint;
445
+ onCheckpoint?.(checkpoint);
446
+ if (results.length > 0) continue;
447
+ if (ENDED.has(page.status)) return { status: page.status, checkpoint };
448
+ if (performance.now() + pollMs >= deadline) throw resultsTimeout(checkpoint);
449
+ await sleep2(pollMs, signal);
450
+ }
451
+ }
452
+ function resultsTimeout(checkpoint) {
453
+ return new StophyError("Gave up waiting for more results. Resume with the checkpoint.", {
454
+ status: 0,
455
+ code: "resultsTimeout",
456
+ retryable: true,
457
+ details: { checkpoint }
458
+ });
459
+ }
460
+ async function readWithinBudget(readPage, checkpoint, remaining, signal) {
461
+ if (remaining > 2147483647) return readPage(checkpoint, { signal });
462
+ const call = withDeadline(signal, remaining, () => resultsTimeout(checkpoint));
463
+ try {
464
+ const page = await readPage(checkpoint, { signal: call.signal });
465
+ call.signal.throwIfAborted();
466
+ return page;
467
+ } finally {
468
+ call.clear();
469
+ }
470
+ }
471
+ function sleep2(ms, signal) {
472
+ return new Promise((resolve, reject) => {
473
+ if (signal?.aborted) return reject(signal.reason);
474
+ const onAbort = () => {
475
+ clearTimeout(timer);
476
+ reject(signal?.reason);
477
+ };
478
+ const timer = setTimeout(() => {
479
+ signal?.removeEventListener("abort", onAbort);
480
+ resolve();
481
+ }, ms);
482
+ signal?.addEventListener("abort", onAbort, { once: true });
483
+ });
484
+ }
485
+
424
486
  // src/client.ts
425
487
  function env(name) {
426
488
  return globalThis.process?.env[name];
@@ -436,6 +498,18 @@ var Stophy = class extends Surface {
436
498
  });
437
499
  super(call);
438
500
  }
501
+ crawlResults(id, options) {
502
+ return checkpointResults(
503
+ (checkpoint, call) => this.crawl.status({ id, checkpoint }, call),
504
+ options
505
+ );
506
+ }
507
+ batchScrapeResults(id, options) {
508
+ return checkpointResults(
509
+ (checkpoint, call) => this.batch.scrape.status({ id, checkpoint }, call),
510
+ options
511
+ );
512
+ }
439
513
  parsed(parser, url, options, request) {
440
514
  return this.scrape({ url, formats: [{ type: "json", parser, options }] }, request);
441
515
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/bind.ts","../src/generated/surface.gen.ts","../package.json","../src/errors.ts","../src/json.ts","../src/transport.ts","../src/client.ts"],"names":["send","error"],"mappings":";;;;;AAOO,SAAS,IAAA,CAAqB,MAAc,IAAA,EAAc;AAC/D,EAAA,OAAO,CAAC,IAAA,EAAY,OAAA,KAClB,IAAA,CAAe,EAAE,QAAQ,MAAA,EAAQ,IAAA,EAAM,IAAA,EAAM,OAAA,EAAS,CAAA;AAC1D;AAEO,SAAS,YAAA,CAA6B,MAAc,IAAA,EAAc;AACvE,EAAA,OAAO,CAAC,IAAA,EAAa,OAAA,KACnB,IAAA,CAAe,EAAE,MAAA,EAAQ,MAAA,EAAQ,IAAA,EAAM,IAAA,EAAM,IAAA,IAAQ,EAAC,EAAG,SAAS,CAAA;AACtE;AAEO,SAAS,IAAA,CAAoC,MAAA,EAAgB,IAAA,EAAc,IAAA,EAAc;AAC9F,EAAA,OAAO,CAAC,KAAA,EAAc,OAAA,KACpB,IAAA,CAAe,EAAE,MAAA,EAAQ,GAAG,QAAA,CAAS,IAAA,EAAM,KAAK,CAAA,EAAG,OAAA,EAAS,CAAA;AAChE;AAEO,SAAS,YAAA,CACd,MAAA,EACA,IAAA,EACA,IAAA,EACA;AACA,EAAA,OAAO,CAAC,KAAA,EAAe,OAAA,KACrB,IAAA,CAAe,EAAE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,OAAO,CAAA;AAC5C,MAAA,OAAA,EAAQ;AAAA,IACV,GAAG,EAAE,CAAA;AACL,IAAA,MAAA,EAAQ,iBAAiB,OAAA,EAAS,OAAA,EAAS,EAAE,IAAA,EAAM,MAAM,CAAA;AAAA,EAC3D,CAAC,CAAA;AACH;;;AC1XA,SAAS,IAAI,IAAA,EAAkC;AAC7C,EAAA,OAAO,UAAA,CAAW,OAAA,EAAS,GAAA,CAAI,IAAI,CAAA;AACrC;AAEO,IAAM,MAAA,GAAN,cAAqB,OAAA,CAAQ;AAAA,EAClC,WAAA,CAAY,KAAA,GAA2B,EAAC,EAAG;AACzC,IAAA,MAAM,UAAU,KAAA,YAAiB,MAAA,GAAS,KAAA,GAAQ,EAAE,QAAQ,KAAA,EAAM;AAClE,IAAA,MAAM,MAAA,GAAS,QAAQ,MAAA,EAAQ,IAAA,MAAU,GAAA,CAAI,gBAAgB,GAAG,IAAA,EAAK;AACrE,IAAA,MAAM,OAAO,YAAA,CAAa;AAAA,MACxB,GAAG,OAAA;AAAA,MACH,MAAA;AAAA,MACA,OAAA,EAAS,OAAA,CAAQ,OAAA,IAAW,GAAA,CAAI,iBAAiB;AAAA,KAClD,CAAA;AACD,IAAA,KAAA,CAAM,IAAI,CAAA;AAAA,EACZ;AAAA,EAEA,MAAA,CACE,MAAA,EACA,GAAA,EACA,OAAA,EACA,OAAA,EACyB;AACzB,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,EAAE,GAAA,EAAK,SAAS,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAA,EAAQ,OAAA,EAAS,CAAA,IAAK,OAAO,CAAA;AAAA,EACnF;AACF","file":"index.cjs","sourcesContent":["import type { Caller, Method, Query } from \"./transport\";\n\nexport interface RequestOptions {\n signal?: AbortSignal;\n idempotencyKey?: string;\n}\n\nexport function post<Body, Response>(path: string, call: Caller) {\n return (body: Body, options?: RequestOptions): Promise<Response> =>\n call<Response>({ method: \"POST\", path, body, options });\n}\n\nexport function postOptional<Body, Response>(path: string, call: Caller) {\n return (body?: Body, options?: RequestOptions): Promise<Response> =>\n call<Response>({ method: \"POST\", path, body: body ?? {}, options });\n}\n\nexport function send<Input extends Query, Response>(method: Method, path: string, call: Caller) {\n return (input: Input, options?: RequestOptions): Promise<Response> =>\n call<Response>({ method, ...fillPath(path, input), options });\n}\n\nexport function sendOptional<Input extends Query, Response>(\n method: Method,\n path: string,\n call: Caller,\n) {\n return (input?: Input, options?: RequestOptions): Promise<Response> =>\n call<Response>({ method, ...fillPath(path, input ?? {}), options });\n}\n\nexport function sendEmpty<Response>(method: Method, path: string, call: Caller) {\n return (options?: RequestOptions): Promise<Response> => call<Response>({ method, path, options });\n}\n\nfunction fillPath(template: string, input: Query) {\n const used = new Set<string>();\n const path = template.replaceAll(/\\{(\\w+)\\}/g, (_, name: string) => {\n const value = input[name];\n if (value === undefined) throw new TypeError(`Missing ${name} for ${template}`);\n used.add(name);\n return encodeURIComponent(String(value));\n });\n const query = Object.fromEntries(Object.entries(input).filter(([key]) => !used.has(key)));\n return { path, query };\n}\n","// Generated by scripts/gen-surface.ts. Do not edit.\n\nimport { post, postOptional, send, sendEmpty, sendOptional } from \"../bind\";\nimport type {\n\tBatchScrapeCancelData,\n\tBatchScrapeCancelResponse,\n\tBatchScrapeData,\n\tBatchScrapeResponse,\n\tBatchScrapeStatusData,\n\tBatchScrapeStatusResponse,\n\tBrowserTaskData,\n\tBrowserTaskResponse,\n\tBrowserTaskStatusData,\n\tBrowserTaskStatusResponse,\n\tCrawlCancelData,\n\tCrawlCancelResponse,\n\tCrawlData,\n\tCrawlResponse,\n\tCrawlStatusData,\n\tCrawlStatusResponse,\n\tExtractData,\n\tExtractResponse,\n\tExtractResultData,\n\tExtractResultResponse,\n\tGetLimitsResponse,\n\tGetLogsData,\n\tGetLogsResponse,\n\tGetUsageResponse,\n\tListEndpointsResponse,\n\tListParsersResponse,\n\tMapData,\n\tMapResponse,\n\tParseData,\n\tParseResponse,\n\tPollSignUpData,\n\tPollSignUpResponse,\n\tRevokeKeyResponse,\n\tScrapeData,\n\tScrapeResponse,\n\tSearchData,\n\tSearchDeveloperData,\n\tSearchDeveloperResponse,\n\tSearchResponse,\n\tSignUpData,\n\tSignUpResponse,\n} from \"./types.gen\";\nimport type { Caller } from \"../transport\";\n\nfunction bindSurface(call: Caller) {\n\treturn {\n\t\textract: Object.assign(postOptional<ExtractData[\"body\"], ExtractResponse>(\"/v1/extract\", call), {\n\t\t\t\tresult: send<ExtractResultData[\"path\"], ExtractResultResponse>(\"GET\", \"/v1/extract/{id}\", call),\n\t\t\t}),\n\t\tsignup: Object.assign(postOptional<SignUpData[\"body\"], SignUpResponse>(\"/v1/signup\", call), {\n\t\t\t\tpoll: post<PollSignUpData[\"body\"], PollSignUpResponse>(\"/v1/signup/poll\", call),\n\t\t\t}),\n\t\tlimits: sendEmpty<GetLimitsResponse>(\"GET\", \"/v1/limits\", call),\n\t\tusage: sendEmpty<GetUsageResponse>(\"GET\", \"/v1/usage\", call),\n\t\tlogs: sendOptional<NonNullable<GetLogsData[\"query\"]>, GetLogsResponse>(\"GET\", \"/v1/logs\", call),\n\t\tkey: {\n\t\t\trevoke: sendEmpty<RevokeKeyResponse>(\"DELETE\", \"/v1/key\", call),\n\t\t},\n\t\tparsers: sendEmpty<ListParsersResponse>(\"GET\", \"/v1/parsers\", call),\n\t\tendpoints: sendEmpty<ListEndpointsResponse>(\"GET\", \"/v1/endpoints\", call),\n\t\tsearch: Object.assign(post<SearchData[\"body\"], SearchResponse>(\"/v1/search\", call), {\n\t\t\t\tdeveloper: post<SearchDeveloperData[\"body\"], SearchDeveloperResponse>(\"/v1/search/developer\", call),\n\t\t\t}),\n\t\tscrape: post<ScrapeData[\"body\"], ScrapeResponse>(\"/v1/scrape\", call),\n\t\tbrowser: {\n\t\t\ttask: Object.assign(post<BrowserTaskData[\"body\"], BrowserTaskResponse>(\"/v1/browser/task\", call), {\n\t\t\t\t\tstatus: post<BrowserTaskStatusData[\"body\"], BrowserTaskStatusResponse>(\"/v1/browser/task/status\", call),\n\t\t\t\t}),\n\t\t},\n\t\tparse: postOptional<ParseData[\"body\"], ParseResponse>(\"/v1/parse\", call),\n\t\tmap: post<MapData[\"body\"], MapResponse>(\"/v1/map\", call),\n\t\tcrawl: Object.assign(post<CrawlData[\"body\"], CrawlResponse>(\"/v1/crawl\", call), {\n\t\t\t\tstatus: send<CrawlStatusData[\"path\"] & NonNullable<CrawlStatusData[\"query\"]>, CrawlStatusResponse>(\"GET\", \"/v1/crawl/{id}\", call),\n\t\t\t\tcancel: send<CrawlCancelData[\"path\"] & NonNullable<CrawlCancelData[\"query\"]>, CrawlCancelResponse>(\"DELETE\", \"/v1/crawl/{id}\", call),\n\t\t\t}),\n\t\tbatch: {\n\t\t\tscrape: Object.assign(post<BatchScrapeData[\"body\"], BatchScrapeResponse>(\"/v1/batch/scrape\", call), {\n\t\t\t\t\tstatus: send<BatchScrapeStatusData[\"path\"] & NonNullable<BatchScrapeStatusData[\"query\"]>, BatchScrapeStatusResponse>(\"GET\", \"/v1/batch/scrape/{id}\", call),\n\t\t\t\t\tcancel: send<BatchScrapeCancelData[\"path\"] & NonNullable<BatchScrapeCancelData[\"query\"]>, BatchScrapeCancelResponse>(\"DELETE\", \"/v1/batch/scrape/{id}\", call),\n\t\t\t\t}),\n\t\t},\n\t};\n}\n\ntype BoundSurface = ReturnType<typeof bindSurface>;\n\nexport class Surface {\n\treadonly extract: BoundSurface[\"extract\"];\n\treadonly signup: BoundSurface[\"signup\"];\n\treadonly limits: BoundSurface[\"limits\"];\n\treadonly usage: BoundSurface[\"usage\"];\n\treadonly logs: BoundSurface[\"logs\"];\n\treadonly key: BoundSurface[\"key\"];\n\treadonly parsers: BoundSurface[\"parsers\"];\n\treadonly endpoints: BoundSurface[\"endpoints\"];\n\treadonly search: BoundSurface[\"search\"];\n\treadonly scrape: BoundSurface[\"scrape\"];\n\treadonly browser: BoundSurface[\"browser\"];\n\treadonly parse: BoundSurface[\"parse\"];\n\treadonly map: BoundSurface[\"map\"];\n\treadonly crawl: BoundSurface[\"crawl\"];\n\treadonly batch: BoundSurface[\"batch\"];\n\n\tconstructor(call: Caller) {\n\t\tconst bound = bindSurface(call);\n\t\tthis.extract = bound.extract;\n\t\tthis.signup = bound.signup;\n\t\tthis.limits = bound.limits;\n\t\tthis.usage = bound.usage;\n\t\tthis.logs = bound.logs;\n\t\tthis.key = bound.key;\n\t\tthis.parsers = bound.parsers;\n\t\tthis.endpoints = bound.endpoints;\n\t\tthis.search = bound.search;\n\t\tthis.scrape = bound.scrape;\n\t\tthis.browser = bound.browser;\n\t\tthis.parse = bound.parse;\n\t\tthis.map = bound.map;\n\t\tthis.crawl = bound.crawl;\n\t\tthis.batch = bound.batch;\n\t}\n}\n","{\n \"name\": \"stophy\",\n \"version\": \"1.4.2\",\n \"description\": \"Search, read, and act on the web. The Stophy client for TypeScript and JavaScript.\",\n \"keywords\": [\n \"ads\",\n \"ai-agents\",\n \"google-maps\",\n \"llm\",\n \"maps\",\n \"reddit\",\n \"scraping\",\n \"sdk\",\n \"stophy\",\n \"transcripts\",\n \"web-data\",\n \"web-search\",\n \"youtube\"\n ],\n \"homepage\": \"https://stophy.dev\",\n \"license\": \"MIT\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/stophydotdev/stophy.git\",\n \"directory\": \"sdk/packages/typescript\"\n },\n \"files\": [\n \"dist\"\n ],\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n }\n },\n \"scripts\": {\n \"generate\": \"openapi-ts && bun ../../scripts/gen-surface.ts\",\n \"build\": \"tsup\",\n \"test\": \"bun test ../../test/typescript\",\n \"check-types\": \"tsc --noEmit && tsc --noEmit -p tsconfig.tests.json\",\n \"prepublishOnly\": \"bun run generate && bun run build\"\n },\n \"devDependencies\": {\n \"@hey-api/client-fetch\": \"^0.10.2\",\n \"@hey-api/openapi-ts\": \"^0.64.0\",\n \"@types/bun\": \"^1.1.14\",\n \"prettier\": \"2.8.8\",\n \"tsup\": \"^8.3.5\",\n \"typescript\": \"^5.7.0\"\n }\n}\n","import type { _Error } from \"./generated/types.gen\";\nimport type { JsonValue } from \"./json\";\n\nexport type StophyErrorCode = _Error[\"code\"];\n\nexport class StophyError extends Error {\n readonly code?: string;\n readonly retryable: boolean;\n readonly retryAfterSeconds?: number;\n readonly status: number;\n readonly requestId?: string;\n readonly details: Record<string, JsonValue>;\n declare readonly outcomeUnknown?: true;\n\n constructor(\n message: string,\n options: {\n status: number;\n code?: string;\n retryable: boolean;\n retryAfterSeconds?: number;\n requestId?: string;\n details?: Record<string, JsonValue>;\n },\n ) {\n super(message);\n this.name = \"StophyError\";\n this.status = options.status;\n this.code = options.code;\n this.retryable = options.retryable;\n this.retryAfterSeconds = options.retryAfterSeconds;\n this.requestId = options.requestId;\n this.details = options.details ?? {};\n }\n}\n","export type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;\n\nexport interface JsonObject {\n [key: string]: JsonValue;\n}\n\ntype MaybeJson = JsonValue | undefined;\n\nfunction tagOf(value: MaybeJson): string {\n return Object.prototype.toString.call(value);\n}\n\nexport function isString(value: MaybeJson): value is string {\n return tagOf(value) === \"[object String]\";\n}\n\nexport function isNumber(value: MaybeJson): value is number {\n return tagOf(value) === \"[object Number]\";\n}\n\nexport function isBoolean(value: MaybeJson): value is boolean {\n return value === true || value === false;\n}\n\nexport function isRecord(value: MaybeJson): value is JsonObject {\n return tagOf(value) === \"[object Object]\";\n}\n","import { version } from \"../package.json\";\nimport { StophyError } from \"./errors\";\nimport { isBoolean, isNumber, isRecord, isString, type JsonValue } from \"./json\";\n\nconst DEFAULT_BASE_URL = \"https://api.stophy.dev\";\nconst DEFAULT_TIMEOUT_MS = 70_000;\nconst MAX_RETRY_WAIT_SECONDS = 60;\nconst RETRYABLE_STATUS = new Set([429, 500, 502, 503, 504]);\nconst JOB_STARTS = new Set([\"/v1/agent\", \"/v1/batch/scrape\", \"/v1/crawl\"]);\nconst BROWSER_TASK_STATUS = \"/v1/browser/task/status\";\nconst KEYLESS_READS = new Set([\"/v1/map\", \"/v1/parse\", \"/v1/scrape\", \"/v1/search\"]);\nconst KEYED_POSTS = new Set([\n ...JOB_STARTS,\n ...KEYLESS_READS,\n BROWSER_TASK_STATUS,\n \"/v1/browser/task\",\n \"/v1/extract\",\n]);\nconst USER_AGENT = `stophy-typescript/${version}`;\n\nexport interface CallOptions {\n signal?: AbortSignal;\n idempotencyKey?: string;\n}\n\nexport type Method = \"GET\" | \"POST\" | \"DELETE\";\n\nexport type Query = Record<string, string | number | undefined>;\n\nexport interface RequestSpec {\n method: Method;\n path: string;\n body?: unknown;\n query?: Query;\n options?: CallOptions;\n}\n\nexport type Caller = <Result>(spec: RequestSpec) => Promise<Result>;\n\nexport type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;\n\nexport interface TransportOptions {\n apiKey?: string;\n baseUrl?: string;\n fetch?: FetchLike;\n headers?: Record<string, string>;\n maxRetries?: number;\n retryInitialDelayMs?: number;\n timeoutMs?: number;\n}\n\nexport function createCaller(options: TransportOptions): Caller {\n const baseFetch: FetchLike = options.fetch ?? globalThis.fetch;\n const baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, \"\");\n const retry: RetryPolicy = {\n maxRetries: options.maxRetries ?? 2,\n initialDelayMs: options.retryInitialDelayMs ?? 500,\n timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n };\n\n return async <Result>(spec: RequestSpec): Promise<Result> => {\n const headers = new Headers(options.headers);\n if (!(\"document\" in globalThis) && !headers.has(\"user-agent\")) {\n headers.set(\"user-agent\", USER_AGENT);\n }\n if (options.apiKey) {\n headers.set(\"authorization\", `Bearer ${options.apiKey}`);\n }\n headers.set(\"accept\", \"application/json\");\n if (spec.body !== undefined) headers.set(\"content-type\", \"application/json\");\n const hasApiKey = headers.has(\"authorization\");\n const keyed = spec.method === \"POST\" && hasApiKey && KEYED_POSTS.has(spec.path);\n const key =\n spec.method === \"POST\"\n ? (spec.options?.idempotencyKey ??\n headers.get(\"idempotency-key\") ??\n (keyed ? crypto.randomUUID() : undefined))\n : undefined;\n if (key !== undefined) headers.set(\"idempotency-key\", key);\n\n const body = spec.body === undefined ? undefined : JSON.stringify(spec.body);\n const protectedKey = keyed && answerIsKept(spec.path, parseJson(body ?? \"\")) ? key : undefined;\n\n const url = withQuery(`${baseUrl}${spec.path}`, spec.query);\n return send<Result>(\n baseFetch,\n url,\n (signal) => ({\n method: spec.method,\n headers,\n body,\n signal,\n }),\n spec.options?.signal,\n spec.method === \"DELETE\" ? { ...retry, maxRetries: 0 } : retry,\n {\n key: protectedKey,\n hasApiKey,\n path: spec.path,\n replayable:\n spec.method !== \"POST\" ||\n spec.path === BROWSER_TASK_STATUS ||\n (!hasApiKey && KEYLESS_READS.has(spec.path)) ||\n protectedKey !== undefined,\n },\n );\n };\n}\n\ninterface RetryPolicy {\n maxRetries: number;\n initialDelayMs: number;\n timeoutMs: number;\n}\n\ninterface CallPlan {\n key: string | undefined;\n hasApiKey: boolean;\n path: string;\n replayable: boolean;\n}\n\nfunction answerIsKept(path: string, body: JsonValue): boolean {\n if (JOB_STARTS.has(path) || !isRecord(body)) return true;\n return ![body, body.scrapeOptions, body.options].some(\n (part) => isRecord(part) && part.zeroDataRetention === true,\n );\n}\n\ninterface NetworkError extends Error {\n code?: string;\n cause?: { code?: string };\n}\n\nconst NEVER_SENT = new Set([\n \"ECONNREFUSED\",\n \"ENOTFOUND\",\n \"EAI_AGAIN\",\n \"ENETUNREACH\",\n \"EHOSTUNREACH\",\n \"UND_ERR_CONNECT_TIMEOUT\",\n]);\n\nconst requestMayHaveLeft = (error: NetworkError) =>\n !NEVER_SENT.has(error.code ?? error.cause?.code ?? \"\");\n\nconst mayHaveRun = (error: StophyError) =>\n error.status === 408 || (error.status >= 500 && error.code !== \"busy\");\n\nconst SEND_AGAIN =\n \"Check before you send it again as a new call, or send it again with the same Idempotency-Key in details.idempotencyKey.\";\n\nfunction mayStillComplete(error: StophyError, key: string): StophyError {\n return Object.assign(\n new StophyError(`${error.message} An earlier send may still complete. ${SEND_AGAIN}`, {\n status: error.status,\n code: error.code,\n retryable: error.retryable,\n retryAfterSeconds: error.retryAfterSeconds,\n requestId: error.requestId,\n details: { ...error.details, idempotencyKey: key },\n }),\n { outcomeUnknown: true },\n );\n}\n\nfunction abortReason(signal: AbortSignal, key: string | undefined) {\n const reason: unknown = signal.reason;\n if (key === undefined) return reason;\n const error = new Error(reason instanceof Error ? reason.message : \"Stophy request cancelled\", {\n cause: reason,\n });\n if (reason instanceof Error) error.name = reason.name;\n return Object.assign(error, { idempotencyKey: key, outcomeUnknown: true });\n}\n\nasync function send<Result>(\n baseFetch: FetchLike,\n url: string,\n init: (signal: AbortSignal) => RequestInit,\n signal: AbortSignal | undefined,\n retry: RetryPolicy,\n plan: CallPlan,\n): Promise<Result> {\n let earlierSendLost = false;\n const failWith = (error: StophyError) =>\n plan.key !== undefined && earlierSendLost ? mayStillComplete(error, plan.key) : error;\n for (let n = 0; ; n += 1) {\n if (signal?.aborted) throw abortReason(signal, earlierSendLost ? plan.key : undefined);\n const deadline = withDeadline(signal, retry.timeoutMs);\n let waitMs: number;\n try {\n const answer = await baseFetch(url, init(deadline.signal))\n .then(async (response) => ({ response, text: await response.text() }))\n .catch((error: NetworkError) => {\n if (signal?.aborted) {\n earlierSendLost ||= !(error instanceof Error) || requestMayHaveLeft(error);\n throw abortReason(signal, earlierSendLost ? plan.key : undefined);\n }\n const mayHaveLeft = requestMayHaveLeft(error);\n if (mayHaveLeft && !plan.replayable) throw Object.assign(error, { outcomeUnknown: true });\n if (error.name === \"TimeoutError\" && !plan.hasApiKey) throw error;\n if (n >= retry.maxRetries) {\n throw (mayHaveLeft || earlierSendLost) && plan.key !== undefined\n ? Object.assign(error, { idempotencyKey: plan.key, outcomeUnknown: true })\n : error;\n }\n earlierSendLost ||= mayHaveLeft;\n return undefined;\n });\n if (answer === undefined) {\n waitMs = backoffMs(n, retry.initialDelayMs);\n } else {\n const { response, text } = answer;\n if (response.ok) {\n try {\n return readBody<Result>(response, text);\n } catch (error) {\n if (!(error instanceof StophyError)) throw error;\n earlierSendLost = true;\n throw !plan.replayable\n ? Object.assign(error, { outcomeUnknown: true })\n : failWith(error);\n }\n }\n const error = errorFrom(response, text);\n earlierSendLost ||= error.code === undefined && mayHaveRun(error);\n const definiteScrapeFailure =\n plan.path === \"/v1/scrape\" &&\n ((error.status === 504 && error.code === \"sourceTimeout\") ||\n (error.status === 503 && error.code === \"sourceUnavailable\"));\n if (!plan.replayable && mayHaveRun(error) && !definiteScrapeFailure) {\n throw Object.assign(error, { outcomeUnknown: true });\n }\n const seconds = error.retryAfterSeconds;\n if (!error.retryable || n >= retry.maxRetries) throw failWith(error);\n if (seconds !== undefined && seconds > MAX_RETRY_WAIT_SECONDS) throw failWith(error);\n waitMs = seconds === undefined ? backoffMs(n, retry.initialDelayMs) : seconds * 1000;\n }\n } finally {\n deadline.clear();\n }\n try {\n await sleep(waitMs, signal);\n } catch (error) {\n throw signal?.aborted ? abortReason(signal, earlierSendLost ? plan.key : undefined) : error;\n }\n }\n}\n\nfunction withDeadline(signal: AbortSignal | undefined, timeoutMs: number) {\n const controller = new AbortController();\n const abort = () => controller.abort(signal?.reason);\n if (signal?.aborted) abort();\n else signal?.addEventListener(\"abort\", abort, { once: true });\n const timer = setTimeout(\n () =>\n controller.abort(\n new DOMException(`Stophy request timed out after ${timeoutMs} ms`, \"TimeoutError\"),\n ),\n timeoutMs,\n );\n return {\n signal: controller.signal,\n clear: () => {\n clearTimeout(timer);\n signal?.removeEventListener(\"abort\", abort);\n },\n };\n}\n\nfunction readBody<Result>(response: Response, text: string): Result {\n if (!text) {\n throw failed(response, \"Stophy returned an empty response\", {});\n }\n try {\n return JSON.parse(text);\n } catch {\n throw failed(response, \"Stophy returned a non-JSON response\", {});\n }\n}\n\nfunction errorFrom(response: Response, text: string): StophyError {\n const error = readError(text ? parseJson(text) : null);\n return failed(response, error.message ?? `Stophy request failed with status ${response.status}`, {\n code: error.code,\n retryable: error.retryable ?? RETRYABLE_STATUS.has(response.status),\n retryAfterSeconds: error.retryAfterSeconds ?? headerRetryAfter(response),\n requestId: error.requestId ?? headerRequestId(response),\n details: error.details,\n });\n}\n\nfunction failed(\n response: Response,\n message: string,\n options: {\n code?: string;\n retryable?: boolean;\n retryAfterSeconds?: number;\n requestId?: string;\n details?: Record<string, JsonValue>;\n },\n): StophyError {\n return new StophyError(message, {\n status: response.status,\n code: options.code,\n retryable: options.retryable ?? false,\n retryAfterSeconds: options.retryAfterSeconds,\n requestId: options.requestId ?? headerRequestId(response),\n details: options.details,\n });\n}\n\ninterface ErrorFields {\n code?: string;\n message?: string;\n retryable?: boolean;\n retryAfterSeconds?: number;\n requestId?: string;\n details?: Record<string, JsonValue>;\n}\n\nfunction parseJson(text: string): JsonValue {\n try {\n return JSON.parse(text);\n } catch {\n return null;\n }\n}\n\nconst ENVELOPE_FIELDS = new Set([\n \"success\",\n \"error\",\n \"message\",\n \"code\",\n \"retryable\",\n \"retryAfterSeconds\",\n \"requestId\",\n]);\n\nfunction readError(body: JsonValue): ErrorFields {\n if (!isRecord(body)) return {};\n const fields = isRecord(body.error) ? body.error : body;\n return {\n code: isString(fields.code) ? fields.code : undefined,\n message: isString(fields.error)\n ? fields.error\n : isString(fields.message)\n ? fields.message\n : undefined,\n retryable: isBoolean(fields.retryable) ? fields.retryable : undefined,\n retryAfterSeconds: isNumber(fields.retryAfterSeconds) ? fields.retryAfterSeconds : undefined,\n requestId: isString(fields.requestId) ? fields.requestId : undefined,\n details: Object.fromEntries(\n Object.entries(fields).filter(([key]) => !ENVELOPE_FIELDS.has(key)),\n ),\n };\n}\n\nfunction headerRequestId(response: Response): string | undefined {\n return response.headers.get(\"x-request-id\") ?? undefined;\n}\n\nfunction headerRetryAfter(response: Response): number | undefined {\n const header = response.headers.get(\"retry-after\");\n if (!header) return undefined;\n const seconds = Number(header);\n if (Number.isFinite(seconds)) return seconds;\n const date = Date.parse(header);\n if (Number.isNaN(date)) return undefined;\n return Math.max(0, Math.ceil((date - Date.now()) / 1000));\n}\n\nfunction withQuery(url: string, query: Query | undefined): string {\n if (!query) return url;\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined) params.set(key, String(value));\n }\n const text = params.toString();\n return text ? `${url}?${text}` : url;\n}\n\nfunction backoffMs(attempt: number, base: number): number {\n const window = base * 2 ** attempt;\n return window / 2 + Math.random() * (window / 2);\n}\n\nfunction sleep(ms: number, signal: AbortSignal | undefined): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) return reject(signal.reason);\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal?.reason);\n };\n const timer = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n","import type { RequestOptions } from \"./bind\";\nimport type { ParserName } from \"./generated/parsers.gen\";\nimport { Surface } from \"./generated/surface.gen\";\nimport type { ScrapeData, ScrapeResponse } from \"./generated/types.gen\";\nimport { type CallOptions, createCaller, type FetchLike } from \"./transport\";\n\nexport interface StophyOptions {\n apiKey?: string;\n baseUrl?: string;\n fetch?: FetchLike;\n headers?: Record<string, string>;\n maxRetries?: number;\n retryInitialDelayMs?: number;\n timeoutMs?: number;\n}\n\nexport type { CallOptions, FetchLike };\n\nexport type StophyClientInput = StophyOptions | string;\n\ntype JsonFormat = Extract<NonNullable<ScrapeData[\"body\"][\"formats\"]>[number], { type: \"json\" }>;\n\nexport type ParserOptions = NonNullable<JsonFormat[\"options\"]>;\n\nfunction env(name: string): string | undefined {\n return globalThis.process?.env[name];\n}\n\nexport class Stophy extends Surface {\n constructor(input: StophyClientInput = {}) {\n const options = input instanceof Object ? input : { apiKey: input };\n const apiKey = options.apiKey?.trim() || env(\"STOPHY_API_KEY\")?.trim();\n const call = createCaller({\n ...options,\n apiKey,\n baseUrl: options.baseUrl ?? env(\"STOPHY_BASE_URL\"),\n });\n super(call);\n }\n\n parsed(\n parser: ParserName,\n url: string,\n options?: ParserOptions,\n request?: RequestOptions,\n ): Promise<ScrapeResponse> {\n return this.scrape({ url, formats: [{ type: \"json\", parser, options }] }, request);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/bind.ts","../src/generated/surface.gen.ts","../src/errors.ts","../package.json","../src/json.ts","../src/transport.ts","../src/results.ts","../src/client.ts"],"names":["send","error","DEFAULT_TIMEOUT_MS","sleep"],"mappings":";;;;;AAOO,SAAS,IAAA,CAAqB,MAAc,IAAA,EAAc;AAC/D,EAAA,OAAO,CAAC,IAAA,EAAY,OAAA,KAClB,IAAA,CAAe,EAAE,QAAQ,MAAA,EAAQ,IAAA,EAAM,IAAA,EAAM,OAAA,EAAS,CAAA;AAC1D;AAEO,SAAS,YAAA,CAA6B,MAAc,IAAA,EAAc;AACvE,EAAA,OAAO,CAAC,IAAA,EAAa,OAAA,KACnB,IAAA,CAAe,EAAE,MAAA,EAAQ,MAAA,EAAQ,IAAA,EAAM,IAAA,EAAM,IAAA,IAAQ,EAAC,EAAG,SAAS,CAAA;AACtE;AAEO,SAAS,IAAA,CAAoC,MAAA,EAAgB,IAAA,EAAc,IAAA,EAAc;AAC9F,EAAA,OAAO,CAAC,KAAA,EAAc,OAAA,KACpB,IAAA,CAAe,EAAE,MAAA,EAAQ,GAAG,QAAA,CAAS,IAAA,EAAM,KAAK,CAAA,EAAG,OAAA,EAAS,CAAA;AAChE;AAEO,SAAS,YAAA,CACd,MAAA,EACA,IAAA,EACA,IAAA,EACA;AACA,EAAA,OAAO,CAAC,KAAA,EAAe,OAAA,KACrB,IAAA,CAAe,EAAE,MAAA,EAAQ,GAAG,QAAA,CAAS,IAAA,EAAM,KAAA,IAAS,EAAE,CAA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;AAC9E,IAAA,OAAO,iBAAA;AAAA,MACL,CAAC,UAAA,EAAY,IAAA,KAAS,IAAA,CAAK,KAAA,CAAM,OAAO,EAAE,EAAA,EAAI,UAAA,EAAW,EAAG,IAAI,CAAA;AAAA,MAChE;AAAA,KACF;AAAA,EACF;AAAA,EAEA,kBAAA,CACE,IACA,OAAA,EACoF;AACpF,IAAA,OAAO,iBAAA;AAAA,MACL,CAAC,UAAA,EAAY,IAAA,KAAS,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,MAAA,CAAO,EAAE,EAAA,EAAI,UAAA,EAAW,EAAG,IAAI,CAAA;AAAA,MACvE;AAAA,KACF;AAAA,EACF;AAAA,EAEA,MAAA,CACE,MAAA,EACA,GAAA,EACA,OAAA,EACA,OAAA,EACyB;AACzB,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,EAAE,GAAA,EAAK,SAAS,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAA,EAAQ,OAAA,EAAS,CAAA,IAAK,OAAO,CAAA;AAAA,EACnF;AACF","file":"index.cjs","sourcesContent":["import type { Caller, Method, Query } from \"./transport\";\n\nexport interface RequestOptions {\n signal?: AbortSignal;\n idempotencyKey?: string;\n}\n\nexport function post<Body, Response>(path: string, call: Caller) {\n return (body: Body, options?: RequestOptions): Promise<Response> =>\n call<Response>({ method: \"POST\", path, body, options });\n}\n\nexport function postOptional<Body, Response>(path: string, call: Caller) {\n return (body?: Body, options?: RequestOptions): Promise<Response> =>\n call<Response>({ method: \"POST\", path, body: body ?? {}, options });\n}\n\nexport function send<Input extends Query, Response>(method: Method, path: string, call: Caller) {\n return (input: Input, options?: RequestOptions): Promise<Response> =>\n call<Response>({ method, ...fillPath(path, input), options });\n}\n\nexport function sendOptional<Input extends Query, Response>(\n method: Method,\n path: string,\n call: Caller,\n) {\n return (input?: Input, options?: RequestOptions): Promise<Response> =>\n call<Response>({ method, ...fillPath(path, input ?? {}), options });\n}\n\nexport function sendEmpty<Response>(method: Method, path: string, call: Caller) {\n return (options?: RequestOptions): Promise<Response> => call<Response>({ method, path, options });\n}\n\nfunction fillPath(template: string, input: Query) {\n const used = new Set<string>();\n const path = template.replaceAll(/\\{(\\w+)\\}/g, (_, name: string) => {\n const value = input[name];\n if (value === undefined) throw new TypeError(`Missing ${name} for ${template}`);\n used.add(name);\n return encodeURIComponent(String(value));\n });\n const query = Object.fromEntries(Object.entries(input).filter(([key]) => !used.has(key)));\n return { path, query };\n}\n","// Generated by scripts/gen-surface.ts. Do not edit.\n\nimport { post, postOptional, send, sendEmpty, sendOptional } from \"../bind\";\nimport type {\n\tBatchScrapeCancelData,\n\tBatchScrapeCancelResponse,\n\tBatchScrapeData,\n\tBatchScrapeResponse,\n\tBatchScrapeStatusData,\n\tBatchScrapeStatusResponse,\n\tBrowserTaskData,\n\tBrowserTaskResponse,\n\tBrowserTaskStatusData,\n\tBrowserTaskStatusResponse,\n\tCrawlCancelData,\n\tCrawlCancelResponse,\n\tCrawlData,\n\tCrawlResponse,\n\tCrawlStatusData,\n\tCrawlStatusResponse,\n\tExtractData,\n\tExtractResponse,\n\tExtractResultData,\n\tExtractResultResponse,\n\tGetLimitsResponse,\n\tGetLogsData,\n\tGetLogsResponse,\n\tGetUsageResponse,\n\tListEndpointsResponse,\n\tListParsersResponse,\n\tMapData,\n\tMapResponse,\n\tParseData,\n\tParseResponse,\n\tPollSignUpData,\n\tPollSignUpResponse,\n\tRevokeKeyResponse,\n\tScrapeData,\n\tScrapeResponse,\n\tSearchData,\n\tSearchDeveloperData,\n\tSearchDeveloperResponse,\n\tSearchResponse,\n\tSignUpData,\n\tSignUpResponse,\n} from \"./types.gen\";\nimport type { Caller } from \"../transport\";\n\nfunction bindSurface(call: Caller) {\n\treturn {\n\t\textract: Object.assign(postOptional<ExtractData[\"body\"], ExtractResponse>(\"/v1/extract\", call), {\n\t\t\t\tresult: send<ExtractResultData[\"path\"], ExtractResultResponse>(\"GET\", \"/v1/extract/{id}\", call),\n\t\t\t}),\n\t\tsignup: Object.assign(postOptional<SignUpData[\"body\"], SignUpResponse>(\"/v1/signup\", call), {\n\t\t\t\tpoll: post<PollSignUpData[\"body\"], PollSignUpResponse>(\"/v1/signup/poll\", call),\n\t\t\t}),\n\t\tlimits: sendEmpty<GetLimitsResponse>(\"GET\", \"/v1/limits\", call),\n\t\tusage: sendEmpty<GetUsageResponse>(\"GET\", \"/v1/usage\", call),\n\t\tlogs: sendOptional<NonNullable<GetLogsData[\"query\"]>, GetLogsResponse>(\"GET\", \"/v1/logs\", call),\n\t\tkey: {\n\t\t\trevoke: sendEmpty<RevokeKeyResponse>(\"DELETE\", \"/v1/key\", call),\n\t\t},\n\t\tparsers: sendEmpty<ListParsersResponse>(\"GET\", \"/v1/parsers\", call),\n\t\tendpoints: sendEmpty<ListEndpointsResponse>(\"GET\", \"/v1/endpoints\", call),\n\t\tsearch: Object.assign(post<SearchData[\"body\"], SearchResponse>(\"/v1/search\", call), {\n\t\t\t\tdeveloper: post<SearchDeveloperData[\"body\"], SearchDeveloperResponse>(\"/v1/search/developer\", call),\n\t\t\t}),\n\t\tscrape: post<ScrapeData[\"body\"], ScrapeResponse>(\"/v1/scrape\", call),\n\t\tbrowser: {\n\t\t\ttask: Object.assign(post<BrowserTaskData[\"body\"], BrowserTaskResponse>(\"/v1/browser/task\", call), {\n\t\t\t\t\tstatus: post<BrowserTaskStatusData[\"body\"], BrowserTaskStatusResponse>(\"/v1/browser/task/status\", call),\n\t\t\t\t}),\n\t\t},\n\t\tparse: postOptional<ParseData[\"body\"], ParseResponse>(\"/v1/parse\", call),\n\t\tmap: post<MapData[\"body\"], MapResponse>(\"/v1/map\", call),\n\t\tcrawl: Object.assign(post<CrawlData[\"body\"], CrawlResponse>(\"/v1/crawl\", call), {\n\t\t\t\tstatus: send<CrawlStatusData[\"path\"] & NonNullable<CrawlStatusData[\"query\"]>, CrawlStatusResponse>(\"GET\", \"/v1/crawl/{id}\", call),\n\t\t\t\tcancel: send<CrawlCancelData[\"path\"] & NonNullable<CrawlCancelData[\"query\"]>, CrawlCancelResponse>(\"DELETE\", \"/v1/crawl/{id}\", call),\n\t\t\t}),\n\t\tbatch: {\n\t\t\tscrape: Object.assign(post<BatchScrapeData[\"body\"], BatchScrapeResponse>(\"/v1/batch/scrape\", call), {\n\t\t\t\t\tstatus: send<BatchScrapeStatusData[\"path\"] & NonNullable<BatchScrapeStatusData[\"query\"]>, BatchScrapeStatusResponse>(\"GET\", \"/v1/batch/scrape/{id}\", call),\n\t\t\t\t\tcancel: send<BatchScrapeCancelData[\"path\"] & NonNullable<BatchScrapeCancelData[\"query\"]>, BatchScrapeCancelResponse>(\"DELETE\", \"/v1/batch/scrape/{id}\", call),\n\t\t\t\t}),\n\t\t},\n\t};\n}\n\ntype BoundSurface = ReturnType<typeof bindSurface>;\n\nexport class Surface {\n\treadonly extract: BoundSurface[\"extract\"];\n\treadonly signup: BoundSurface[\"signup\"];\n\treadonly limits: BoundSurface[\"limits\"];\n\treadonly usage: BoundSurface[\"usage\"];\n\treadonly logs: BoundSurface[\"logs\"];\n\treadonly key: BoundSurface[\"key\"];\n\treadonly parsers: BoundSurface[\"parsers\"];\n\treadonly endpoints: BoundSurface[\"endpoints\"];\n\treadonly search: BoundSurface[\"search\"];\n\treadonly scrape: BoundSurface[\"scrape\"];\n\treadonly browser: BoundSurface[\"browser\"];\n\treadonly parse: BoundSurface[\"parse\"];\n\treadonly map: BoundSurface[\"map\"];\n\treadonly crawl: BoundSurface[\"crawl\"];\n\treadonly batch: BoundSurface[\"batch\"];\n\n\tconstructor(call: Caller) {\n\t\tconst bound = bindSurface(call);\n\t\tthis.extract = bound.extract;\n\t\tthis.signup = bound.signup;\n\t\tthis.limits = bound.limits;\n\t\tthis.usage = bound.usage;\n\t\tthis.logs = bound.logs;\n\t\tthis.key = bound.key;\n\t\tthis.parsers = bound.parsers;\n\t\tthis.endpoints = bound.endpoints;\n\t\tthis.search = bound.search;\n\t\tthis.scrape = bound.scrape;\n\t\tthis.browser = bound.browser;\n\t\tthis.parse = bound.parse;\n\t\tthis.map = bound.map;\n\t\tthis.crawl = bound.crawl;\n\t\tthis.batch = bound.batch;\n\t}\n}\n","import type { _Error } from \"./generated/types.gen\";\nimport type { JsonValue } from \"./json\";\n\nexport type StophyErrorCode = _Error[\"code\"];\n\nexport class StophyError extends Error {\n readonly code?: string;\n readonly retryable: boolean;\n readonly retryAfterSeconds?: number;\n readonly status: number;\n readonly requestId?: string;\n readonly details: Record<string, JsonValue>;\n declare readonly outcomeUnknown?: true;\n\n constructor(\n message: string,\n options: {\n status: number;\n code?: string;\n retryable: boolean;\n retryAfterSeconds?: number;\n requestId?: string;\n details?: Record<string, JsonValue>;\n },\n ) {\n super(message);\n this.name = \"StophyError\";\n this.status = options.status;\n this.code = options.code;\n this.retryable = options.retryable;\n this.retryAfterSeconds = options.retryAfterSeconds;\n this.requestId = options.requestId;\n this.details = options.details ?? {};\n }\n}\n","{\n \"name\": \"stophy\",\n \"version\": \"1.5.0\",\n \"description\": \"Search, read, and act on the web. The Stophy client for TypeScript and JavaScript.\",\n \"keywords\": [\n \"ads\",\n \"ai-agents\",\n \"google-maps\",\n \"llm\",\n \"maps\",\n \"reddit\",\n \"scraping\",\n \"sdk\",\n \"stophy\",\n \"transcripts\",\n \"web-data\",\n \"web-search\",\n \"youtube\"\n ],\n \"homepage\": \"https://stophy.dev\",\n \"license\": \"MIT\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/stophydotdev/stophy.git\",\n \"directory\": \"sdk/packages/typescript\"\n },\n \"files\": [\n \"dist\"\n ],\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n }\n },\n \"scripts\": {\n \"generate\": \"openapi-ts && bun ../../scripts/gen-surface.ts\",\n \"build\": \"tsup\",\n \"test\": \"bun test ../../test/typescript\",\n \"check-types\": \"tsc --noEmit && tsc --noEmit -p tsconfig.tests.json\",\n \"prepublishOnly\": \"bun run generate && bun run build\"\n },\n \"devDependencies\": {\n \"@hey-api/client-fetch\": \"^0.10.2\",\n \"@hey-api/openapi-ts\": \"^0.64.0\",\n \"@types/bun\": \"^1.1.14\",\n \"prettier\": \"2.8.8\",\n \"tsup\": \"^8.3.5\",\n \"typescript\": \"^5.7.0\"\n }\n}\n","export type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;\n\nexport interface JsonObject {\n [key: string]: JsonValue;\n}\n\ntype MaybeJson = JsonValue | undefined;\n\nfunction tagOf(value: MaybeJson): string {\n return Object.prototype.toString.call(value);\n}\n\nexport function isString(value: MaybeJson): value is string {\n return tagOf(value) === \"[object String]\";\n}\n\nexport function isNumber(value: MaybeJson): value is number {\n return tagOf(value) === \"[object Number]\";\n}\n\nexport function isBoolean(value: MaybeJson): value is boolean {\n return value === true || value === false;\n}\n\nexport function isRecord(value: MaybeJson): value is JsonObject {\n return tagOf(value) === \"[object Object]\";\n}\n","import { version } from \"../package.json\";\nimport { StophyError } from \"./errors\";\nimport { isBoolean, isNumber, isRecord, isString, type JsonValue } from \"./json\";\n\nconst DEFAULT_BASE_URL = \"https://api.stophy.dev\";\nconst DEFAULT_TIMEOUT_MS = 70_000;\nconst MAX_RETRY_WAIT_SECONDS = 60;\nconst RETRYABLE_STATUS = new Set([429, 500, 502, 503, 504]);\nconst JOB_STARTS = new Set([\"/v1/agent\", \"/v1/batch/scrape\", \"/v1/crawl\"]);\nconst BROWSER_TASK_STATUS = \"/v1/browser/task/status\";\nconst KEYLESS_READS = new Set([\"/v1/map\", \"/v1/parse\", \"/v1/scrape\", \"/v1/search\"]);\nconst KEYED_POSTS = new Set([\n ...JOB_STARTS,\n ...KEYLESS_READS,\n BROWSER_TASK_STATUS,\n \"/v1/browser/task\",\n \"/v1/extract\",\n]);\nconst USER_AGENT = `stophy-typescript/${version}`;\n\nexport interface CallOptions {\n signal?: AbortSignal;\n idempotencyKey?: string;\n}\n\nexport type Method = \"GET\" | \"POST\" | \"DELETE\";\n\nexport type Query = Record<string, string | number | undefined>;\n\nexport interface RequestSpec {\n method: Method;\n path: string;\n body?: unknown;\n query?: Query;\n options?: CallOptions;\n}\n\nexport type Caller = <Result>(spec: RequestSpec) => Promise<Result>;\n\nexport type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;\n\nexport interface TransportOptions {\n apiKey?: string;\n baseUrl?: string;\n fetch?: FetchLike;\n headers?: Record<string, string>;\n maxRetries?: number;\n retryInitialDelayMs?: number;\n timeoutMs?: number;\n}\n\nexport function createCaller(options: TransportOptions): Caller {\n const baseFetch: FetchLike = options.fetch ?? globalThis.fetch;\n const baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, \"\");\n const retry: RetryPolicy = {\n maxRetries: options.maxRetries ?? 2,\n initialDelayMs: options.retryInitialDelayMs ?? 500,\n timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n };\n\n return async <Result>(spec: RequestSpec): Promise<Result> => {\n const headers = new Headers(options.headers);\n if (!(\"document\" in globalThis) && !headers.has(\"user-agent\")) {\n headers.set(\"user-agent\", USER_AGENT);\n }\n if (options.apiKey) {\n headers.set(\"authorization\", `Bearer ${options.apiKey}`);\n }\n headers.set(\"accept\", \"application/json\");\n if (spec.body !== undefined) headers.set(\"content-type\", \"application/json\");\n const hasApiKey = headers.has(\"authorization\");\n const keyed = spec.method === \"POST\" && hasApiKey && KEYED_POSTS.has(spec.path);\n const key =\n spec.method === \"POST\"\n ? (spec.options?.idempotencyKey ??\n headers.get(\"idempotency-key\") ??\n (keyed ? crypto.randomUUID() : undefined))\n : undefined;\n if (key !== undefined) headers.set(\"idempotency-key\", key);\n\n const body = spec.body === undefined ? undefined : JSON.stringify(spec.body);\n const protectedKey = keyed && answerIsKept(spec.path, parseJson(body ?? \"\")) ? key : undefined;\n\n const url = withQuery(`${baseUrl}${spec.path}`, spec.query);\n return send<Result>(\n baseFetch,\n url,\n (signal) => ({\n method: spec.method,\n headers,\n body,\n signal,\n }),\n spec.options?.signal,\n spec.method === \"DELETE\" ? { ...retry, maxRetries: 0 } : retry,\n {\n key: protectedKey,\n hasApiKey,\n path: spec.path,\n replayable:\n spec.method !== \"POST\" ||\n spec.path === BROWSER_TASK_STATUS ||\n (!hasApiKey && KEYLESS_READS.has(spec.path)) ||\n protectedKey !== undefined,\n },\n );\n };\n}\n\ninterface RetryPolicy {\n maxRetries: number;\n initialDelayMs: number;\n timeoutMs: number;\n}\n\ninterface CallPlan {\n key: string | undefined;\n hasApiKey: boolean;\n path: string;\n replayable: boolean;\n}\n\nfunction answerIsKept(path: string, body: JsonValue): boolean {\n if (JOB_STARTS.has(path) || !isRecord(body)) return true;\n return ![body, body.scrapeOptions, body.options].some(\n (part) => isRecord(part) && part.zeroDataRetention === true,\n );\n}\n\ninterface NetworkError extends Error {\n code?: string;\n cause?: { code?: string };\n}\n\nconst NEVER_SENT = new Set([\n \"ECONNREFUSED\",\n \"ENOTFOUND\",\n \"EAI_AGAIN\",\n \"ENETUNREACH\",\n \"EHOSTUNREACH\",\n \"UND_ERR_CONNECT_TIMEOUT\",\n]);\n\nconst requestMayHaveLeft = (error: NetworkError) =>\n !NEVER_SENT.has(error.code ?? error.cause?.code ?? \"\");\n\nconst mayHaveRun = (error: StophyError) =>\n error.status === 408 || (error.status >= 500 && error.code !== \"busy\");\n\nconst SEND_AGAIN =\n \"Check before you send it again as a new call, or send it again with the same Idempotency-Key in details.idempotencyKey.\";\n\nfunction mayStillComplete(error: StophyError, key: string): StophyError {\n return Object.assign(\n new StophyError(`${error.message} An earlier send may still complete. ${SEND_AGAIN}`, {\n status: error.status,\n code: error.code,\n retryable: error.retryable,\n retryAfterSeconds: error.retryAfterSeconds,\n requestId: error.requestId,\n details: { ...error.details, idempotencyKey: key },\n }),\n { outcomeUnknown: true },\n );\n}\n\nfunction abortReason(signal: AbortSignal, key: string | undefined) {\n const reason: unknown = signal.reason;\n if (key === undefined) return reason;\n const error = new Error(reason instanceof Error ? reason.message : \"Stophy request cancelled\", {\n cause: reason,\n });\n if (reason instanceof Error) error.name = reason.name;\n return Object.assign(error, { idempotencyKey: key, outcomeUnknown: true });\n}\n\nasync function send<Result>(\n baseFetch: FetchLike,\n url: string,\n init: (signal: AbortSignal) => RequestInit,\n signal: AbortSignal | undefined,\n retry: RetryPolicy,\n plan: CallPlan,\n): Promise<Result> {\n let earlierSendLost = false;\n const failWith = (error: StophyError) =>\n plan.key !== undefined && earlierSendLost ? mayStillComplete(error, plan.key) : error;\n for (let n = 0; ; n += 1) {\n if (signal?.aborted) throw abortReason(signal, earlierSendLost ? plan.key : undefined);\n const deadline = withDeadline(signal, retry.timeoutMs);\n let waitMs: number;\n try {\n const answer = await baseFetch(url, init(deadline.signal))\n .then(async (response) => ({ response, text: await response.text() }))\n .catch((error: NetworkError) => {\n if (signal?.aborted) {\n earlierSendLost ||= !(error instanceof Error) || requestMayHaveLeft(error);\n throw abortReason(signal, earlierSendLost ? plan.key : undefined);\n }\n const mayHaveLeft = requestMayHaveLeft(error);\n if (mayHaveLeft && !plan.replayable) throw Object.assign(error, { outcomeUnknown: true });\n if (error.name === \"TimeoutError\" && !plan.hasApiKey) throw error;\n if (n >= retry.maxRetries) {\n throw (mayHaveLeft || earlierSendLost) && plan.key !== undefined\n ? Object.assign(error, { idempotencyKey: plan.key, outcomeUnknown: true })\n : error;\n }\n earlierSendLost ||= mayHaveLeft;\n return undefined;\n });\n if (answer === undefined) {\n waitMs = backoffMs(n, retry.initialDelayMs);\n } else {\n const { response, text } = answer;\n if (response.ok) {\n try {\n return readBody<Result>(response, text);\n } catch (error) {\n if (!(error instanceof StophyError)) throw error;\n earlierSendLost = true;\n throw !plan.replayable\n ? Object.assign(error, { outcomeUnknown: true })\n : failWith(error);\n }\n }\n const error = errorFrom(response, text);\n earlierSendLost ||= error.code === undefined && mayHaveRun(error);\n const definiteScrapeFailure =\n plan.path === \"/v1/scrape\" &&\n ((error.status === 504 && error.code === \"sourceTimeout\") ||\n (error.status === 503 && error.code === \"sourceUnavailable\"));\n if (!plan.replayable && mayHaveRun(error) && !definiteScrapeFailure) {\n throw Object.assign(error, { outcomeUnknown: true });\n }\n const seconds = error.retryAfterSeconds;\n if (!error.retryable || n >= retry.maxRetries) throw failWith(error);\n if (seconds !== undefined && seconds > MAX_RETRY_WAIT_SECONDS) throw failWith(error);\n waitMs = seconds === undefined ? backoffMs(n, retry.initialDelayMs) : seconds * 1000;\n }\n } finally {\n deadline.clear();\n }\n try {\n await sleep(waitMs, signal);\n } catch (error) {\n throw signal?.aborted ? abortReason(signal, earlierSendLost ? plan.key : undefined) : error;\n }\n }\n}\n\nexport function withDeadline(\n signal: AbortSignal | undefined,\n timeoutMs: number,\n reason = (): Error =>\n new DOMException(`Stophy request timed out after ${timeoutMs} ms`, \"TimeoutError\"),\n) {\n const controller = new AbortController();\n const abort = () => controller.abort(signal?.reason);\n if (signal?.aborted) abort();\n else signal?.addEventListener(\"abort\", abort, { once: true });\n const timer = setTimeout(() => controller.abort(reason()), timeoutMs);\n return {\n signal: controller.signal,\n clear: () => {\n clearTimeout(timer);\n signal?.removeEventListener(\"abort\", abort);\n },\n };\n}\n\nfunction readBody<Result>(response: Response, text: string): Result {\n if (!text) {\n throw failed(response, \"Stophy returned an empty response\", {});\n }\n try {\n return JSON.parse(text);\n } catch {\n throw failed(response, \"Stophy returned a non-JSON response\", {});\n }\n}\n\nfunction errorFrom(response: Response, text: string): StophyError {\n const error = readError(text ? parseJson(text) : null);\n return failed(response, error.message ?? `Stophy request failed with status ${response.status}`, {\n code: error.code,\n retryable: error.retryable ?? RETRYABLE_STATUS.has(response.status),\n retryAfterSeconds: error.retryAfterSeconds ?? headerRetryAfter(response),\n requestId: error.requestId ?? headerRequestId(response),\n details: error.details,\n });\n}\n\nfunction failed(\n response: Response,\n message: string,\n options: {\n code?: string;\n retryable?: boolean;\n retryAfterSeconds?: number;\n requestId?: string;\n details?: Record<string, JsonValue>;\n },\n): StophyError {\n return new StophyError(message, {\n status: response.status,\n code: options.code,\n retryable: options.retryable ?? false,\n retryAfterSeconds: options.retryAfterSeconds,\n requestId: options.requestId ?? headerRequestId(response),\n details: options.details,\n });\n}\n\ninterface ErrorFields {\n code?: string;\n message?: string;\n retryable?: boolean;\n retryAfterSeconds?: number;\n requestId?: string;\n details?: Record<string, JsonValue>;\n}\n\nfunction parseJson(text: string): JsonValue {\n try {\n return JSON.parse(text);\n } catch {\n return null;\n }\n}\n\nconst ENVELOPE_FIELDS = new Set([\n \"success\",\n \"error\",\n \"message\",\n \"code\",\n \"retryable\",\n \"retryAfterSeconds\",\n \"requestId\",\n]);\n\nfunction readError(body: JsonValue): ErrorFields {\n if (!isRecord(body)) return {};\n const fields = isRecord(body.error) ? body.error : body;\n return {\n code: isString(fields.code) ? fields.code : undefined,\n message: isString(fields.error)\n ? fields.error\n : isString(fields.message)\n ? fields.message\n : undefined,\n retryable: isBoolean(fields.retryable) ? fields.retryable : undefined,\n retryAfterSeconds: isNumber(fields.retryAfterSeconds) ? fields.retryAfterSeconds : undefined,\n requestId: isString(fields.requestId) ? fields.requestId : undefined,\n details: Object.fromEntries(\n Object.entries(fields).filter(([key]) => !ENVELOPE_FIELDS.has(key)),\n ),\n };\n}\n\nfunction headerRequestId(response: Response): string | undefined {\n return response.headers.get(\"x-request-id\") ?? undefined;\n}\n\nfunction headerRetryAfter(response: Response): number | undefined {\n const header = response.headers.get(\"retry-after\");\n if (!header) return undefined;\n const seconds = Number(header);\n if (Number.isFinite(seconds)) return seconds;\n const date = Date.parse(header);\n if (Number.isNaN(date)) return undefined;\n return Math.max(0, Math.ceil((date - Date.now()) / 1000));\n}\n\nfunction withQuery(url: string, query: Query | undefined): string {\n if (!query) return url;\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined) params.set(key, String(value));\n }\n const text = params.toString();\n return text ? `${url}?${text}` : url;\n}\n\nfunction backoffMs(attempt: number, base: number): number {\n const window = base * 2 ** attempt;\n return window / 2 + Math.random() * (window / 2);\n}\n\nfunction sleep(ms: number, signal: AbortSignal | undefined): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) return reject(signal.reason);\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal?.reason);\n };\n const timer = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n","import { StophyError } from \"./errors\";\nimport { type CallOptions, withDeadline } from \"./transport\";\n\nconst START = \"ck_start\";\nconst ENDED = new Set([\"completed\", \"failed\", \"cancelled\"]);\nconst DEFAULT_POLL_MS = 2_000;\nconst DEFAULT_TIMEOUT_MS = 15 * 60_000;\n\nexport interface ResultsOptions {\n checkpoint?: string;\n pollIntervalMs?: number;\n timeoutMs?: number;\n signal?: AbortSignal;\n onCheckpoint?: (checkpoint: string) => void;\n}\n\nexport interface ResultsEnd {\n status: string;\n checkpoint: string;\n}\n\ninterface StatusPage<Item> {\n status: string;\n checkpoint?: string;\n data?: Item[];\n}\n\nexport type ReadPage<Item> = (checkpoint: string, call: CallOptions) => Promise<StatusPage<Item>>;\n\nexport async function* checkpointResults<Item>(\n readPage: ReadPage<Item>,\n options: ResultsOptions = {},\n): AsyncGenerator<Item, ResultsEnd> {\n const { signal, onCheckpoint } = options;\n const pollMs = options.pollIntervalMs ?? DEFAULT_POLL_MS;\n const deadline = performance.now() + (options.timeoutMs ?? DEFAULT_TIMEOUT_MS);\n let checkpoint = options.checkpoint ?? START;\n\n for (;;) {\n signal?.throwIfAborted();\n const remaining = deadline - performance.now();\n if (remaining <= 0) throw resultsTimeout(checkpoint);\n const page = await readWithinBudget(readPage, checkpoint, remaining, signal);\n if (performance.now() >= deadline) throw resultsTimeout(checkpoint);\n if (page.checkpoint === undefined) {\n throw new StophyError(\"The job's answer carried no checkpoint to resume from.\", {\n status: 0,\n code: \"checkpointMissing\",\n retryable: false,\n });\n }\n const results = page.data ?? [];\n yield* results;\n checkpoint = page.checkpoint;\n onCheckpoint?.(checkpoint);\n if (results.length > 0) continue;\n if (ENDED.has(page.status)) return { status: page.status, checkpoint };\n if (performance.now() + pollMs >= deadline) throw resultsTimeout(checkpoint);\n await sleep(pollMs, signal);\n }\n}\n\nfunction resultsTimeout(checkpoint: string): StophyError {\n return new StophyError(\"Gave up waiting for more results. Resume with the checkpoint.\", {\n status: 0,\n code: \"resultsTimeout\",\n retryable: true,\n details: { checkpoint },\n });\n}\n\nasync function readWithinBudget<Item>(\n readPage: ReadPage<Item>,\n checkpoint: string,\n remaining: number,\n signal: AbortSignal | undefined,\n): Promise<StatusPage<Item>> {\n if (remaining > 2_147_483_647) return readPage(checkpoint, { signal });\n const call = withDeadline(signal, remaining, () => resultsTimeout(checkpoint));\n try {\n const page = await readPage(checkpoint, { signal: call.signal });\n call.signal.throwIfAborted();\n return page;\n } finally {\n call.clear();\n }\n}\n\nfunction sleep(ms: number, signal: AbortSignal | undefined): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) return reject(signal.reason);\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal?.reason);\n };\n const timer = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n","import type { RequestOptions } from \"./bind\";\nimport type { ParserName } from \"./generated/parsers.gen\";\nimport { Surface } from \"./generated/surface.gen\";\nimport type {\n BatchScrapeStatusResponse,\n CrawlStatusResponse,\n ScrapeData,\n ScrapeResponse,\n} from \"./generated/types.gen\";\nimport { checkpointResults, type ResultsEnd, type ResultsOptions } from \"./results\";\nimport { type CallOptions, createCaller, type FetchLike } from \"./transport\";\n\nexport interface StophyOptions {\n apiKey?: string;\n baseUrl?: string;\n fetch?: FetchLike;\n headers?: Record<string, string>;\n maxRetries?: number;\n retryInitialDelayMs?: number;\n timeoutMs?: number;\n}\n\nexport type { CallOptions, FetchLike };\n\nexport type StophyClientInput = StophyOptions | string;\n\ntype JsonFormat = Extract<NonNullable<ScrapeData[\"body\"][\"formats\"]>[number], { type: \"json\" }>;\n\nexport type ParserOptions = NonNullable<JsonFormat[\"options\"]>;\n\nfunction env(name: string): string | undefined {\n return globalThis.process?.env[name];\n}\n\nexport class Stophy extends Surface {\n constructor(input: StophyClientInput = {}) {\n const options = input instanceof Object ? input : { apiKey: input };\n const apiKey = options.apiKey?.trim() || env(\"STOPHY_API_KEY\")?.trim();\n const call = createCaller({\n ...options,\n apiKey,\n baseUrl: options.baseUrl ?? env(\"STOPHY_BASE_URL\"),\n });\n super(call);\n }\n\n crawlResults(\n id: string,\n options?: ResultsOptions,\n ): AsyncGenerator<NonNullable<CrawlStatusResponse[\"data\"]>[number], ResultsEnd> {\n return checkpointResults(\n (checkpoint, call) => this.crawl.status({ id, checkpoint }, call),\n options,\n );\n }\n\n batchScrapeResults(\n id: string,\n options?: ResultsOptions,\n ): AsyncGenerator<NonNullable<BatchScrapeStatusResponse[\"data\"]>[number], ResultsEnd> {\n return checkpointResults(\n (checkpoint, call) => this.batch.scrape.status({ id, checkpoint }, call),\n options,\n );\n }\n\n parsed(\n parser: ParserName,\n url: string,\n options?: ParserOptions,\n request?: RequestOptions,\n ): Promise<ScrapeResponse> {\n return this.scrape({ url, formats: [{ type: \"json\", parser, options }] }, request);\n }\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -797,11 +797,11 @@ type SearchData = {
797
797
  */
798
798
  highlights?: boolean;
799
799
  /**
800
- * With formats, reads each web and news result, as many as scrapeLimit or limit asks for, within timeout, and fills each web result's description from it. Without formats no page is read and nothing more is charged. Takes the options of scrape: formats (markdown, html, rawHtml, links, images, summary, screenshot, json and the rest), onlyMainContent, includeTags, excludeTags, maxAge, minAge, waitFor, mobile, timeout (per page), headers, actions, location, parsers, profile and zeroDataRetention. Costs what scrape costs for each page read: $1 per 1,000 pages, plus $3 per 1,000 pages for each summary or json with a schema or prompt that returns something.
800
+ * With formats, reads each web and news result, as many as scrapeLimit or limit asks for, within timeout, and fills each web result's description from it. Without formats no page is read and nothing more is charged. Takes the options of scrape: formats (markdown, html, rawHtml, links, images, summary, screenshot, json and the rest), onlyMainContent, includeTags, excludeTags, maxAge, minAge, waitFor, mobile, timeout (per page), headers, actions, location, parsers, profile and zeroDataRetention. redactPII uses patterns on web descriptions, news snippets, research snippets and video snippets, even without formats, when sources has web or news. Titles and URLs are unchanged. Snippets can still contain names and places that patterns miss. With formats, page reads and their add-ons use scrape pricing, starting at $1 per 1,000 pages for a standard read.
801
801
  */
802
802
  scrapeOptions?: {
803
803
  /**
804
- * What to return: markdown (clean page text), summary (a short summary of the page), html (the cleaned page), rawHtml (the page as sent), audio and video (for a YouTube link: the audio track as an M4A file, or the video as an MP4 file, as a link that works for 1 hour), rawBase64 (the bytes the site sent, Base64 encoded, from a live read; metadata.contentType says what they are), links (every link on the page), images (every image address), screenshot (a link to a JPEG of the visible page, kept for 7 days), changeTracking (what changed in the markdown since your key last read this page with the same options, kept 30 days; add modes ["git-diff","json"] with a schema or prompt to compare fields too), question (send { "type": "question", "question": "..." } to get answer, left out with a warning when the page does not state one), product (title, brand, category, url, description and variants with price, sale, availability and images, left out with a warning when there is none) and menu (merchant, currency and sections of items with prices, left out with a warning when there is none) network (the JSON the page loaded while it rendered, up to 30 responses) and branding (the page's colors, fonts, typography, spacing, button and input styles, logo and brand images, read from how the page looks, with a field left out when the page does not show it). Send { "type": "screenshot", "fullPage": true } for the whole page. Send { "type": "highlights", "query": "refund policy" } for the passages that best match a query. Send { "type": "json", "schema": { "type": "object", "properties": { "price": { "type": "number" } } } } or { "type": "json", "prompt": "the price and the stock" } for fields filled from the page, each checked against it. Send { "type": "json", "parser": "amazon-product" } to get a site's own data as json instead of reading the page; GET /v1/parsers lists the parsers. Send { "type": "json", "rules": { "title": "h1", "links": { "selector": "a", "type": "list", "output": "@href" } } } to read the page with CSS rules and no model, at the page's own price. Send { "type": "attributes", "selectors": [{ "selector": "a", "attribute": "href" }] } for attribute values, returned in attributes. Without a parser or rules, json needs a schema or a prompt and is filled from the page. json with a schema or a prompt, summary, highlights, question, product, menu and changeTracking in json mode add $3 per 1,000 pages each when they return something. json with rules or a parser, and attributes, cost nothing more. A screenshot, network or branding read costs $1 per 1,000 pages, the same as any page. A PDF comes back as markdown only, and adds $0.50 per 1,000 pages of text from its text layer and $2.50 per 1,000 pages of text read from its picture that comes back. A CSV or an Excel .xlsx file comes back as markdown tables.
804
+ * What to return: markdown (clean page text), summary (a short summary of the page), html (the cleaned page), rawHtml (the page as sent), audio and video (for a YouTube link: the audio track as an M4A file, or the video as an MP4 file, as a link that works for 1 hour), rawBase64 (the bytes the site sent, Base64 encoded, from a live read; metadata.contentType says what they are), links (every link on the page), images (every image address), screenshot (a link to a JPEG of the visible page, kept for 7 days), changeTracking (what changed in the markdown since your key last read this page with the same options, kept 30 days; add modes ["git-diff","json"] with a schema or prompt to compare fields too), question (send { "type": "question", "question": "..." } to get answer, left out with a warning when the page does not state one), product (title, brand, category, url, description and variants with price, sale, availability and images, left out with a warning when there is none) and menu (merchant, currency and sections of items with prices, left out with a warning when there is none) network (the JSON the page loaded while it rendered, up to 30 responses) and branding (the page's colors, fonts, typography, spacing, button and input styles, logo and brand images, read from how the page looks, with a field left out when the page does not show it). Send { "type": "screenshot", "fullPage": true } for the whole page. Send { "type": "highlights", "query": "refund policy" } for the passages that best match a query. Send { "type": "json", "schema": { "type": "object", "properties": { "price": { "type": "number" } } } } or { "type": "json", "prompt": "the price and the stock" } for fields filled from the page, each checked against it. Send { "type": "json", "parser": "amazon-product" } to get a site's own data as json instead of reading the page; GET /v1/parsers lists the parsers. Send { "type": "json", "rules": { "title": "h1", "links": { "selector": "a", "type": "list", "output": "@href" } } } to read the page with CSS rules and no model, at the page's own price. Send { "type": "attributes", "selectors": [{ "selector": "a", "attribute": "href" }] } for attribute values, returned in attributes. Without a parser or rules, json needs a schema or a prompt and is filled from the page. json with a schema or a prompt, summary, highlights, question, product, menu and changeTracking in json mode add $3 per 1,000 pages each when they return something. JSON with CSS rules and attributes add nothing. A named parser uses its own price. Any page read or other paid format you ask for is charged separately. A screenshot, network or branding read costs $1 per 1,000 pages, the same as any page. A PDF comes back as markdown only, and adds $0.50 per 1,000 pages of text from its text layer and $2.50 per 1,000 pages of text read from its picture that comes back. A CSV or an Excel .xlsx file comes back as markdown tables.
805
805
  */
806
806
  formats?: Array<("markdown" | "summary" | "html" | "rawHtml" | "rawBase64" | "links" | "images" | "network" | "branding" | "audio" | "video" | "screenshot" | "changeTracking" | "product" | "menu") | {
807
807
  type: "markdown" | "summary" | "html" | "rawHtml" | "rawBase64" | "links" | "images" | "network" | "branding" | "audio" | "video";
@@ -1657,7 +1657,7 @@ type ScrapeData = {
1657
1657
  */
1658
1658
  url: string;
1659
1659
  /**
1660
- * What to return: markdown (clean page text), summary (a short summary of the page), html (the cleaned page), rawHtml (the page as sent), audio and video (for a YouTube link: the audio track as an M4A file, or the video as an MP4 file, as a link that works for 1 hour), rawBase64 (the bytes the site sent, Base64 encoded, from a live read; metadata.contentType says what they are), links (every link on the page), images (every image address), screenshot (a link to a JPEG of the visible page, kept for 7 days), changeTracking (what changed in the markdown since your key last read this page with the same options, kept 30 days; add modes ["git-diff","json"] with a schema or prompt to compare fields too), question (send { "type": "question", "question": "..." } to get answer, left out with a warning when the page does not state one), product (title, brand, category, url, description and variants with price, sale, availability and images, left out with a warning when there is none) and menu (merchant, currency and sections of items with prices, left out with a warning when there is none) network (the JSON the page loaded while it rendered, up to 30 responses) and branding (the page's colors, fonts, typography, spacing, button and input styles, logo and brand images, read from how the page looks, with a field left out when the page does not show it). Send { "type": "screenshot", "fullPage": true } for the whole page. Send { "type": "highlights", "query": "refund policy" } for the passages that best match a query. Send { "type": "json", "schema": { "type": "object", "properties": { "price": { "type": "number" } } } } or { "type": "json", "prompt": "the price and the stock" } for fields filled from the page, each checked against it. Send { "type": "json", "parser": "amazon-product" } to get a site's own data as json instead of reading the page; GET /v1/parsers lists the parsers. Send { "type": "json", "rules": { "title": "h1", "links": { "selector": "a", "type": "list", "output": "@href" } } } to read the page with CSS rules and no model, at the page's own price. Send { "type": "attributes", "selectors": [{ "selector": "a", "attribute": "href" }] } for attribute values, returned in attributes. Without a parser or rules, json needs a schema or a prompt and is filled from the page. json with a schema or a prompt, summary, highlights, question, product, menu and changeTracking in json mode add $3 per 1,000 pages each when they return something. json with rules or a parser, and attributes, cost nothing more. A screenshot, network or branding read costs $1 per 1,000 pages, the same as any page. A PDF comes back as markdown only, and adds $0.50 per 1,000 pages of text from its text layer and $2.50 per 1,000 pages of text read from its picture that comes back. A CSV or an Excel .xlsx file comes back as markdown tables.
1660
+ * What to return: markdown (clean page text), summary (a short summary of the page), html (the cleaned page), rawHtml (the page as sent), audio and video (for a YouTube link: the audio track as an M4A file, or the video as an MP4 file, as a link that works for 1 hour), rawBase64 (the bytes the site sent, Base64 encoded, from a live read; metadata.contentType says what they are), links (every link on the page), images (every image address), screenshot (a link to a JPEG of the visible page, kept for 7 days), changeTracking (what changed in the markdown since your key last read this page with the same options, kept 30 days; add modes ["git-diff","json"] with a schema or prompt to compare fields too), question (send { "type": "question", "question": "..." } to get answer, left out with a warning when the page does not state one), product (title, brand, category, url, description and variants with price, sale, availability and images, left out with a warning when there is none) and menu (merchant, currency and sections of items with prices, left out with a warning when there is none) network (the JSON the page loaded while it rendered, up to 30 responses) and branding (the page's colors, fonts, typography, spacing, button and input styles, logo and brand images, read from how the page looks, with a field left out when the page does not show it). Send { "type": "screenshot", "fullPage": true } for the whole page. Send { "type": "highlights", "query": "refund policy" } for the passages that best match a query. Send { "type": "json", "schema": { "type": "object", "properties": { "price": { "type": "number" } } } } or { "type": "json", "prompt": "the price and the stock" } for fields filled from the page, each checked against it. Send { "type": "json", "parser": "amazon-product" } to get a site's own data as json instead of reading the page; GET /v1/parsers lists the parsers. Send { "type": "json", "rules": { "title": "h1", "links": { "selector": "a", "type": "list", "output": "@href" } } } to read the page with CSS rules and no model, at the page's own price. Send { "type": "attributes", "selectors": [{ "selector": "a", "attribute": "href" }] } for attribute values, returned in attributes. Without a parser or rules, json needs a schema or a prompt and is filled from the page. json with a schema or a prompt, summary, highlights, question, product, menu and changeTracking in json mode add $3 per 1,000 pages each when they return something. JSON with CSS rules and attributes add nothing. A named parser uses its own price. Any page read or other paid format you ask for is charged separately. A screenshot, network or branding read costs $1 per 1,000 pages, the same as any page. A PDF comes back as markdown only, and adds $0.50 per 1,000 pages of text from its text layer and $2.50 per 1,000 pages of text read from its picture that comes back. A CSV or an Excel .xlsx file comes back as markdown tables.
1661
1661
  */
1662
1662
  formats?: Array<("markdown" | "summary" | "html" | "rawHtml" | "rawBase64" | "links" | "images" | "network" | "branding" | "audio" | "video" | "screenshot" | "changeTracking" | "product" | "menu") | {
1663
1663
  type: "markdown" | "summary" | "html" | "rawHtml" | "rawBase64" | "links" | "images" | "network" | "branding" | "audio" | "video";
@@ -2283,7 +2283,7 @@ type ExtractData = {
2283
2283
  */
2284
2284
  proxy?: "auto" | "basic" | "enhanced" | "stealth";
2285
2285
  /**
2286
- * Send false to neither read nor keep a stored copy of this page.
2286
+ * Send false to skip reading and saving stored copies. Use zeroDataRetention to read live without saving a copy.
2287
2287
  */
2288
2288
  storeInCache?: boolean;
2289
2289
  /**
@@ -2497,6 +2497,10 @@ type BrowserTaskStatusResponses = {
2497
2497
  steps?: Array<string>;
2498
2498
  url?: string;
2499
2499
  title?: string;
2500
+ /**
2501
+ * The page the task ended on, as the browser showed it, so you can check the answer against it.
2502
+ */
2503
+ pageText?: string;
2500
2504
  seconds?: number;
2501
2505
  fields?: {
2502
2506
  [key: string]: BrowserTaskStatusSchema0;
@@ -2830,6 +2834,10 @@ type MapData = {
2830
2834
  * List each page once, without its ?query part.
2831
2835
  */
2832
2836
  ignoreQueryParameters?: boolean;
2837
+ /**
2838
+ * Send false to list distinct addresses such as /docs/a, /docs/a/ and /docs/a.md.
2839
+ */
2840
+ deduplicateSimilarURLs?: boolean;
2833
2841
  /**
2834
2842
  * Send true to build the list again instead of reusing one made in the last 6 hours.
2835
2843
  */
@@ -2963,7 +2971,7 @@ type CrawlData = {
2963
2971
  */
2964
2972
  scrapeOptions?: {
2965
2973
  /**
2966
- * What to return: markdown (clean page text), summary (a short summary of the page), html (the cleaned page), rawHtml (the page as sent), audio and video (for a YouTube link: the audio track as an M4A file, or the video as an MP4 file, as a link that works for 1 hour), rawBase64 (the bytes the site sent, Base64 encoded, from a live read; metadata.contentType says what they are), links (every link on the page), images (every image address), screenshot (a link to a JPEG of the visible page, kept for 7 days), changeTracking (what changed in the markdown since your key last read this page with the same options, kept 30 days; add modes ["git-diff","json"] with a schema or prompt to compare fields too), question (send { "type": "question", "question": "..." } to get answer, left out with a warning when the page does not state one), product (title, brand, category, url, description and variants with price, sale, availability and images, left out with a warning when there is none) and menu (merchant, currency and sections of items with prices, left out with a warning when there is none) network (the JSON the page loaded while it rendered, up to 30 responses) and branding (the page's colors, fonts, typography, spacing, button and input styles, logo and brand images, read from how the page looks, with a field left out when the page does not show it). Send { "type": "screenshot", "fullPage": true } for the whole page. Send { "type": "highlights", "query": "refund policy" } for the passages that best match a query. Send { "type": "json", "schema": { "type": "object", "properties": { "price": { "type": "number" } } } } or { "type": "json", "prompt": "the price and the stock" } for fields filled from the page, each checked against it. Send { "type": "json", "parser": "amazon-product" } to get a site's own data as json instead of reading the page; GET /v1/parsers lists the parsers. Send { "type": "json", "rules": { "title": "h1", "links": { "selector": "a", "type": "list", "output": "@href" } } } to read the page with CSS rules and no model, at the page's own price. Send { "type": "attributes", "selectors": [{ "selector": "a", "attribute": "href" }] } for attribute values, returned in attributes. Without a parser or rules, json needs a schema or a prompt and is filled from the page. json with a schema or a prompt, summary, highlights, question, product, menu and changeTracking in json mode add $3 per 1,000 pages each when they return something. json with rules or a parser, and attributes, cost nothing more. A screenshot, network or branding read costs $1 per 1,000 pages, the same as any page. A PDF comes back as markdown only, and adds $0.50 per 1,000 pages of text from its text layer and $2.50 per 1,000 pages of text read from its picture that comes back. A CSV or an Excel .xlsx file comes back as markdown tables.
2974
+ * What to return: markdown (clean page text), summary (a short summary of the page), html (the cleaned page), rawHtml (the page as sent), audio and video (for a YouTube link: the audio track as an M4A file, or the video as an MP4 file, as a link that works for 1 hour), rawBase64 (the bytes the site sent, Base64 encoded, from a live read; metadata.contentType says what they are), links (every link on the page), images (every image address), screenshot (a link to a JPEG of the visible page, kept for 7 days), changeTracking (what changed in the markdown since your key last read this page with the same options, kept 30 days; add modes ["git-diff","json"] with a schema or prompt to compare fields too), question (send { "type": "question", "question": "..." } to get answer, left out with a warning when the page does not state one), product (title, brand, category, url, description and variants with price, sale, availability and images, left out with a warning when there is none) and menu (merchant, currency and sections of items with prices, left out with a warning when there is none) network (the JSON the page loaded while it rendered, up to 30 responses) and branding (the page's colors, fonts, typography, spacing, button and input styles, logo and brand images, read from how the page looks, with a field left out when the page does not show it). Send { "type": "screenshot", "fullPage": true } for the whole page. Send { "type": "highlights", "query": "refund policy" } for the passages that best match a query. Send { "type": "json", "schema": { "type": "object", "properties": { "price": { "type": "number" } } } } or { "type": "json", "prompt": "the price and the stock" } for fields filled from the page, each checked against it. Send { "type": "json", "parser": "amazon-product" } to get a site's own data as json instead of reading the page; GET /v1/parsers lists the parsers. Send { "type": "json", "rules": { "title": "h1", "links": { "selector": "a", "type": "list", "output": "@href" } } } to read the page with CSS rules and no model, at the page's own price. Send { "type": "attributes", "selectors": [{ "selector": "a", "attribute": "href" }] } for attribute values, returned in attributes. Without a parser or rules, json needs a schema or a prompt and is filled from the page. json with a schema or a prompt, summary, highlights, question, product, menu and changeTracking in json mode add $3 per 1,000 pages each when they return something. JSON with CSS rules and attributes add nothing. A named parser uses its own price. Any page read or other paid format you ask for is charged separately. A screenshot, network or branding read costs $1 per 1,000 pages, the same as any page. A PDF comes back as markdown only, and adds $0.50 per 1,000 pages of text from its text layer and $2.50 per 1,000 pages of text read from its picture that comes back. A CSV or an Excel .xlsx file comes back as markdown tables.
2967
2975
  */
2968
2976
  formats?: Array<("markdown" | "summary" | "html" | "rawHtml" | "rawBase64" | "links" | "images" | "network" | "branding" | "audio" | "video" | "screenshot" | "changeTracking" | "product" | "menu") | {
2969
2977
  type: "markdown" | "summary" | "html" | "rawHtml" | "rawBase64" | "links" | "images" | "network" | "branding" | "audio" | "video";
@@ -3359,6 +3367,10 @@ type CrawlStatusData = {
3359
3367
  * Cut every text value in the response to this many characters. A value that was cut ends with …, and a page whose text was cut has isTruncated set to true. A screenshot is never cut. Leave it out to get the full text.
3360
3368
  */
3361
3369
  maxTextLength?: number;
3370
+ /**
3371
+ * Send ck_start to start reading with checkpoints. Send the returned checkpoint here to resume, even when no more pages are ready.
3372
+ */
3373
+ checkpoint?: string;
3362
3374
  /**
3363
3375
  * The cursor from the previous response. Send it as is.
3364
3376
  */
@@ -3406,6 +3418,8 @@ type CrawlStatusResponses = {
3406
3418
  duration?: number;
3407
3419
  expiresAt?: string;
3408
3420
  next?: string;
3421
+ checkpoint?: string;
3422
+ message?: string;
3409
3423
  data: Array<{
3410
3424
  markdown?: string;
3411
3425
  summary?: string;
@@ -3502,7 +3516,7 @@ type BatchScrapeData = {
3502
3516
  */
3503
3517
  ignoreInvalidURLs?: boolean;
3504
3518
  /**
3505
- * What to return: markdown (clean page text), summary (a short summary of the page), html (the cleaned page), rawHtml (the page as sent), audio and video (for a YouTube link: the audio track as an M4A file, or the video as an MP4 file, as a link that works for 1 hour), rawBase64 (the bytes the site sent, Base64 encoded, from a live read; metadata.contentType says what they are), links (every link on the page), images (every image address), screenshot (a link to a JPEG of the visible page, kept for 7 days), changeTracking (what changed in the markdown since your key last read this page with the same options, kept 30 days; add modes ["git-diff","json"] with a schema or prompt to compare fields too), question (send { "type": "question", "question": "..." } to get answer, left out with a warning when the page does not state one), product (title, brand, category, url, description and variants with price, sale, availability and images, left out with a warning when there is none) and menu (merchant, currency and sections of items with prices, left out with a warning when there is none) network (the JSON the page loaded while it rendered, up to 30 responses) and branding (the page's colors, fonts, typography, spacing, button and input styles, logo and brand images, read from how the page looks, with a field left out when the page does not show it). Send { "type": "screenshot", "fullPage": true } for the whole page. Send { "type": "highlights", "query": "refund policy" } for the passages that best match a query. Send { "type": "json", "schema": { "type": "object", "properties": { "price": { "type": "number" } } } } or { "type": "json", "prompt": "the price and the stock" } for fields filled from the page, each checked against it. Send { "type": "json", "parser": "amazon-product" } to get a site's own data as json instead of reading the page; GET /v1/parsers lists the parsers. Send { "type": "json", "rules": { "title": "h1", "links": { "selector": "a", "type": "list", "output": "@href" } } } to read the page with CSS rules and no model, at the page's own price. Send { "type": "attributes", "selectors": [{ "selector": "a", "attribute": "href" }] } for attribute values, returned in attributes. Without a parser or rules, json needs a schema or a prompt and is filled from the page. json with a schema or a prompt, summary, highlights, question, product, menu and changeTracking in json mode add $3 per 1,000 pages each when they return something. json with rules or a parser, and attributes, cost nothing more. A screenshot, network or branding read costs $1 per 1,000 pages, the same as any page. A PDF comes back as markdown only, and adds $0.50 per 1,000 pages of text from its text layer and $2.50 per 1,000 pages of text read from its picture that comes back. A CSV or an Excel .xlsx file comes back as markdown tables.
3519
+ * What to return: markdown (clean page text), summary (a short summary of the page), html (the cleaned page), rawHtml (the page as sent), audio and video (for a YouTube link: the audio track as an M4A file, or the video as an MP4 file, as a link that works for 1 hour), rawBase64 (the bytes the site sent, Base64 encoded, from a live read; metadata.contentType says what they are), links (every link on the page), images (every image address), screenshot (a link to a JPEG of the visible page, kept for 7 days), changeTracking (what changed in the markdown since your key last read this page with the same options, kept 30 days; add modes ["git-diff","json"] with a schema or prompt to compare fields too), question (send { "type": "question", "question": "..." } to get answer, left out with a warning when the page does not state one), product (title, brand, category, url, description and variants with price, sale, availability and images, left out with a warning when there is none) and menu (merchant, currency and sections of items with prices, left out with a warning when there is none) network (the JSON the page loaded while it rendered, up to 30 responses) and branding (the page's colors, fonts, typography, spacing, button and input styles, logo and brand images, read from how the page looks, with a field left out when the page does not show it). Send { "type": "screenshot", "fullPage": true } for the whole page. Send { "type": "highlights", "query": "refund policy" } for the passages that best match a query. Send { "type": "json", "schema": { "type": "object", "properties": { "price": { "type": "number" } } } } or { "type": "json", "prompt": "the price and the stock" } for fields filled from the page, each checked against it. Send { "type": "json", "parser": "amazon-product" } to get a site's own data as json instead of reading the page; GET /v1/parsers lists the parsers. Send { "type": "json", "rules": { "title": "h1", "links": { "selector": "a", "type": "list", "output": "@href" } } } to read the page with CSS rules and no model, at the page's own price. Send { "type": "attributes", "selectors": [{ "selector": "a", "attribute": "href" }] } for attribute values, returned in attributes. Without a parser or rules, json needs a schema or a prompt and is filled from the page. json with a schema or a prompt, summary, highlights, question, product, menu and changeTracking in json mode add $3 per 1,000 pages each when they return something. JSON with CSS rules and attributes add nothing. A named parser uses its own price. Any page read or other paid format you ask for is charged separately. A screenshot, network or branding read costs $1 per 1,000 pages, the same as any page. A PDF comes back as markdown only, and adds $0.50 per 1,000 pages of text from its text layer and $2.50 per 1,000 pages of text read from its picture that comes back. A CSV or an Excel .xlsx file comes back as markdown tables.
3506
3520
  */
3507
3521
  formats?: Array<("markdown" | "summary" | "html" | "rawHtml" | "rawBase64" | "links" | "images" | "network" | "branding" | "audio" | "video" | "screenshot" | "changeTracking" | "product" | "menu") | {
3508
3522
  type: "markdown" | "summary" | "html" | "rawHtml" | "rawBase64" | "links" | "images" | "network" | "branding" | "audio" | "video";
@@ -3893,6 +3907,10 @@ type BatchScrapeStatusData = {
3893
3907
  * Cut every text value in the response to this many characters. A value that was cut ends with …, and a page whose text was cut has isTruncated set to true. A screenshot is never cut. Leave it out to get the full text.
3894
3908
  */
3895
3909
  maxTextLength?: number;
3910
+ /**
3911
+ * Send ck_start to start reading with checkpoints. Send the returned checkpoint here to resume, even when no more pages are ready.
3912
+ */
3913
+ checkpoint?: string;
3896
3914
  /**
3897
3915
  * The cursor from the previous response. Send it as is.
3898
3916
  */
@@ -3940,6 +3958,7 @@ type BatchScrapeStatusResponses = {
3940
3958
  duration?: number;
3941
3959
  expiresAt?: string;
3942
3960
  next?: string;
3961
+ checkpoint?: string;
3943
3962
  data: Array<{
3944
3963
  markdown?: string;
3945
3964
  summary?: string;
@@ -5091,6 +5110,7 @@ declare function bindSurface(call: Caller): {
5091
5110
  steps?: Array<string>;
5092
5111
  url?: string;
5093
5112
  title?: string;
5113
+ pageText?: string;
5094
5114
  seconds?: number;
5095
5115
  fields?: {
5096
5116
  [key: string]: BrowserTaskStatusSchema0;
@@ -5215,6 +5235,7 @@ declare function bindSurface(call: Caller): {
5215
5235
  sitemap?: "skip" | "include" | "only";
5216
5236
  includeSubdomains?: boolean;
5217
5237
  ignoreQueryParameters?: boolean;
5238
+ deduplicateSimilarURLs?: boolean;
5218
5239
  ignoreCache?: boolean;
5219
5240
  limit?: number;
5220
5241
  timeout?: number;
@@ -5406,6 +5427,7 @@ declare function bindSurface(call: Caller): {
5406
5427
  id: string;
5407
5428
  } & {
5408
5429
  maxTextLength?: number;
5430
+ checkpoint?: string;
5409
5431
  cursor?: string;
5410
5432
  }, options?: RequestOptions) => Promise<{
5411
5433
  success: true;
@@ -5432,6 +5454,8 @@ declare function bindSurface(call: Caller): {
5432
5454
  duration?: number;
5433
5455
  expiresAt?: string;
5434
5456
  next?: string;
5457
+ checkpoint?: string;
5458
+ message?: string;
5435
5459
  data: Array<{
5436
5460
  markdown?: string;
5437
5461
  summary?: string;
@@ -5667,6 +5691,7 @@ declare function bindSurface(call: Caller): {
5667
5691
  id: string;
5668
5692
  } & {
5669
5693
  maxTextLength?: number;
5694
+ checkpoint?: string;
5670
5695
  cursor?: string;
5671
5696
  }, options?: RequestOptions) => Promise<{
5672
5697
  success: true;
@@ -5693,6 +5718,7 @@ declare function bindSurface(call: Caller): {
5693
5718
  duration?: number;
5694
5719
  expiresAt?: string;
5695
5720
  next?: string;
5721
+ checkpoint?: string;
5696
5722
  data: Array<{
5697
5723
  markdown?: string;
5698
5724
  summary?: string;
@@ -5783,6 +5809,18 @@ declare class Surface {
5783
5809
  constructor(call: Caller);
5784
5810
  }
5785
5811
 
5812
+ interface ResultsOptions {
5813
+ checkpoint?: string;
5814
+ pollIntervalMs?: number;
5815
+ timeoutMs?: number;
5816
+ signal?: AbortSignal;
5817
+ onCheckpoint?: (checkpoint: string) => void;
5818
+ }
5819
+ interface ResultsEnd {
5820
+ status: string;
5821
+ checkpoint: string;
5822
+ }
5823
+
5786
5824
  interface StophyOptions {
5787
5825
  apiKey?: string;
5788
5826
  baseUrl?: string;
@@ -5800,6 +5838,8 @@ type JsonFormat = Extract<NonNullable<ScrapeData["body"]["formats"]>[number], {
5800
5838
  type ParserOptions = NonNullable<JsonFormat["options"]>;
5801
5839
  declare class Stophy extends Surface {
5802
5840
  constructor(input?: StophyClientInput);
5841
+ crawlResults(id: string, options?: ResultsOptions): AsyncGenerator<NonNullable<CrawlStatusResponse["data"]>[number], ResultsEnd>;
5842
+ batchScrapeResults(id: string, options?: ResultsOptions): AsyncGenerator<NonNullable<BatchScrapeStatusResponse["data"]>[number], ResultsEnd>;
5803
5843
  parsed(parser: ParserName, url: string, options?: ParserOptions, request?: RequestOptions): Promise<ScrapeResponse>;
5804
5844
  }
5805
5845
 
@@ -5827,4 +5867,4 @@ declare class StophyError extends Error {
5827
5867
  });
5828
5868
  }
5829
5869
 
5830
- export { type BatchScrapeCancelData, type BatchScrapeCancelError, type BatchScrapeCancelErrors, type BatchScrapeCancelResponse, type BatchScrapeCancelResponses, type BatchScrapeData, type BatchScrapeError, type BatchScrapeErrors, type BatchScrapeInputSchema0, type BatchScrapeInputSchema1, type BatchScrapeInputSchema2, type BatchScrapeResponse, type BatchScrapeResponses, type BatchScrapeStatusData, type BatchScrapeStatusError, type BatchScrapeStatusErrors, type BatchScrapeStatusResponse, type BatchScrapeStatusResponses, type BatchScrapeStatusSchema0, type BrowserTaskData, type BrowserTaskError, type BrowserTaskErrors, type BrowserTaskInputSchema0, type BrowserTaskResponse, type BrowserTaskResponses, type BrowserTaskStatusData, type BrowserTaskStatusError, type BrowserTaskStatusErrors, type BrowserTaskStatusResponse, type BrowserTaskStatusResponses, type BrowserTaskStatusSchema0, type CallOptions, type ClientOptions, type CrawlCancelData, type CrawlCancelError, type CrawlCancelErrors, type CrawlCancelResponse, type CrawlCancelResponses, type CrawlData, type CrawlError, type CrawlErrors, type CrawlInputSchema0, type CrawlInputSchema1, type CrawlInputSchema2, type CrawlResponse, type CrawlResponses, type CrawlStatusData, type CrawlStatusError, type CrawlStatusErrors, type CrawlStatusResponse, type CrawlStatusResponses, type CrawlStatusSchema0, type ExtractData, type ExtractError, type ExtractErrors, type ExtractInputSchema0, type ExtractResponse, type ExtractResponses, type ExtractResultData, type ExtractResultError, type ExtractResultErrors, type ExtractResultResponse, type ExtractResultResponses, type ExtractResultSchema0, type FetchLike, type GetLimitsData, type GetLimitsError, type GetLimitsErrors, type GetLimitsResponse, type GetLimitsResponses, type GetLogsData, type GetLogsError, type GetLogsErrors, type GetLogsResponse, type GetLogsResponses, type GetUsageData, type GetUsageError, type GetUsageErrors, type GetUsageResponse, type GetUsageResponses, type IdempotencyKey, type ListEndpoints26Schema0, type ListEndpointsData, type ListEndpointsError, type ListEndpointsErrors, type ListEndpointsResponse, type ListEndpointsResponses, type ListParsersData, type ListParsersResponse, type ListParsersResponses, type MapData, type MapError, type MapErrors, type MapResponse, type MapResponses, type MaxTextLength, type ParseData, type ParseError, type ParseErrors, type ParseInputSchema0, type ParseResponse, type ParseResponses, type ParseSchema0, type ParserName, type ParserOptions, type PollSignUpData, type PollSignUpError, type PollSignUpErrors, type PollSignUpResponse, type PollSignUpResponses, type RevokeKeyData, type RevokeKeyError, type RevokeKeyErrors, type RevokeKeyResponse, type RevokeKeyResponses, type ScrapeData, type ScrapeError, type ScrapeErrors, type ScrapeInputSchema0, type ScrapeInputSchema1, type ScrapeInputSchema2, type ScrapeResponse, type ScrapeResponses, type ScrapeSchema0, type SearchData, type SearchDeveloperData, type SearchDeveloperError, type SearchDeveloperErrors, type SearchDeveloperResponse, type SearchDeveloperResponses, type SearchError, type SearchErrors, type SearchInputSchema0, type SearchInputSchema1, type SearchInputSchema2, type SearchResponse, type SearchResponses, type SearchSchema0, type SignUpData, type SignUpError, type SignUpErrors, type SignUpResponse, type SignUpResponses, Stophy, type StophyClientInput, StophyError, type StophyErrorCode, type StophyOptions, Surface, type _Error, Stophy as default };
5870
+ export { type BatchScrapeCancelData, type BatchScrapeCancelError, type BatchScrapeCancelErrors, type BatchScrapeCancelResponse, type BatchScrapeCancelResponses, type BatchScrapeData, type BatchScrapeError, type BatchScrapeErrors, type BatchScrapeInputSchema0, type BatchScrapeInputSchema1, type BatchScrapeInputSchema2, type BatchScrapeResponse, type BatchScrapeResponses, type BatchScrapeStatusData, type BatchScrapeStatusError, type BatchScrapeStatusErrors, type BatchScrapeStatusResponse, type BatchScrapeStatusResponses, type BatchScrapeStatusSchema0, type BrowserTaskData, type BrowserTaskError, type BrowserTaskErrors, type BrowserTaskInputSchema0, type BrowserTaskResponse, type BrowserTaskResponses, type BrowserTaskStatusData, type BrowserTaskStatusError, type BrowserTaskStatusErrors, type BrowserTaskStatusResponse, type BrowserTaskStatusResponses, type BrowserTaskStatusSchema0, type CallOptions, type ClientOptions, type CrawlCancelData, type CrawlCancelError, type CrawlCancelErrors, type CrawlCancelResponse, type CrawlCancelResponses, type CrawlData, type CrawlError, type CrawlErrors, type CrawlInputSchema0, type CrawlInputSchema1, type CrawlInputSchema2, type CrawlResponse, type CrawlResponses, type CrawlStatusData, type CrawlStatusError, type CrawlStatusErrors, type CrawlStatusResponse, type CrawlStatusResponses, type CrawlStatusSchema0, type ExtractData, type ExtractError, type ExtractErrors, type ExtractInputSchema0, type ExtractResponse, type ExtractResponses, type ExtractResultData, type ExtractResultError, type ExtractResultErrors, type ExtractResultResponse, type ExtractResultResponses, type ExtractResultSchema0, type FetchLike, type GetLimitsData, type GetLimitsError, type GetLimitsErrors, type GetLimitsResponse, type GetLimitsResponses, type GetLogsData, type GetLogsError, type GetLogsErrors, type GetLogsResponse, type GetLogsResponses, type GetUsageData, type GetUsageError, type GetUsageErrors, type GetUsageResponse, type GetUsageResponses, type IdempotencyKey, type ListEndpoints26Schema0, type ListEndpointsData, type ListEndpointsError, type ListEndpointsErrors, type ListEndpointsResponse, type ListEndpointsResponses, type ListParsersData, type ListParsersResponse, type ListParsersResponses, type MapData, type MapError, type MapErrors, type MapResponse, type MapResponses, type MaxTextLength, type ParseData, type ParseError, type ParseErrors, type ParseInputSchema0, type ParseResponse, type ParseResponses, type ParseSchema0, type ParserName, type ParserOptions, type PollSignUpData, type PollSignUpError, type PollSignUpErrors, type PollSignUpResponse, type PollSignUpResponses, type ResultsEnd, type ResultsOptions, type RevokeKeyData, type RevokeKeyError, type RevokeKeyErrors, type RevokeKeyResponse, type RevokeKeyResponses, type ScrapeData, type ScrapeError, type ScrapeErrors, type ScrapeInputSchema0, type ScrapeInputSchema1, type ScrapeInputSchema2, type ScrapeResponse, type ScrapeResponses, type ScrapeSchema0, type SearchData, type SearchDeveloperData, type SearchDeveloperError, type SearchDeveloperErrors, type SearchDeveloperResponse, type SearchDeveloperResponses, type SearchError, type SearchErrors, type SearchInputSchema0, type SearchInputSchema1, type SearchInputSchema2, type SearchResponse, type SearchResponses, type SearchSchema0, type SignUpData, type SignUpError, type SignUpErrors, type SignUpResponse, type SignUpResponses, Stophy, type StophyClientInput, StophyError, type StophyErrorCode, type StophyOptions, Surface, type _Error, Stophy as default };