@datafuel/sdk 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -10
- package/dist/index.cjs +284 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +321 -8
- package/dist/index.d.ts +321 -8
- package/dist/index.js +282 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +215 -17
- package/src/core.ts +172 -4
- package/src/errors.ts +47 -2
- package/src/index.ts +30 -1
- package/src/models.ts +247 -1
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,8 @@ interface Proxy {
|
|
|
24
24
|
asn?: string;
|
|
25
25
|
/**
|
|
26
26
|
* Sticky session: the same exit across requests, `ttl` in seconds. Read by
|
|
27
|
-
* `scrape` and
|
|
27
|
+
* `scrape`, `map`, URL jobs and crawls, and sent in attributes rather than
|
|
28
|
+
* the envelope.
|
|
28
29
|
*/
|
|
29
30
|
sessionId?: string;
|
|
30
31
|
ttl?: number;
|
|
@@ -53,6 +54,7 @@ interface ScrapeOptions {
|
|
|
53
54
|
jsRendering?: boolean;
|
|
54
55
|
waitFor?: string;
|
|
55
56
|
waitForTimeoutMs?: number;
|
|
57
|
+
/** An object keyed by action, e.g. `{ click: "#more" }`. `df.jsInstructions()` lists them. */
|
|
56
58
|
jsInstructions?: unknown;
|
|
57
59
|
blockResource?: string;
|
|
58
60
|
/** Markdown only: always render just the `<main>` / `<article>` container. */
|
|
@@ -198,6 +200,9 @@ interface CrawlStatus {
|
|
|
198
200
|
total_cost: number;
|
|
199
201
|
/** Whether the crawl reached a final state. */
|
|
200
202
|
done: boolean;
|
|
203
|
+
/** RFC 3339. */
|
|
204
|
+
created_at?: string;
|
|
205
|
+
updated_at?: string;
|
|
201
206
|
}
|
|
202
207
|
/** One page of crawl results. */
|
|
203
208
|
interface CrawlResultsPage {
|
|
@@ -220,6 +225,11 @@ interface JobStatus {
|
|
|
220
225
|
total_cost: number;
|
|
221
226
|
done: boolean;
|
|
222
227
|
}
|
|
228
|
+
/** A cancelled job or crawl: its final progress and what was refunded. */
|
|
229
|
+
interface CancelResult extends JobStatus {
|
|
230
|
+
refunded_tasks: number;
|
|
231
|
+
refunded_credits: number;
|
|
232
|
+
}
|
|
223
233
|
/** Every task of a job. A job completes even when some of its tasks failed. */
|
|
224
234
|
interface JobResults {
|
|
225
235
|
id: string;
|
|
@@ -228,15 +238,228 @@ interface JobResults {
|
|
|
228
238
|
tasks_complete: number;
|
|
229
239
|
tasks: Result[];
|
|
230
240
|
}
|
|
241
|
+
/** A task type, as the list and analytics filters take it. */
|
|
242
|
+
type TaskType = "unlocker" | "llm_scraping" | "serp" | "map" | "crawl" | (string & {});
|
|
243
|
+
/** Filters shared by {@link DataFuel.listJobs} and {@link DataFuel.listTasks}. */
|
|
244
|
+
interface ListOptions {
|
|
245
|
+
status?: Status;
|
|
246
|
+
type?: TaskType;
|
|
247
|
+
/** Created on or after this day (UTC). A Date is sent as its UTC day. */
|
|
248
|
+
startDate?: string | Date;
|
|
249
|
+
/** Created on or before this day (UTC, inclusive). */
|
|
250
|
+
endDate?: string | Date;
|
|
251
|
+
/** Items per page. API default 50, max 200. */
|
|
252
|
+
limit?: number;
|
|
253
|
+
/** `nextCursor` of the previous page. */
|
|
254
|
+
cursor?: string;
|
|
255
|
+
}
|
|
256
|
+
/** {@link ListOptions} plus the job or crawl the tasks belong to. */
|
|
257
|
+
interface ListTasksOptions extends ListOptions {
|
|
258
|
+
jobId?: string;
|
|
259
|
+
}
|
|
260
|
+
/** A job or crawl in a list, with the same counters as {@link JobStatus}. */
|
|
261
|
+
interface JobSummary extends JobStatus {
|
|
262
|
+
id: string;
|
|
263
|
+
/** `crawl` for a crawl, otherwise the task type of the batch. */
|
|
264
|
+
type: TaskType;
|
|
265
|
+
/** RFC 3339. */
|
|
266
|
+
created_at: string;
|
|
267
|
+
updated_at: string;
|
|
268
|
+
}
|
|
269
|
+
/** One page of jobs, newest first. */
|
|
270
|
+
interface JobsPage {
|
|
271
|
+
jobs: JobSummary[];
|
|
272
|
+
/** Absent on the last page. */
|
|
273
|
+
nextCursor?: string;
|
|
274
|
+
}
|
|
275
|
+
/** A task in a list. It has no result: fetch that with {@link DataFuel.getTask}. */
|
|
276
|
+
interface TaskSummary {
|
|
277
|
+
id: string;
|
|
278
|
+
/** `null` for a task created on its own rather than by a job or crawl. */
|
|
279
|
+
job_id: string | null;
|
|
280
|
+
type: TaskType;
|
|
281
|
+
status: Status;
|
|
282
|
+
/** Absent for `llm_scraping` and `serp`. */
|
|
283
|
+
url?: string;
|
|
284
|
+
/** Charged when queued; a failed task is refunded. */
|
|
285
|
+
credit_cost: number;
|
|
286
|
+
/** RFC 3339. */
|
|
287
|
+
created_at: string;
|
|
288
|
+
processed_at?: string;
|
|
289
|
+
failed_at?: string;
|
|
290
|
+
}
|
|
291
|
+
/** One page of tasks, newest first. */
|
|
292
|
+
interface TasksPage {
|
|
293
|
+
tasks: TaskSummary[];
|
|
294
|
+
/** Absent on the last page. */
|
|
295
|
+
nextCursor?: string;
|
|
296
|
+
}
|
|
297
|
+
/** What moved credits on the account. */
|
|
298
|
+
type TransactionOperation = "plan_assignment" | "purchase" | "usage" | "refund" | "topup" | "expiry" | "adjustment" | (string & {});
|
|
299
|
+
/** Filters and paging for {@link DataFuel.transactions}. */
|
|
300
|
+
interface TransactionsOptions {
|
|
301
|
+
operation?: TransactionOperation;
|
|
302
|
+
startDate?: string | Date;
|
|
303
|
+
endDate?: string | Date;
|
|
304
|
+
/** 1-based. API default 1. */
|
|
305
|
+
page?: number;
|
|
306
|
+
/** API default 10, max 200. */
|
|
307
|
+
limit?: number;
|
|
308
|
+
}
|
|
309
|
+
/** One credit movement. `amount` is negative for usage and expiry. */
|
|
310
|
+
interface Transaction {
|
|
311
|
+
id: number;
|
|
312
|
+
amount: number;
|
|
313
|
+
/** The part of `amount` that moved plan credits, same sign; the rest moved pay-as-you-go credits. */
|
|
314
|
+
plan_amount?: number;
|
|
315
|
+
operation: TransactionOperation;
|
|
316
|
+
/** What `reference_id` points to, e.g. `task_id` or `job_id`. */
|
|
317
|
+
reference_type: string;
|
|
318
|
+
reference_id: string;
|
|
319
|
+
/** The balance right after this movement. */
|
|
320
|
+
balance_after?: number;
|
|
321
|
+
/** RFC 3339. */
|
|
322
|
+
created_at: string;
|
|
323
|
+
}
|
|
324
|
+
/** Total of one operation over the whole filtered range, not just the page. */
|
|
325
|
+
interface TransactionSum {
|
|
326
|
+
operation: TransactionOperation;
|
|
327
|
+
total: number;
|
|
328
|
+
count: number;
|
|
329
|
+
}
|
|
330
|
+
/** One page of credit movements, newest first. */
|
|
331
|
+
interface TransactionsPage {
|
|
332
|
+
transactions: Transaction[];
|
|
333
|
+
/** Movements matching the filters across all pages. */
|
|
334
|
+
total_count: number;
|
|
335
|
+
sums: TransactionSum[];
|
|
336
|
+
}
|
|
337
|
+
/** Range and grouping for {@link DataFuel.analytics}. */
|
|
338
|
+
interface AnalyticsOptions {
|
|
339
|
+
/** API default 30 days ago. The range may span at most 365 days. */
|
|
340
|
+
startDate?: string | Date;
|
|
341
|
+
/** Inclusive. API default today. */
|
|
342
|
+
endDate?: string | Date;
|
|
343
|
+
/** Time series bucket. API default `daily`. */
|
|
344
|
+
interval?: "hourly" | "daily" | "weekly" | "monthly";
|
|
345
|
+
/** Restrict to one task type. */
|
|
346
|
+
module?: TaskType;
|
|
347
|
+
}
|
|
348
|
+
/** Task counts and net credits of one slice. Failed tasks are refunded and count 0 credits. */
|
|
349
|
+
interface AnalyticsCounts {
|
|
350
|
+
total: number;
|
|
351
|
+
completed: number;
|
|
352
|
+
failed: number;
|
|
353
|
+
credits_used: number;
|
|
354
|
+
}
|
|
355
|
+
/** Tasks by the HTTP status the target answered. `status_code` 0 means no answer (timeout, DNS). */
|
|
356
|
+
interface StatusCodeBreakdown {
|
|
357
|
+
status_code: number;
|
|
358
|
+
count: number;
|
|
359
|
+
completed: number;
|
|
360
|
+
failed: number;
|
|
361
|
+
credits_used: number;
|
|
362
|
+
avg_credits_per_request: number;
|
|
363
|
+
}
|
|
364
|
+
/** The same figures for the equally long period before, and the change in percent. */
|
|
365
|
+
interface PreviousPeriod {
|
|
366
|
+
credits_used: number;
|
|
367
|
+
fulfilled_requests: number;
|
|
368
|
+
failed_requests: number;
|
|
369
|
+
failed_percentage: number;
|
|
370
|
+
efficiency_score: number;
|
|
371
|
+
credits_used_change: number;
|
|
372
|
+
fulfilled_requests_change: number;
|
|
373
|
+
failed_requests_change: number;
|
|
374
|
+
efficiency_score_change: number;
|
|
375
|
+
}
|
|
376
|
+
/** Usage over a date range. Percentages are 0-100. */
|
|
377
|
+
interface Analytics {
|
|
378
|
+
summary: {
|
|
379
|
+
total_tasks: number;
|
|
380
|
+
credits_used: number;
|
|
381
|
+
fulfilled_requests: number;
|
|
382
|
+
failed_requests: number;
|
|
383
|
+
failed_percentage: number;
|
|
384
|
+
success_rate: number;
|
|
385
|
+
efficiency_score: number;
|
|
386
|
+
avg_credits_per_request: number;
|
|
387
|
+
avg_duration_ms: number;
|
|
388
|
+
previous_period?: PreviousPeriod | null;
|
|
389
|
+
};
|
|
390
|
+
timeseries: (AnalyticsCounts & {
|
|
391
|
+
period: string;
|
|
392
|
+
})[];
|
|
393
|
+
by_module: (AnalyticsCounts & {
|
|
394
|
+
module: string;
|
|
395
|
+
success_rate: number;
|
|
396
|
+
avg_credits_per_request: number;
|
|
397
|
+
avg_duration_ms: number;
|
|
398
|
+
status_codes: StatusCodeBreakdown[];
|
|
399
|
+
})[];
|
|
400
|
+
top_targets: (AnalyticsCounts & {
|
|
401
|
+
target: string;
|
|
402
|
+
})[];
|
|
403
|
+
by_status_code: StatusCodeBreakdown[];
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Credits by pool. Plan credits are spent first, roll over when the plan renews and
|
|
407
|
+
* expire if it is not renewed. Pay-as-you-go credits come from credit packs, are spent
|
|
408
|
+
* after plan credits and never expire.
|
|
409
|
+
*/
|
|
410
|
+
interface BalanceSplit {
|
|
411
|
+
/** Total spendable credits: `plan_balance` plus `payg_balance`. */
|
|
412
|
+
balance: number;
|
|
413
|
+
plan_balance: number;
|
|
414
|
+
payg_balance: number;
|
|
415
|
+
}
|
|
231
416
|
/** The account behind the API key. */
|
|
232
417
|
interface Profile {
|
|
233
418
|
email: string;
|
|
234
419
|
username: string;
|
|
235
420
|
current_concurrency: number;
|
|
236
421
|
concurrency_limit: number;
|
|
422
|
+
/** Total spendable credits: `plan_credit_balance` plus `payg_credit_balance`. */
|
|
237
423
|
credit_balance: number;
|
|
424
|
+
/** Spent first; expire if the plan is not renewed. */
|
|
425
|
+
plan_credit_balance?: number;
|
|
426
|
+
/** Spent after plan credits; never expire. */
|
|
427
|
+
payg_credit_balance?: number;
|
|
238
428
|
monthly_credit_limit: number;
|
|
239
429
|
}
|
|
430
|
+
/** One argument of a browser action. */
|
|
431
|
+
interface JsInstructionArg {
|
|
432
|
+
name: string;
|
|
433
|
+
type: string;
|
|
434
|
+
values?: string[];
|
|
435
|
+
required: boolean;
|
|
436
|
+
}
|
|
437
|
+
/** One browser action `jsInstructions` accepts. */
|
|
438
|
+
interface JsInstruction {
|
|
439
|
+
action: string;
|
|
440
|
+
description: string;
|
|
441
|
+
/** Shape of the value: scalar, array or object. */
|
|
442
|
+
value: string;
|
|
443
|
+
args: JsInstructionArg[];
|
|
444
|
+
/** Whether it can target an element inside an iframe. */
|
|
445
|
+
iframe: boolean;
|
|
446
|
+
example: unknown;
|
|
447
|
+
}
|
|
448
|
+
/** A named proxy location: a city, or an ASN. */
|
|
449
|
+
interface ProxyLocation {
|
|
450
|
+
code: string;
|
|
451
|
+
name: string;
|
|
452
|
+
}
|
|
453
|
+
/** A proxy country with its regions and their cities. */
|
|
454
|
+
interface ProxyCountry {
|
|
455
|
+
code: string;
|
|
456
|
+
name: string;
|
|
457
|
+
regions: {
|
|
458
|
+
code: string;
|
|
459
|
+
name: string;
|
|
460
|
+
cities: ProxyLocation[];
|
|
461
|
+
}[];
|
|
462
|
+
}
|
|
240
463
|
/** One task type or LLM engine, and whether it accepts new work. */
|
|
241
464
|
interface Capability {
|
|
242
465
|
name: string;
|
|
@@ -265,13 +488,14 @@ declare class Capabilities {
|
|
|
265
488
|
|
|
266
489
|
declare const DEFAULT_BASE_URL = "https://scraping-api.datafuel.ai/api/v1";
|
|
267
490
|
/** Kept in step with package.json by a test; see test/hardening.test.ts. */
|
|
268
|
-
declare const VERSION = "0.
|
|
491
|
+
declare const VERSION = "0.3.0";
|
|
269
492
|
/** Options for the llm_scraping module, which reads its proxy country here. */
|
|
270
493
|
interface AskOptions {
|
|
271
494
|
engine: Engine | string;
|
|
272
495
|
websearch?: boolean;
|
|
273
496
|
followUp?: string;
|
|
274
497
|
country?: string;
|
|
498
|
+
location?: string;
|
|
275
499
|
format?: string;
|
|
276
500
|
}
|
|
277
501
|
/** Options for `map`. */
|
|
@@ -303,6 +527,40 @@ interface CrawlOptions extends ScrapeOptions {
|
|
|
303
527
|
/** Pages in flight, default 5. */
|
|
304
528
|
concurrency?: number;
|
|
305
529
|
}
|
|
530
|
+
/** Options for `search`, the Google SERP module. Proxy type is not used. */
|
|
531
|
+
interface SearchOptions {
|
|
532
|
+
/** Google `gl`, e.g. "us". */
|
|
533
|
+
country?: string;
|
|
534
|
+
/** Google `hl`, e.g. "en". */
|
|
535
|
+
language?: string;
|
|
536
|
+
/** Canonical location name. Give at most one of location, uule, lat/lon. */
|
|
537
|
+
location?: string;
|
|
538
|
+
/** 1-based, default 1. */
|
|
539
|
+
page?: number;
|
|
540
|
+
/** e.g. "google.de". */
|
|
541
|
+
googleDomain?: string;
|
|
542
|
+
uule?: string;
|
|
543
|
+
lat?: number;
|
|
544
|
+
lon?: number;
|
|
545
|
+
/** Metres around lat/lon or location, max 1000. */
|
|
546
|
+
radius?: number;
|
|
547
|
+
cr?: string;
|
|
548
|
+
lr?: string;
|
|
549
|
+
tbs?: string;
|
|
550
|
+
safe?: "active" | "off";
|
|
551
|
+
nfpr?: boolean;
|
|
552
|
+
filter?: boolean;
|
|
553
|
+
uds?: string;
|
|
554
|
+
kgmid?: string;
|
|
555
|
+
si?: string;
|
|
556
|
+
ludocid?: string;
|
|
557
|
+
lsig?: string;
|
|
558
|
+
ibp?: string;
|
|
559
|
+
/** Exit country of the request. */
|
|
560
|
+
proxyCountry?: string;
|
|
561
|
+
/** Default json. */
|
|
562
|
+
format?: "json" | "html" | "markdown";
|
|
563
|
+
}
|
|
306
564
|
|
|
307
565
|
/** The client. It only moves bytes; `core` decides what goes on the wire. */
|
|
308
566
|
|
|
@@ -332,7 +590,8 @@ interface ClientOptions {
|
|
|
332
590
|
*
|
|
333
591
|
* Pick the call by the shape of the work: one URL is {@link scrape}, a site's
|
|
334
592
|
* URL list is {@link map}, many pages from a start URL is {@link crawl}, a list
|
|
335
|
-
* of known URLs is {@link runJob}, a question for an AI engine is {@link ask}
|
|
593
|
+
* of known URLs is {@link runJob}, a question for an AI engine is {@link ask}, a
|
|
594
|
+
* Google search is {@link search}.
|
|
336
595
|
*
|
|
337
596
|
* Every write carries an `Idempotency-Key`, generated per request, so a retry
|
|
338
597
|
* attaches to the task already running instead of charging twice.
|
|
@@ -375,6 +634,8 @@ declare class DataFuel {
|
|
|
375
634
|
getTask(taskId: string, options?: CallOptions): Promise<Result>;
|
|
376
635
|
/** Send a prompt to an AI engine and return its answer. */
|
|
377
636
|
ask(prompt: string, options: AskOptions & CallOptions): Promise<Result>;
|
|
637
|
+
/** Run a Google search and return the results page, parsed to JSON by default. */
|
|
638
|
+
search(query: string, options?: SearchOptions & CallOptions): Promise<Result>;
|
|
378
639
|
/**
|
|
379
640
|
* List the URLs of a site without scraping them.
|
|
380
641
|
*
|
|
@@ -390,6 +651,11 @@ declare class DataFuel {
|
|
|
390
651
|
* refunded. Unset limits use the API defaults: 100 pages, depth 3, 5 in flight.
|
|
391
652
|
*/
|
|
392
653
|
startCrawl(url: string, options?: CrawlOptions & CallOptions): Promise<string>;
|
|
654
|
+
/**
|
|
655
|
+
* Stop a crawl. Queued pages are refunded, pages in flight finish and bill.
|
|
656
|
+
* Throws {@link JobNotCancellable} when it already finished.
|
|
657
|
+
*/
|
|
658
|
+
cancelCrawl(crawlId: string, options?: CallOptions): Promise<CancelResult>;
|
|
393
659
|
/** Return the progress of a crawl. */
|
|
394
660
|
getCrawl(crawlId: string, options?: CallOptions): Promise<CrawlStatus>;
|
|
395
661
|
/** One page of results, in discovery order. `limit` unset uses the API default. */
|
|
@@ -430,8 +696,17 @@ declare class DataFuel {
|
|
|
430
696
|
createAskJob(prompts: string[], options: AskOptions & CallOptions & {
|
|
431
697
|
sequential?: boolean;
|
|
432
698
|
}): Promise<string>;
|
|
699
|
+
/** Queue a batch of Google searches and return the job id. */
|
|
700
|
+
createSearchJob(queries: string[], options?: SearchOptions & CallOptions & {
|
|
701
|
+
sequential?: boolean;
|
|
702
|
+
}): Promise<string>;
|
|
433
703
|
/** Return the progress of a job. */
|
|
434
704
|
getJob(jobId: string, options?: CallOptions): Promise<JobStatus>;
|
|
705
|
+
/**
|
|
706
|
+
* Stop a job. Queued tasks are refunded, tasks in flight finish and bill.
|
|
707
|
+
* Throws {@link JobNotCancellable} when it already finished.
|
|
708
|
+
*/
|
|
709
|
+
cancelJob(jobId: string, options?: CallOptions): Promise<CancelResult>;
|
|
435
710
|
/**
|
|
436
711
|
* Return the per-task results of a job.
|
|
437
712
|
*
|
|
@@ -439,6 +714,13 @@ declare class DataFuel {
|
|
|
439
714
|
* `task.raiseForStatus()` per task.
|
|
440
715
|
*/
|
|
441
716
|
jobResults(jobId: string, options?: CallOptions): Promise<JobResults>;
|
|
717
|
+
/** One page of your jobs and crawls, newest first. Pass `nextCursor` back as `cursor`. */
|
|
718
|
+
listJobs(options?: ListOptions & CallOptions): Promise<JobsPage>;
|
|
719
|
+
/**
|
|
720
|
+
* One page of your tasks, newest first, including those of jobs and crawls.
|
|
721
|
+
* Items carry no result: fetch it with {@link getTask}.
|
|
722
|
+
*/
|
|
723
|
+
listTasks(options?: ListTasksOptions & CallOptions): Promise<TasksPage>;
|
|
442
724
|
/** Poll until the job is done. Without `timeoutMs` it waits indefinitely. */
|
|
443
725
|
waitJob(jobId: string, options?: CallOptions): Promise<JobStatus>;
|
|
444
726
|
/** Create a job, wait for it, and return its results. */
|
|
@@ -449,10 +731,33 @@ declare class DataFuel {
|
|
|
449
731
|
runAskJob(prompts: string[], options: AskOptions & CallOptions & {
|
|
450
732
|
sequential?: boolean;
|
|
451
733
|
}): Promise<JobResults>;
|
|
452
|
-
/**
|
|
734
|
+
/** Create a search job, wait for it, and return its results. */
|
|
735
|
+
runSearchJob(queries: string[], options?: SearchOptions & CallOptions & {
|
|
736
|
+
sequential?: boolean;
|
|
737
|
+
}): Promise<JobResults>;
|
|
738
|
+
/** Which task types and LLM engines are switched on right now. Needs no key. */
|
|
453
739
|
capabilities(options?: CallOptions): Promise<Capabilities>;
|
|
454
|
-
/**
|
|
740
|
+
/** The browser actions `jsInstructions` accepts, with their arguments. Needs no key. */
|
|
741
|
+
jsInstructions(options?: CallOptions): Promise<JsInstruction[]>;
|
|
742
|
+
/** Countries, regions and cities a proxy type can exit from. */
|
|
743
|
+
proxyLocations(options?: CallOptions & {
|
|
744
|
+
proxyType?: string;
|
|
745
|
+
}): Promise<ProxyCountry[]>;
|
|
746
|
+
/** ASNs a proxy type can exit from in one country (ISO 3166-1 alpha-2). */
|
|
747
|
+
proxyAsns(country: string, options?: CallOptions & {
|
|
748
|
+
proxyType?: string;
|
|
749
|
+
}): Promise<ProxyLocation[]>;
|
|
750
|
+
/** Remaining credits: plan and pay-as-you-go together. */
|
|
455
751
|
balance(options?: CallOptions): Promise<number>;
|
|
752
|
+
/** Remaining credits by pool: plan credits (spent first) and pay-as-you-go credits. */
|
|
753
|
+
balanceSplit(options?: CallOptions): Promise<BalanceSplit>;
|
|
754
|
+
/**
|
|
755
|
+
* Credit movements, newest first: plan assignments, credit pack purchases, usage, refunds, expiry.
|
|
756
|
+
* `sums` totals each operation over the whole range, not just this page.
|
|
757
|
+
*/
|
|
758
|
+
transactions(options?: TransactionsOptions & CallOptions): Promise<TransactionsPage>;
|
|
759
|
+
/** Usage over a date range: totals, a time series and breakdowns. Default: the last 30 days. */
|
|
760
|
+
analytics(options?: AnalyticsOptions & CallOptions): Promise<Analytics>;
|
|
456
761
|
/** The account behind the API key. */
|
|
457
762
|
me(options?: CallOptions): Promise<Profile>;
|
|
458
763
|
/**
|
|
@@ -486,10 +791,12 @@ declare class NoApiKey extends DataFuelError {
|
|
|
486
791
|
/** The request never got an answer: DNS, connection, abort, read timeout. */
|
|
487
792
|
declare class TransportError extends DataFuelError {
|
|
488
793
|
}
|
|
794
|
+
/** The `code` of an API error. The API may add codes; unknown ones pass through. */
|
|
795
|
+
type ErrorCode = "UNAUTHORIZED" | "INVALID_API_KEY" | "FORBIDDEN" | "INSUFFICIENT_CREDITS" | "RATE_LIMIT_EXCEEDED" | "CONCURRENCY_LIMIT_REACHED" | "INVALID_REQUEST_BODY" | "INVALID_ATTRIBUTES" | "MISSING_TARGET" | "UNSUPPORTED_TASK_TYPE" | "JOB_REQUIRES_MULTIPLE_TARGETS" | "INVALID_IDEMPOTENCY_KEY" | "IDEMPOTENCY_KEY_REUSED" | "INVALID_TASK_ID" | "INVALID_JOB_ID" | "TASK_NOT_FOUND" | "JOB_NOT_FOUND" | "CRAWL_NOT_FOUND" | "JOB_NOT_CANCELLABLE" | "INVALID_CRAWL_PATTERN" | "CRAWL_UNSUPPORTED_OPTION" | "INVALID_CURSOR" | "INVALID_QUERY_PARAM" | "INVALID_PROXY_TYPE" | "INVALID_COUNTRY" | "INVALID_DATE_FORMAT" | "INVALID_DATE_RANGE" | "INVALID_INTERVAL" | "MODULE_UNAVAILABLE" | "ENGINE_UNAVAILABLE" | "API_KEY_RESET_FAILED" | "TASK_RESULT_TIMEOUT" | "INTERNAL_ERROR" | (string & {});
|
|
489
796
|
/** A non-2xx answer from the API itself. */
|
|
490
797
|
declare class APIError extends DataFuelError {
|
|
491
798
|
readonly status: number;
|
|
492
|
-
readonly code:
|
|
799
|
+
readonly code: ErrorCode;
|
|
493
800
|
/** Seconds the API asked us to wait, from Retry-After. 0 when absent. */
|
|
494
801
|
readonly retryAfter: number;
|
|
495
802
|
constructor(status: number, code: string, message: string, retryAfter?: number);
|
|
@@ -497,6 +804,9 @@ declare class APIError extends DataFuelError {
|
|
|
497
804
|
/** 401: the API key is missing or invalid. */
|
|
498
805
|
declare class Unauthorized extends APIError {
|
|
499
806
|
}
|
|
807
|
+
/** 403 FORBIDDEN: the account is inactive. */
|
|
808
|
+
declare class Forbidden extends APIError {
|
|
809
|
+
}
|
|
500
810
|
/** 404: unknown id, or one that belongs to another account. */
|
|
501
811
|
declare class NotFound extends APIError {
|
|
502
812
|
}
|
|
@@ -512,7 +822,10 @@ declare class InvalidAttributes extends APIError {
|
|
|
512
822
|
/** 422: the key was already used for a different request. */
|
|
513
823
|
declare class IdempotencyKeyReused extends APIError {
|
|
514
824
|
}
|
|
515
|
-
/**
|
|
825
|
+
/** 409 JOB_NOT_CANCELLABLE: the job or crawl already finished. */
|
|
826
|
+
declare class JobNotCancellable extends APIError {
|
|
827
|
+
}
|
|
828
|
+
/** 503: an operator switched something off, or a dependency is down. The message carries the reason. */
|
|
516
829
|
declare class Unavailable extends APIError {
|
|
517
830
|
}
|
|
518
831
|
/** 503 MODULE_UNAVAILABLE: this task type is switched off. Nothing was charged. */
|
|
@@ -551,4 +864,4 @@ declare class WaitTimeout extends DataFuelError {
|
|
|
551
864
|
constructor(message: string, id?: string, status?: unknown);
|
|
552
865
|
}
|
|
553
866
|
|
|
554
|
-
export { type AI, APIError, type AskOptions, Blocked, type CallOptions, Capabilities, type Capability, type ClientOptions, type CrawlOptions, CrawlPage, type CrawlResult, type CrawlResultsPage, type CrawlStatus, DEFAULT_BASE_URL, DataFuel, DataFuelError, type Engine, EngineUnavailable, type Format, IdempotencyKeyReused, InsufficientCredits, InvalidAttributes, type JobResults, type JobStatus, type Link, type MapOptions, ModuleUnavailable, NoApiKey, NotFound, type Payload, type Profile, type Proxy, type ProxyType, RateLimited, Result, type ScrapeOptions, type SiteMap, type Status, TaskFailed, TransportError, Unauthorized, Unavailable, VERSION, WaitTimeout, isDone };
|
|
867
|
+
export { type AI, APIError, type Analytics, type AnalyticsCounts, type AnalyticsOptions, type AskOptions, type BalanceSplit, Blocked, type CallOptions, type CancelResult, Capabilities, type Capability, type ClientOptions, type CrawlOptions, CrawlPage, type CrawlResult, type CrawlResultsPage, type CrawlStatus, DEFAULT_BASE_URL, DataFuel, DataFuelError, type Engine, EngineUnavailable, type ErrorCode, Forbidden, type Format, IdempotencyKeyReused, InsufficientCredits, InvalidAttributes, JobNotCancellable, type JobResults, type JobStatus, type JobSummary, type JobsPage, type JsInstruction, type JsInstructionArg, type Link, type ListOptions, type ListTasksOptions, type MapOptions, ModuleUnavailable, NoApiKey, NotFound, type Payload, type PreviousPeriod, type Profile, type Proxy, type ProxyCountry, type ProxyLocation, type ProxyType, RateLimited, Result, type ScrapeOptions, type SearchOptions, type SiteMap, type Status, type StatusCodeBreakdown, TaskFailed, type TaskSummary, type TaskType, type TasksPage, type Transaction, type TransactionOperation, type TransactionSum, type TransactionsOptions, type TransactionsPage, TransportError, Unauthorized, Unavailable, VERSION, WaitTimeout, isDone };
|