@decodo/sdk-ts 2.6.1 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -481,6 +481,12 @@ console.log(progress.status); // 'pending' | 'done' | 'faulted' | 'cancelled' |
481
481
 
482
482
  const pages = await client.webScrapingApi.getCrawlResults(job.crawl_id);
483
483
 
484
+ const firstPage = await client.webScrapingApi.listCrawlPages(job.crawl_id);
485
+
486
+ if (firstPage.next) {
487
+ await client.webScrapingApi.listCrawlPages(job.crawl_id, { cursor: firstPage.next });
488
+ }
489
+
484
490
  await client.webScrapingApi.cancelCrawl(job.crawl_id);
485
491
  ```
486
492
 
@@ -130,7 +130,7 @@ var HttpClient = class {
130
130
  errorBody = await res.json();
131
131
  } catch {
132
132
  }
133
- const message = errorBody?.message ?? `HTTP ${res.status}`;
133
+ const message = errorBody?.message ?? errorBody?.error ?? `HTTP ${res.status}`;
134
134
  if (res.status === 401 || res.status === 403) {
135
135
  throw new AuthenticationError(message);
136
136
  }
@@ -2778,6 +2778,18 @@ var DATA_API_ROUTES = {
2778
2778
  var DEFAULT_CRAWL_POLL_INTERVAL_MS = 5e3;
2779
2779
  var DEFAULT_CRAWL_TIMEOUT_MS = 36e5;
2780
2780
  var sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
2781
+ var nextCursor = (next) => {
2782
+ if (!next) {
2783
+ return void 0;
2784
+ }
2785
+ const cursor = new URL(next).searchParams.get("cursor");
2786
+ if (!cursor) {
2787
+ throw new Error(
2788
+ `Crawl results next link has no cursor: ${next}. Use getCrawlResults() to fetch every page.`
2789
+ );
2790
+ }
2791
+ return cursor;
2792
+ };
2781
2793
  var WebScrapingApi = class {
2782
2794
  http;
2783
2795
  schemas;
@@ -2854,6 +2866,20 @@ var WebScrapingApi = class {
2854
2866
  this.crawlPath("getCrawlStatus", crawlId, "getCrawlStatus")
2855
2867
  );
2856
2868
  }
2869
+ async listCrawlPages(crawlId, { cursor, content = true } = {}) {
2870
+ const query = {};
2871
+ if (content) {
2872
+ query.type = "content";
2873
+ }
2874
+ if (cursor) {
2875
+ query.cursor = cursor;
2876
+ }
2877
+ const res = await this.http.get(
2878
+ this.crawlPath("listCrawlPages", crawlId, "listCrawlPages"),
2879
+ query
2880
+ );
2881
+ return { pages: res.url, next: nextCursor(res.next), total: res.total };
2882
+ }
2857
2883
  async getCrawlResults(crawlId, { content = true } = {}) {
2858
2884
  const path = this.crawlPath("listCrawlPages", crawlId, "getCrawlResults");
2859
2885
  const pages = [];
@@ -975,6 +975,9 @@ export type CrawlOptions = {
975
975
  export type CrawlResultsOptions = {
976
976
  content?: boolean;
977
977
  };
978
+ export type CrawlPagesOptions = CrawlResultsOptions & {
979
+ cursor?: string;
980
+ };
978
981
  export type ResultEntry = {
979
982
  content: unknown;
980
983
  status_code: number;
@@ -1033,6 +1036,11 @@ export type TaskResultsResponse = {
1033
1036
  results: ResultEntry[];
1034
1037
  };
1035
1038
  export type CrawlPage = ListCrawlPagesResponse["url"][number];
1039
+ export type CrawlPageList = {
1040
+ pages: CrawlPage[];
1041
+ next?: string;
1042
+ total?: number;
1043
+ };
1036
1044
  export type CrawlResult = {
1037
1045
  status: GetCrawlStatusResponse;
1038
1046
  pages: CrawlPage[];
@@ -1059,6 +1067,7 @@ export declare class WebScrapingApi {
1059
1067
  map(params: MapSiteRequest): Promise<MapSiteResponse>;
1060
1068
  startCrawl(params: StartCrawlRequest): Promise<StartCrawlResponse>;
1061
1069
  getCrawlStatus(crawlId: string): Promise<GetCrawlStatusResponse>;
1070
+ listCrawlPages(crawlId: string, { cursor, content }?: CrawlPagesOptions): Promise<CrawlPageList>;
1062
1071
  getCrawlResults(crawlId: string, { content }?: CrawlResultsOptions): Promise<CrawlPage[]>;
1063
1072
  cancelCrawl(crawlId: string): Promise<CancelCrawlResponse>;
1064
1073
  crawl(params: StartCrawlRequest, { pollInterval, timeout, }?: CrawlOptions): Promise<CrawlResult>;
@@ -3,8 +3,8 @@ import type { DecodoSchema } from '../schema/types.js';
3
3
  import { dataApiEndpoints } from '../generated/data-api.js';
4
4
  import type { CancelCrawlResponse, GetCrawlStatusResponse, MapSiteRequest, MapSiteResponse, RunSearchRequest, RunSearchResponse, StartCrawlRequest, StartCrawlResponse } from '../generated/data-api.js';
5
5
  import type { ScrapeRequest, BatchRequest } from '../generated/targets.js';
6
- import type { CrawlOptions, CrawlResultsOptions } from '../types/requests.js';
7
- import type { CrawlPage, CrawlResult, SyncResponse, AsyncTaskResponse, BatchResponse, TaskMetadata, TaskResultsResponse } from '../types/responses.js';
6
+ import type { CrawlOptions, CrawlPagesOptions, CrawlResultsOptions } from '../types/requests.js';
7
+ import type { CrawlPage, CrawlPageList, CrawlResult, SyncResponse, AsyncTaskResponse, BatchResponse, TaskMetadata, TaskResultsResponse } from '../types/responses.js';
8
8
  export type WebScrapingApiRoutes = {
9
9
  scrape: string;
10
10
  task: string;
@@ -29,6 +29,7 @@ export declare class WebScrapingApi {
29
29
  map(params: MapSiteRequest): Promise<MapSiteResponse>;
30
30
  startCrawl(params: StartCrawlRequest): Promise<StartCrawlResponse>;
31
31
  getCrawlStatus(crawlId: string): Promise<GetCrawlStatusResponse>;
32
+ listCrawlPages(crawlId: string, { cursor, content }?: CrawlPagesOptions): Promise<CrawlPageList>;
32
33
  getCrawlResults(crawlId: string, { content }?: CrawlResultsOptions): Promise<CrawlPage[]>;
33
34
  cancelCrawl(crawlId: string): Promise<CancelCrawlResponse>;
34
35
  crawl(params: StartCrawlRequest, { pollInterval, timeout, }?: CrawlOptions): Promise<CrawlResult>;
@@ -14,6 +14,16 @@ export const DATA_API_ROUTES = {
14
14
  const DEFAULT_CRAWL_POLL_INTERVAL_MS = 5_000;
15
15
  const DEFAULT_CRAWL_TIMEOUT_MS = 3_600_000;
16
16
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
17
+ const nextCursor = (next) => {
18
+ if (!next) {
19
+ return undefined;
20
+ }
21
+ const cursor = new URL(next).searchParams.get('cursor');
22
+ if (!cursor) {
23
+ throw new Error(`Crawl results next link has no cursor: ${next}. Use getCrawlResults() to fetch every page.`);
24
+ }
25
+ return cursor;
26
+ };
17
27
  export class WebScrapingApi {
18
28
  http;
19
29
  schemas;
@@ -72,6 +82,17 @@ export class WebScrapingApi {
72
82
  async getCrawlStatus(crawlId) {
73
83
  return this.http.get(this.crawlPath('getCrawlStatus', crawlId, 'getCrawlStatus'));
74
84
  }
85
+ async listCrawlPages(crawlId, { cursor, content = true } = {}) {
86
+ const query = {};
87
+ if (content) {
88
+ query.type = 'content';
89
+ }
90
+ if (cursor) {
91
+ query.cursor = cursor;
92
+ }
93
+ const res = await this.http.get(this.crawlPath('listCrawlPages', crawlId, 'listCrawlPages'), query);
94
+ return { pages: res.url, next: nextCursor(res.next), total: res.total };
95
+ }
75
96
  async getCrawlResults(crawlId, { content = true } = {}) {
76
97
  const path = this.crawlPath('listCrawlPages', crawlId, 'getCrawlResults');
77
98
  const pages = [];
package/build/esm/http.js CHANGED
@@ -47,7 +47,7 @@ export class HttpClient {
47
47
  catch {
48
48
  // response body wasn't JSON
49
49
  }
50
- const message = errorBody?.message ?? `HTTP ${res.status}`;
50
+ const message = errorBody?.message ?? errorBody?.error ?? `HTTP ${res.status}`;
51
51
  if (res.status === 401 || res.status === 403) {
52
52
  throw new AuthenticationError(message);
53
53
  }
@@ -9,7 +9,7 @@ export type { TargetString, TargetParamsMap, TargetMeta, ScrapeRequest, BatchReq
9
9
  export { targets, targetMeta, Target, } from './generated/targets.js';
10
10
  export { parameterMeta } from './generated/parameters.js';
11
11
  export type { ParameterMeta } from './generated/parameters.js';
12
- export type { SyncResponse, AsyncTaskResponse, BatchResponse, TaskMetadata, TaskResultsResponse, TaskStatus, ResultEntry, CrawlPage, CrawlResult, } from './types/responses.js';
13
- export type { CrawlOptions, CrawlResultsOptions } from './types/requests.js';
12
+ export type { SyncResponse, AsyncTaskResponse, BatchResponse, TaskMetadata, TaskResultsResponse, TaskStatus, ResultEntry, CrawlPage, CrawlPageList, CrawlResult, } from './types/responses.js';
13
+ export type { CrawlOptions, CrawlPagesOptions, CrawlResultsOptions, } from './types/requests.js';
14
14
  export type { RunSearchRequest, RunSearchResponse, MapSiteRequest, MapSiteResponse, StartCrawlRequest, StartCrawlResponse, GetCrawlStatusResponse, ListCrawlPagesResponse, CancelCrawlResponse, } from './generated/data-api.js';
15
15
  export { DecodoError, AuthenticationError, RateLimitError, ValidationError, TimeoutError, } from './errors.js';
@@ -6,3 +6,6 @@ export type CrawlOptions = {
6
6
  export type CrawlResultsOptions = {
7
7
  content?: boolean;
8
8
  };
9
+ export type CrawlPagesOptions = CrawlResultsOptions & {
10
+ cursor?: string;
11
+ };
@@ -57,11 +57,17 @@ export type TaskResultsResponse = {
57
57
  results: ResultEntry[];
58
58
  };
59
59
  export type ErrorResponse = {
60
- status: string;
61
- message: string;
60
+ status?: string;
61
+ message?: string;
62
+ error?: string;
62
63
  errors?: unknown[];
63
64
  };
64
65
  export type CrawlPage = ListCrawlPagesResponse['url'][number];
66
+ export type CrawlPageList = {
67
+ pages: CrawlPage[];
68
+ next?: string;
69
+ total?: number;
70
+ };
65
71
  export type CrawlResult = {
66
72
  status: GetCrawlStatusResponse;
67
73
  pages: CrawlPage[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decodo/sdk-ts",
3
- "version": "2.6.1",
3
+ "version": "2.7.0",
4
4
  "description": "Official TypeScript SDK for the Decodo APIs",
5
5
  "license": "MIT",
6
6
  "repository": {