@datafuel/sdk 0.2.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 +7 -0
- package/dist/index.cjs +12 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -4
- package/dist/index.d.ts +24 -4
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +13 -2
- package/src/core.ts +1 -1
- package/src/index.ts +1 -0
- package/src/models.ts +19 -0
package/dist/index.d.cts
CHANGED
|
@@ -310,6 +310,8 @@ interface TransactionsOptions {
|
|
|
310
310
|
interface Transaction {
|
|
311
311
|
id: number;
|
|
312
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;
|
|
313
315
|
operation: TransactionOperation;
|
|
314
316
|
/** What `reference_id` points to, e.g. `task_id` or `job_id`. */
|
|
315
317
|
reference_type: string;
|
|
@@ -400,13 +402,29 @@ interface Analytics {
|
|
|
400
402
|
})[];
|
|
401
403
|
by_status_code: StatusCodeBreakdown[];
|
|
402
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
|
+
}
|
|
403
416
|
/** The account behind the API key. */
|
|
404
417
|
interface Profile {
|
|
405
418
|
email: string;
|
|
406
419
|
username: string;
|
|
407
420
|
current_concurrency: number;
|
|
408
421
|
concurrency_limit: number;
|
|
422
|
+
/** Total spendable credits: `plan_credit_balance` plus `payg_credit_balance`. */
|
|
409
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;
|
|
410
428
|
monthly_credit_limit: number;
|
|
411
429
|
}
|
|
412
430
|
/** One argument of a browser action. */
|
|
@@ -470,7 +488,7 @@ declare class Capabilities {
|
|
|
470
488
|
|
|
471
489
|
declare const DEFAULT_BASE_URL = "https://scraping-api.datafuel.ai/api/v1";
|
|
472
490
|
/** Kept in step with package.json by a test; see test/hardening.test.ts. */
|
|
473
|
-
declare const VERSION = "0.
|
|
491
|
+
declare const VERSION = "0.3.0";
|
|
474
492
|
/** Options for the llm_scraping module, which reads its proxy country here. */
|
|
475
493
|
interface AskOptions {
|
|
476
494
|
engine: Engine | string;
|
|
@@ -729,10 +747,12 @@ declare class DataFuel {
|
|
|
729
747
|
proxyAsns(country: string, options?: CallOptions & {
|
|
730
748
|
proxyType?: string;
|
|
731
749
|
}): Promise<ProxyLocation[]>;
|
|
732
|
-
/** Remaining credits. */
|
|
750
|
+
/** Remaining credits: plan and pay-as-you-go together. */
|
|
733
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>;
|
|
734
754
|
/**
|
|
735
|
-
* Credit movements, newest first: purchases, usage, refunds, expiry.
|
|
755
|
+
* Credit movements, newest first: plan assignments, credit pack purchases, usage, refunds, expiry.
|
|
736
756
|
* `sums` totals each operation over the whole range, not just this page.
|
|
737
757
|
*/
|
|
738
758
|
transactions(options?: TransactionsOptions & CallOptions): Promise<TransactionsPage>;
|
|
@@ -844,4 +864,4 @@ declare class WaitTimeout extends DataFuelError {
|
|
|
844
864
|
constructor(message: string, id?: string, status?: unknown);
|
|
845
865
|
}
|
|
846
866
|
|
|
847
|
-
export { type AI, APIError, type Analytics, type AnalyticsCounts, type AnalyticsOptions, type AskOptions, 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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -310,6 +310,8 @@ interface TransactionsOptions {
|
|
|
310
310
|
interface Transaction {
|
|
311
311
|
id: number;
|
|
312
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;
|
|
313
315
|
operation: TransactionOperation;
|
|
314
316
|
/** What `reference_id` points to, e.g. `task_id` or `job_id`. */
|
|
315
317
|
reference_type: string;
|
|
@@ -400,13 +402,29 @@ interface Analytics {
|
|
|
400
402
|
})[];
|
|
401
403
|
by_status_code: StatusCodeBreakdown[];
|
|
402
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
|
+
}
|
|
403
416
|
/** The account behind the API key. */
|
|
404
417
|
interface Profile {
|
|
405
418
|
email: string;
|
|
406
419
|
username: string;
|
|
407
420
|
current_concurrency: number;
|
|
408
421
|
concurrency_limit: number;
|
|
422
|
+
/** Total spendable credits: `plan_credit_balance` plus `payg_credit_balance`. */
|
|
409
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;
|
|
410
428
|
monthly_credit_limit: number;
|
|
411
429
|
}
|
|
412
430
|
/** One argument of a browser action. */
|
|
@@ -470,7 +488,7 @@ declare class Capabilities {
|
|
|
470
488
|
|
|
471
489
|
declare const DEFAULT_BASE_URL = "https://scraping-api.datafuel.ai/api/v1";
|
|
472
490
|
/** Kept in step with package.json by a test; see test/hardening.test.ts. */
|
|
473
|
-
declare const VERSION = "0.
|
|
491
|
+
declare const VERSION = "0.3.0";
|
|
474
492
|
/** Options for the llm_scraping module, which reads its proxy country here. */
|
|
475
493
|
interface AskOptions {
|
|
476
494
|
engine: Engine | string;
|
|
@@ -729,10 +747,12 @@ declare class DataFuel {
|
|
|
729
747
|
proxyAsns(country: string, options?: CallOptions & {
|
|
730
748
|
proxyType?: string;
|
|
731
749
|
}): Promise<ProxyLocation[]>;
|
|
732
|
-
/** Remaining credits. */
|
|
750
|
+
/** Remaining credits: plan and pay-as-you-go together. */
|
|
733
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>;
|
|
734
754
|
/**
|
|
735
|
-
* Credit movements, newest first: purchases, usage, refunds, expiry.
|
|
755
|
+
* Credit movements, newest first: plan assignments, credit pack purchases, usage, refunds, expiry.
|
|
736
756
|
* `sums` totals each operation over the whole range, not just this page.
|
|
737
757
|
*/
|
|
738
758
|
transactions(options?: TransactionsOptions & CallOptions): Promise<TransactionsPage>;
|
|
@@ -844,4 +864,4 @@ declare class WaitTimeout extends DataFuelError {
|
|
|
844
864
|
constructor(message: string, id?: string, status?: unknown);
|
|
845
865
|
}
|
|
846
866
|
|
|
847
|
-
export { type AI, APIError, type Analytics, type AnalyticsCounts, type AnalyticsOptions, type AskOptions, 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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -102,7 +102,7 @@ function apiError(status, body, retryAfter = 0) {
|
|
|
102
102
|
|
|
103
103
|
// src/core.ts
|
|
104
104
|
var DEFAULT_BASE_URL = "https://scraping-api.datafuel.ai/api/v1";
|
|
105
|
-
var VERSION = "0.
|
|
105
|
+
var VERSION = "0.3.0";
|
|
106
106
|
var DEFAULT_TIMEOUT_MS = 18e4;
|
|
107
107
|
var STILL_PROCESSING_DELAY_MS = 2e3;
|
|
108
108
|
var STILL_PROCESSING = "TASK_STILL_PROCESSING";
|
|
@@ -978,13 +978,22 @@ var DataFuel = class {
|
|
|
978
978
|
await this.send(new Request("GET", "/config/proxy/asn", params), options)
|
|
979
979
|
);
|
|
980
980
|
}
|
|
981
|
-
/** Remaining credits. */
|
|
981
|
+
/** Remaining credits: plan and pay-as-you-go together. */
|
|
982
982
|
async balance(options = {}) {
|
|
983
983
|
const body = await this.send(new Request("GET", "/users/@me/balance"), options);
|
|
984
984
|
return intField(body, "balance");
|
|
985
985
|
}
|
|
986
|
+
/** Remaining credits by pool: plan credits (spent first) and pay-as-you-go credits. */
|
|
987
|
+
async balanceSplit(options = {}) {
|
|
988
|
+
const body = await this.send(new Request("GET", "/users/@me/balance"), options);
|
|
989
|
+
return {
|
|
990
|
+
balance: intField(body, "balance"),
|
|
991
|
+
plan_balance: intField(body, "plan_balance"),
|
|
992
|
+
payg_balance: intField(body, "payg_balance")
|
|
993
|
+
};
|
|
994
|
+
}
|
|
986
995
|
/**
|
|
987
|
-
* Credit movements, newest first: purchases, usage, refunds, expiry.
|
|
996
|
+
* Credit movements, newest first: plan assignments, credit pack purchases, usage, refunds, expiry.
|
|
988
997
|
* `sums` totals each operation over the whole range, not just this page.
|
|
989
998
|
*/
|
|
990
999
|
async transactions(options = {}) {
|